Class: Mapi::PropertySet::Key

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/mapi/property_set.rb

Overview

Properties are accessed by Keys, which are coerced to this class. Includes a bunch of methods (hash, ==, eql?) to allow it to work as a key in a Hash.

Also contains the code that maps keys to symbolic names.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, guid = PS_MAPI) ⇒ Key

Returns a new instance of Key.



68
69
70
# File 'lib/mapi/property_set.rb', line 68

def initialize code, guid=PS_MAPI
	@code, @guid = code, guid
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



67
68
69
# File 'lib/mapi/property_set.rb', line 67

def code
  @code
end

#guidObject (readonly)

Returns the value of attribute guid.



67
68
69
# File 'lib/mapi/property_set.rb', line 67

def guid
  @guid
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



109
110
111
# File 'lib/mapi/property_set.rb', line 109

def == other
	hash == other.hash
end

#hashObject

this stuff is to allow it to be a useful key



105
106
107
# File 'lib/mapi/property_set.rb', line 105

def hash
	[code, guid].hash
end

#inspectObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/mapi/property_set.rb', line 115

def inspect
	# maybe the way to do this, would be to be able to register guids
	# in a global lookup, which are used by Clsid#inspect itself, to
	# provide symbolic names...
	guid_str = NAMES[guid] || "{#{guid.format}}"
	if Integer === code
		hex = '0x%04x' % code
		if guid == PS_MAPI
			# just display as plain hex number
			hex
		else
			"#<Key #{guid_str}/#{hex}>"
		end
	else
		# display full guid and code
		"#<Key #{guid_str}/#{code.inspect}>"
	end
end

#to_sObject



95
96
97
# File 'lib/mapi/property_set.rb', line 95

def to_s
	to_sym.to_s
end

#to_symObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mapi/property_set.rb', line 72

def to_sym
	# hmmm, for some stuff, like, eg, the message class specific range, sym-ification
	# of the key depends on knowing our message class. i don't want to store anything else
	# here though, so if that kind of thing is needed, it can be passed to this function.
	# worry about that when some examples arise.
	case code
	when Integer
		if guid == PS_MAPI # and < 0x8000 ?
			# the hash should be updated now that i've changed the process
			TAGS['%04x' % code].first[/_(.*)/, 1].downcase.to_sym rescue code
		else
			# handle other guids here, like mapping names to outlook properties, based on the
			# outlook object model.
			NAMED_MAP[self].to_sym rescue code
		end
	when String
		# return something like
		# note that named properties don't go through the map at the moment. so #categories
		# doesn't work yet
		code.downcase.to_sym
	end
end

#transmittable?Boolean

FIXME implement these

Returns:

  • (Boolean)


100
101
102
# File 'lib/mapi/property_set.rb', line 100

def transmittable?
	# etc, can go here too
end