Parent

Ole::Storage::MetaData

The MetaData class is designed to be high level interface to all the underlying meta data stored within different sections, themselves within different property set streams.

With this class, you can simply get properties using their names, without needing to know about the underlying guids, property ids etc.

Example:

Ole::Storage.open('test.doc') { |ole| p ole.meta_data.doc_author }

TODO:

Public Class Methods

new(ole) click to toggle source
# File lib/ole/storage/meta_data.rb, line 63
def initialize ole
  @ole = ole
end

Public Instance Methods

[](key) click to toggle source
# File lib/ole/storage/meta_data.rb, line 115
def [] key
  pair = Types::PropertySet::PROPERTY_MAP[key.to_s] or return nil
  file = FILE_MAP[pair.first] or return nil
  dirent = @ole.root[file] or return nil
  dirent.open { |io| return Types::PropertySet.new(io)[key] }
end
[]=(key, value) click to toggle source
# File lib/ole/storage/meta_data.rb, line 122
def []= key, value
  raise NotImplementedError, 'meta data writes not implemented'
end
each(&block) click to toggle source
# File lib/ole/storage/meta_data.rb, line 126
def each(&block)
  FILE_MAP.values.each do |file|
    dirent = @ole.root[file] or next
    dirent.open { |io| Types::PropertySet.new(io).each(&block) }
  end
end
file_format() click to toggle source
# File lib/ole/storage/meta_data.rb, line 93
def file_format
  comp_obj[:file_format]
end
method_missing(name, *args, &block) click to toggle source
# File lib/ole/storage/meta_data.rb, line 137
def method_missing name, *args, &block
  return super unless args.empty?
  pair = Types::PropertySet::PROPERTY_MAP[name.to_s] or return super
  self[name]
end
mime_type() click to toggle source
# File lib/ole/storage/meta_data.rb, line 97
def mime_type
  # based on the CompObj stream contents
  type = FORMAT_MAP[file_format]
  return MIME_TYPES[type] if type

  # based on the root clsid
  type = CLSID_MAP[Types::Clsid.load(@ole.root.clsid)]
  return MIME_TYPES[type] if type

  # fallback to heuristics
  has_file = Hash[*@ole.root.children.map { |d| [d.name.downcase, true] }.flatten]
  return MIME_TYPES[:msg] if has_file['__nameid_version1.0'] or has_file['__properties_version1.0']
  return MIME_TYPES[:doc] if has_file['worddocument'] or has_file['document']
  return MIME_TYPES[:xls] if has_file['workbook'] or has_file['book']

  MIME_TYPES[nil]
end
to_h() click to toggle source
# File lib/ole/storage/meta_data.rb, line 133
def to_h
  inject({}) { |hash, (name, value)| hash.update name.to_sym => value }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.