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.
-
#long_name ⇒ Object
Returns the value of attribute long_name.
-
#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.
-
#table_fragment ⇒ Object
Returns the value of attribute table_fragment.
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.
52 53 54 55 56 57 58 59 |
# File 'lib/rets/metadata/table.rb', line 52 def initialize(table_fragment, resource) self.table_fragment = table_fragment self.resource = resource self.name = table_fragment["SystemName"] self.interpretation = table_fragment["Interpretation"] self.lookup_name = table_fragment["LookupName"] self.long_name = table_fragment["LongName"] end |
Instance Attribute Details
#interpretation ⇒ Object
Returns the value of attribute interpretation.
48 49 50 |
# File 'lib/rets/metadata/table.rb', line 48 def interpretation @interpretation end |
#long_name ⇒ Object
Returns the value of attribute long_name.
49 50 51 |
# File 'lib/rets/metadata/table.rb', line 49 def long_name @long_name end |
#lookup_name ⇒ Object
Returns the value of attribute lookup_name.
46 47 48 |
# File 'lib/rets/metadata/table.rb', line 46 def lookup_name @lookup_name end |
#name ⇒ Object
Returns the value of attribute name.
47 48 49 |
# File 'lib/rets/metadata/table.rb', line 47 def name @name end |
#resource ⇒ Object
Returns the value of attribute resource.
45 46 47 |
# File 'lib/rets/metadata/table.rb', line 45 def resource @resource end |
#table_fragment ⇒ Object
Returns the value of attribute table_fragment.
50 51 52 |
# File 'lib/rets/metadata/table.rb', line 50 def table_fragment @table_fragment end |
Instance Method Details
#lookup_type(value) ⇒ Object
82 83 84 |
# File 'lib/rets/metadata/table.rb', line 82 def lookup_type(value) lookup_types.detect {|lt| lt.value == value } end |
#lookup_types ⇒ Object
65 66 67 |
# File 'lib/rets/metadata/table.rb', line 65 def lookup_types resource.lookup_types[lookup_name] end |
#multi? ⇒ Boolean
61 62 63 |
# File 'lib/rets/metadata/table.rb', line 61 def multi? interpretation == "LookupMulti" end |
#print_tree ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rets/metadata/table.rb', line 69 def print_tree puts " LookupTable: #{name}" puts " Required: #{table_fragment['Required']}" puts " Searchable: #{ table_fragment["Searchable"] }" puts " Units: #{ table_fragment["Units"] }" puts " ShortName: #{ table_fragment["ShortName"] }" puts " LongName: #{ table_fragment["LongName"] }" puts " StandardName: #{ table_fragment["StandardName"] }" puts " Types:" lookup_types.each(&:print_tree) end |
#resolve(value) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rets/metadata/table.rb', line 86 def resolve(value) if value.empty? return [] if multi? return value.to_s.strip end values = multi? ? value.split(","): [value] values = values.map do |v| #Remove surrounding quotes clean_value = v.scan(/^["']?(.*?)["']?$/).join lookup_type = lookup_type(clean_value) resolved_value = lookup_type ? lookup_type.long_value : nil warn("Discarding unmappable value of #{clean_value.inspect}") if resolved_value.nil? && $VERBOSE resolved_value end multi? ? values.map {|v| v.to_s.strip } : values.first.to_s.strip end |