Class: Locus::Place

Inherits:
Object
  • Object
show all
Defined in:
lib/locus/place.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Place

Returns a new instance of Place.



7
8
9
10
11
# File 'lib/locus/place.rb', line 7

def initialize(attributes = {})
  attributes.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/locus/place.rb', line 5

def country
  @country
end

#postal_codeObject

Returns the value of attribute postal_code.



5
6
7
# File 'lib/locus/place.rb', line 5

def postal_code
  @postal_code
end

#state_codeObject

Returns the value of attribute state_code.



5
6
7
# File 'lib/locus/place.rb', line 5

def state_code
  @state_code
end

Class Method Details

.find_by_postal_code(postal_code, country = Locus.default_country) ⇒ Place

Find a place by postal code and country.

Examples:

Locus::Place.find_by_postal_code '12053', :de  # => 'BE'

Parameters:

  • postal_code (String)

    The postal code.

  • country (Symbol) (defaults to: Locus.default_country)

    Country symbol.

Returns:



22
23
24
25
26
27
# File 'lib/locus/place.rb', line 22

def self.find_by_postal_code(postal_code, country = Locus.default_country)
  return nil unless state_code = state_code(postal_code, country)
  self.new(country: country,
           postal_code: postal_code,
           state_code: state_code)
end