Class: Ole::Types::PropertySet::Section

Inherits:
Struct
  • Object
show all
Includes:
Enumerable, Variant::Constants
Defined in:
lib/ole/property_set.rb

Constant Summary collapse

SIZE =
Clsid::SIZE + 4
PACK =
"a#{Clsid::SIZE}v"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#group_by, #sum

Constructor Details

#initialize(str, property_set) ⇒ Section

Returns a new instance of Section.



47
48
49
50
51
52
53
# File 'lib/ole/property_set.rb', line 47

def initialize str, property_set
	@property_set = property_set
	super(*str.unpack(PACK))
	self.guid = Clsid.load guid
	@map = DATA[guid] ? DATA[guid][1] : nil
	load_header
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/ole/property_set.rb', line 89

def method_missing name, *args
	if args.empty? and @map and @map.values.include? name.to_s
		self[name.to_s]
	else
		super
	end
end

Instance Attribute Details

#guidObject

Returns the value of attribute guid

Returns:

  • (Object)

    the current value of guid



39
40
41
# File 'lib/ole/property_set.rb', line 39

def guid
  @guid
end

#lengthObject (readonly)

Returns the value of attribute length.



46
47
48
# File 'lib/ole/property_set.rb', line 46

def length
  @length
end

#offsetObject

Returns the value of attribute offset

Returns:

  • (Object)

    the current value of offset



39
40
41
# File 'lib/ole/property_set.rb', line 39

def offset
  @offset
end

Instance Method Details

#[](key) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/ole/property_set.rb', line 81

def [] key
	unless Integer === key
		return unless @map and key = @map.invert[key]
	end
	return unless result = properties.assoc(key)
	result.last
end

#eachObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ole/property_set.rb', line 64

def each
	io.seek offset + 8
	io.read(length * 8).scan(/.{8}/m).each do |str|
		id, property_offset = str.unpack 'V2'
		io.seek offset + property_offset
		type, value = io.read(8).unpack('V2')
		# is the method of serialization here custom?
		case type
		when VT_LPSTR, VT_LPWSTR
			value = Variant.load type, io.read(value)
		# ....
		end
		yield id, type, value
	end
	self
end

#ioObject



55
56
57
# File 'lib/ole/property_set.rb', line 55

def io
	@property_set.io
end

#load_headerObject



59
60
61
62
# File 'lib/ole/property_set.rb', line 59

def load_header
	io.seek offset
	@byte_size, @length = io.read(8).unpack 'V2'
end

#propertiesObject



97
98
99
# File 'lib/ole/property_set.rb', line 97

def properties
	@properties ||= to_enum.to_a
end