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.

Parameters:

  • code (Integer, String)
  • guid (Ole::Types::Clsid) (defaults to: PS_MAPI)


74
75
76
# File 'lib/mapi/property_set.rb', line 74

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

Instance Attribute Details

#codeInteger, String (readonly)

Returns:

  • (Integer, String)


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

def code
  @code
end

#guidOle::Types::Clsid (readonly)

Returns:

  • (Ole::Types::Clsid)


70
71
72
# File 'lib/mapi/property_set.rb', line 70

def guid
  @guid
end

Instance Method Details

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

Returns:

  • (Boolean)


120
121
122
# File 'lib/mapi/property_set.rb', line 120

def == other
  hash == other.hash
end

#hashInteger

this stuff is to allow it to be a useful key

Returns:

  • (Integer)


115
116
117
# File 'lib/mapi/property_set.rb', line 115

def hash
  [code, guid].hash
end

#inspectString

Returns:

  • (String)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mapi/property_set.rb', line 127

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_sString

Returns:

  • (String)


103
104
105
# File 'lib/mapi/property_set.rb', line 103

def to_s
  to_sym.to_s
end

#to_symSymbol

Returns:

  • (Symbol)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mapi/property_set.rb', line 79

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)


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

def transmittable?
  # etc, can go here too
end