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.



58
59
60
61
62
63
64
65
# File 'lib/rets/metadata/table.rb', line 58

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.



54
55
56
# File 'lib/rets/metadata/table.rb', line 54

def interpretation
  @interpretation
end

#long_nameObject

Returns the value of attribute long_name.



55
56
57
# File 'lib/rets/metadata/table.rb', line 55

def long_name
  @long_name
end

#lookup_nameObject

Returns the value of attribute lookup_name.



52
53
54
# File 'lib/rets/metadata/table.rb', line 52

def lookup_name
  @lookup_name
end

#nameObject

Returns the value of attribute name.



53
54
55
# File 'lib/rets/metadata/table.rb', line 53

def name
  @name
end

#resourceObject

Returns the value of attribute resource.



51
52
53
# File 'lib/rets/metadata/table.rb', line 51

def resource
  @resource
end

#table_fragmentObject

Returns the value of attribute table_fragment.



56
57
58
# File 'lib/rets/metadata/table.rb', line 56

def table_fragment
  @table_fragment
end

Instance Method Details

#lookup_type(value) ⇒ Object



94
95
96
# File 'lib/rets/metadata/table.rb', line 94

def lookup_type(value)
  lookup_types.detect {|lt| lt.value == value }
end

#lookup_typesObject



71
72
73
# File 'lib/rets/metadata/table.rb', line 71

def lookup_types
  resource.lookup_types[lookup_name]
end

#multi?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/rets/metadata/table.rb', line 67

def multi?
  interpretation == "LookupMulti"
end

Print the tree to a file

out

The file to print to. Defaults to $stdout.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rets/metadata/table.rb', line 78

def print_tree(out = $stdout)
  out.puts "    LookupTable: #{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: #{ table_fragment["LongName"] }"
  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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rets/metadata/table.rb', line 98

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