Class: Ole::Storage::MetaData

### Home Classes Methods

### In Files

- lib/ole/storage/meta_data.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #each
- #file_format
- #method_missing
- #mime_type
- #to_h

### Files

- ChangeLog
- README

### Class/Module Index

Quicksearch

- Ole
- Ole::IOMode
- Ole::IOMode::Constants
- Ole::Storage
- Ole::Storage::AllocationTable
- Ole::Storage::AllocationTable::Big
- Ole::Storage::AllocationTable::Small
- Ole::Storage::DirClass
- Ole::Storage::DirClass::Dir
- Ole::Storage::Dirent
- Ole::Storage::FileClass
- Ole::Storage::FileClass::Stat
- Ole::Storage::Header
- Ole::Storage::MetaData
- Ole::Storage::RangesIOMigrateable
- Ole::Storage::RangesIOResizeable
- Ole::Types
- Ole::Types::Clsid
- Ole::Types::Data
- Ole::Types::FileTime
- Ole::Types::Lpstr
- Ole::Types::Lpwstr
- Ole::Types::PropertySet
- Ole::Types::PropertySet::Constants
- Ole::Types::PropertySet::Section
- Ole::Types::Variant
- Ole::Types::Variant::Constants
- RangesIO

No matching classes.

# 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:

- add write support

- fix some of the missing type coercion (eg FileTime)

- maybe add back the ability to access individual property sets as a unit directly. ie `ole.summary_information`. Is this useful?

- full key support, for unknown keys, like `ole.meta_data[myguid, myid]`. probably needed for user-defined properties too.

### Constants

CLSID_EXCEL95
CLSID_EXCEL97
CLSID_MAP
CLSID_WORD95
CLSID_WORD97
FILE_MAP
FORMAT_MAP
MIME_TYPES

### 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?
      return super unless Types::PropertySet::PROPERTY_MAP[name.to_s]
      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.