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.



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

#interpretationObject

Returns the value of attribute interpretation.



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

def interpretation
  @interpretation
end

#lookup_nameObject

Returns the value of attribute lookup_name.



43
44
45
# File 'lib/rets/metadata/table.rb', line 43

def lookup_name
  @lookup_name
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#resourceObject

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_typesObject



58
59
60
# File 'lib/rets/metadata/table.rb', line 58

def lookup_types
  resource.lookup_types[lookup_name]
end

#multi?Boolean

Returns:

  • (Boolean)


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

def multi?
  interpretation == "LookupMulti"
end


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