Class: Rets::Metadata::MultiLookupTable
- Inherits:
-
Object
- Object
- Rets::Metadata::MultiLookupTable
- Defined in:
- lib/rets/metadata/multi_lookup_table.rb
Instance Attribute Summary collapse
-
#long_name ⇒ Object
readonly
Returns the value of attribute long_name.
-
#lookup_types ⇒ Object
readonly
Returns the value of attribute lookup_types.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource_id ⇒ Object
readonly
Returns the value of attribute resource_id.
-
#table_fragment ⇒ Object
readonly
Returns the value of attribute table_fragment.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(resource_id, lookup_types, table_fragment) ⇒ MultiLookupTable
constructor
A new instance of MultiLookupTable.
- #lookup_type(value) ⇒ Object
-
#print_tree(out = $stdout) ⇒ Object
Print the tree to a file.
- #resolve(value) ⇒ Object
Constructor Details
#initialize(resource_id, lookup_types, table_fragment) ⇒ MultiLookupTable
Returns a new instance of MultiLookupTable.
6 7 8 9 10 11 12 13 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 6 def initialize(resource_id, lookup_types, table_fragment) @resource_id = resource_id @lookup_types = lookup_types @table_fragment = table_fragment @name = table_fragment["SystemName"] @long_name = table_fragment["LongName"] end |
Instance Attribute Details
#long_name ⇒ Object (readonly)
Returns the value of attribute long_name.
4 5 6 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 4 def long_name @long_name end |
#lookup_types ⇒ Object (readonly)
Returns the value of attribute lookup_types.
4 5 6 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 4 def lookup_types @lookup_types end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 4 def name @name end |
#resource_id ⇒ Object (readonly)
Returns the value of attribute resource_id.
4 5 6 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 4 def resource_id @resource_id end |
#table_fragment ⇒ Object (readonly)
Returns the value of attribute table_fragment.
4 5 6 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 4 def table_fragment @table_fragment end |
Class Method Details
.build(table_fragment, resource_id, lookup_types) ⇒ Object
15 16 17 18 19 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 15 def self.build(table_fragment, resource_id, lookup_types) lookup_name = table_fragment["LookupName"] lookup_types = lookup_types[lookup_name] new(resource_id, lookup_types, table_fragment) end |
Instance Method Details
#lookup_type(value) ⇒ Object
40 41 42 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 40 def lookup_type(value) lookup_types.detect {|lt| lt.value == value } end |
#print_tree(out = $stdout) ⇒ Object
Print the tree to a file
- out
-
The file to print to. Defaults to $stdout.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 24 def print_tree(out = $stdout) out.puts "### MultiLookupTable: #{name}" out.puts " Resource: #{resource_id}" out.puts " Required: #{table_fragment['Required']}" out.puts " Searchable: #{ table_fragment["Searchable"] }" out.puts " Units: #{ table_fragment["Units"] }" out.puts " ShortName: #{ table_fragment["ShortName"] }" out.puts " LongName: #{ long_name }" out.puts " StandardName: #{ table_fragment["StandardName"] }" out.puts " Types:" lookup_types.each do |lookup_type| lookup_type.print_tree(out) end end |
#resolve(value) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rets/metadata/multi_lookup_table.rb', line 44 def resolve(value) if value.empty? return [] end values = value.split(",") 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 if resolved_value.nil? && $VERBOSE warn("Discarding unmappable value of #{clean_value.inspect}") end resolved_value.to_s.strip end end |