Class: Postcodes::Postcode

Inherits:
Object
  • Object
show all
Defined in:
lib/postcodes_io/postcode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Postcode

Returns a new instance of Postcode.



6
7
8
# File 'lib/postcodes_io/postcode.rb', line 6

def initialize(info)
  @info = info
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

allow accessing info values with dot notation



11
12
13
14
15
# File 'lib/postcodes_io/postcode.rb', line 11

def method_missing(name, *args, &block)
  return @info[name] if @info.key? name
  @info.each { |k,v| return v if k.to_s.to_sym == name }
  super.method_missing name
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



4
5
6
# File 'lib/postcodes_io/postcode.rb', line 4

def info
  @info
end