Class: WeatherJp::City
- Inherits:
-
Object
- Object
- WeatherJp::City
- Defined in:
- lib/weather_jp/city.rb
Constant Summary collapse
- KEYS =
Canonical key names for attributes.
%i(name full_name code latitude longitude)
Instance Attribute Summary collapse
-
#name ⇒ String
(also: #to_s)
readonly
The current value of name.
Instance Method Summary collapse
-
#code ⇒ String
(also: #area_code, #location_code)
i.e.
- #full_name ⇒ String
-
#initialize(name, attrs = {}) ⇒ City
constructor
A new instance of City.
- #latitude ⇒ Float (also: #lat)
- #longitude ⇒ Float (also: #long)
- #to_hash ⇒ Hash
Constructor Details
#initialize(name, attrs = {}) ⇒ City
Returns a new instance of City.
11 12 13 14 |
# File 'lib/weather_jp/city.rb', line 11 def initialize(name, attrs = {}) @name = name @attrs = attrs end |
Instance Attribute Details
#name ⇒ String (readonly) Also known as: to_s
Returns the current value of name.
3 4 5 |
# File 'lib/weather_jp/city.rb', line 3 def name @name end |
Instance Method Details
#code ⇒ String Also known as: area_code, location_code
i.e. ‘JAXX0085’
23 24 25 26 27 28 29 |
# File 'lib/weather_jp/city.rb', line 23 def code if str = @attrs['weatherlocationcode'] str.split(':').last else nil end end |
#full_name ⇒ String
17 18 19 |
# File 'lib/weather_jp/city.rb', line 17 def full_name @attrs['weatherlocationname'] end |
#latitude ⇒ Float Also known as: lat
34 35 36 |
# File 'lib/weather_jp/city.rb', line 34 def latitude @attrs['lat'].try(:to_f) end |
#longitude ⇒ Float Also known as: long
40 41 42 |
# File 'lib/weather_jp/city.rb', line 40 def longitude @attrs['long'].try(:to_f) end |
#to_hash ⇒ Hash
48 49 50 |
# File 'lib/weather_jp/city.rb', line 48 def to_hash Hash[KEYS.map {|k| [k, public_send(k)] }] end |