Class: Rets::Metadata::LookupTable
- Inherits:
-
Object
- Object
- Rets::Metadata::LookupTable
- Defined in:
- lib/rets/metadata/table.rb
Instance Attribute Summary collapse
-
#interpretation ⇒ Object
Returns the value of attribute interpretation.
-
#lookup_name ⇒ Object
Returns the value of attribute lookup_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(table_fragment, resource) ⇒ LookupTable
constructor
A new instance of LookupTable.
- #lookup_type(value) ⇒ Object
- #lookup_types ⇒ Object
- #multi? ⇒ Boolean
- #print_tree ⇒ Object
- #resolve(value) ⇒ Object
Constructor Details
#initialize(table_fragment, resource) ⇒ LookupTable
Returns a new instance of LookupTable.
47 48 49 50 51 52 |
# File 'lib/rets/metadata/table.rb', line 47 def initialize(table_fragment, resource) self.resource = resource self.name = table_fragment["SystemName"] self.interpretation = table_fragment["Interpretation"] self.lookup_name = table_fragment["LookupName"] end |
Instance Attribute Details
#interpretation ⇒ Object
Returns the value of attribute interpretation.
45 46 47 |
# File 'lib/rets/metadata/table.rb', line 45 def interpretation @interpretation end |
#lookup_name ⇒ Object
Returns the value of attribute lookup_name.
43 44 45 |
# File 'lib/rets/metadata/table.rb', line 43 def lookup_name @lookup_name end |
#name ⇒ Object
Returns the value of attribute name.
44 45 46 |
# File 'lib/rets/metadata/table.rb', line 44 def name @name end |
#resource ⇒ Object
Returns the value of attribute resource.
42 43 44 |
# File 'lib/rets/metadata/table.rb', line 42 def resource @resource end |
Instance Method Details
#lookup_type(value) ⇒ Object
68 69 70 |
# File 'lib/rets/metadata/table.rb', line 68 def lookup_type(value) lookup_types.detect {|lt| lt.value == value } end |
#lookup_types ⇒ Object
58 59 60 |
# File 'lib/rets/metadata/table.rb', line 58 def lookup_types resource.lookup_types[lookup_name] end |
#multi? ⇒ Boolean
54 55 56 |
# File 'lib/rets/metadata/table.rb', line 54 def multi? interpretation == "LookupMulti" end |
#print_tree ⇒ Object
62 63 64 65 66 |
# File 'lib/rets/metadata/table.rb', line 62 def print_tree puts " LookupTable: #{name}" lookup_types.each(&:print_tree) end |
#resolve(value) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rets/metadata/table.rb', line 72 def resolve(value) if value.empty? return [] if multi? return value.to_s.strip end values = multi? ? value.split(","): [value] values = values.map do |value| #Remove surrounding quotes value = value.scan(/^["']?(.*?)["']?$/).to_s lookup_type = lookup_type(value) resolved_value = lookup_type ? lookup_type.long_value : nil warn("Discarding unmappable value of #{value.inspect}") if resolved_value.nil? && $VERBOSE resolved_value end multi? ? values.map {|value| value.to_s.strip } : values.first.to_s.strip end |