Class: Ole::Types::Clsid

Inherits:
String
  • Object
show all
Defined in:
lib/ole/types.rb

Overview

for VT_CLSID Unlike most of the other conversions, the Guid’s are serialized/deserialized by actually doing nothing! (eg, _load & _dump are null ops) Rather, its just a string with a different inspect string, and it includes a helper method for creating a Guid from that readable form (#format).

Constant Summary collapse

SIZE =
16
PACK =
'V v v CC C6'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#indexes

Class Method Details

.dump(guid) ⇒ Object



105
106
107
108
109
# File 'lib/ole/types.rb', line 105

def self.dump guid
	return 0.chr * SIZE unless guid
	# allow use of plain strings in place of guids.
	guid['-'] ? parse(guid) : guid
end

.load(str) ⇒ Object



101
102
103
# File 'lib/ole/types.rb', line 101

def self.load str
	new str.to_s
end

.parse(str) ⇒ Object

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ole/types.rb', line 111

def self.parse str
	vals = str.scan(/[a-f\d]+/i).map(&:hex)
	if vals.length == 5
		# this is pretty ugly
		vals[3] = ('%04x' % vals[3]).scan(/../).map(&:hex)
		vals[4] = ('%012x' % vals[4]).scan(/../).map(&:hex)
		guid = new vals.flatten.pack(PACK)
		return guid unless guid.delete('{}') == str.downcase.delete('{}')
	end
	raise ArgumentError, 'invalid guid - %p' % str
end

Instance Method Details

#formatObject



123
124
125
# File 'lib/ole/types.rb', line 123

def format
	"%08x-%04x-%04x-%02x%02x-#{'%02x' * 6}" % unpack(PACK)
end

#inspectObject



127
128
129
# File 'lib/ole/types.rb', line 127

def inspect
	"#<#{self.class}:{#{format}}>"
end