Class: MaxMind::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/max_mind/lookup.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Lookup

Returns a new instance of Lookup.



4
5
6
7
8
9
10
# File 'lib/max_mind/lookup.rb', line 4

def initialize(raw)
  @attributes = Hash.new
  for key, value in raw.split(';').map{|r| r.split('=', 2)}
    field_name, type = mapping[key]
    @attributes[field_name] = parse_value(value, type)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

 Return the appropriate attribute from the attributes hash.



13
14
15
16
# File 'lib/max_mind/lookup.rb', line 13

def method_missing(name)
  super unless mapping.values.map(&:first).include?(name.to_sym)
  @attributes[name.to_sym]
end