Class: Rets::Metadata::LookupTable

Inherits:
Object
  • Object
show all
Defined in:
lib/rets/metadata/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#interpretationObject

Returns the value of attribute interpretation.



48
49
50
# File 'lib/rets/metadata/table.rb', line 48

def interpretation
  @interpretation
end

#long_nameObject

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_nameObject

Returns the value of attribute lookup_name.



46
47
48
# File 'lib/rets/metadata/table.rb', line 46

def lookup_name
  @lookup_name
end

#nameObject

Returns the value of attribute name.



47
48
49
# File 'lib/rets/metadata/table.rb', line 47

def name
  @name
end

#resourceObject

Returns the value of attribute resource.



45
46
47
# File 'lib/rets/metadata/table.rb', line 45

def resource
  @resource
end

#table_fragmentObject

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_typesObject



65
66
67
# File 'lib/rets/metadata/table.rb', line 65

def lookup_types
  resource.lookup_types[lookup_name]
end

#multi?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/rets/metadata/table.rb', line 61

def multi?
  interpretation == "LookupMulti"
end


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