Class: DcAddressLookup::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/dc_address_lookup/location.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/dc_address_lookup/location.rb', line 22

def method_missing(method_sym, *arguments, &block)
  if has_property?(method_sym)
   data[method_sym.to_s]
  else
   super
  end
end

Class Method Details

.from_table(xml) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dc_address_lookup/location.rb', line 3

def self.from_table(xml)
  location = self.new

  xml.children.each do |node|
    next if node.node_name == "text"
    key = node.name.downcase
    value = node.text.gsub(/\A#{key.split("_").first}\b/i, "").squeeze("\s").strip
    value = value.to_i if value.to_i.to_s == value
    value = value.to_f if value.to_f.to_s == value
    location.data[key] = value
  end

  location
end

Instance Method Details

#dataObject



38
39
40
# File 'lib/dc_address_lookup/location.rb', line 38

def data
  @data ||= {}
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/dc_address_lookup/location.rb', line 30

def respond_to?(method_sym, include_private = false)
  if has_property?(method_sym)
    true
  else
    super
  end
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dc_address_lookup/location.rb', line 18

def valid?
  !(data.empty?)
end