Class: ClimaTempo::Weather
- Inherits:
-
Object
- Object
- ClimaTempo::Weather
- Defined in:
- lib/climatempo/weather.rb
Instance Attribute Summary collapse
-
#airports ⇒ Object
readonly
Returns the value of attribute airports.
-
#brazil ⇒ Object
readonly
Returns the value of attribute brazil.
-
#capitals ⇒ Object
readonly
Returns the value of attribute capitals.
-
#fetcher ⇒ Object
readonly
Returns the value of attribute fetcher.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#places ⇒ Object
readonly
Returns the value of attribute places.
-
#regions ⇒ Object
readonly
Returns the value of attribute regions.
Instance Method Summary collapse
-
#forecast_for(place) ⇒ Object
Search nominally for a given place and return its forecasts.
-
#initialize(capitals_only = false, fetcher = HTTParty, parser = Parser) ⇒ Weather
constructor
A new instance of Weather.
Constructor Details
#initialize(capitals_only = false, fetcher = HTTParty, parser = Parser) ⇒ Weather
Returns a new instance of Weather.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/climatempo/weather.rb', line 45 def initialize(capitals_only = false, fetcher = HTTParty, parser = Parser) @fetcher = fetcher @parser = parser @capitals = load_up(:capitals) unless capitals_only @brazil = load_up(:brazil) @regions = load_up(:regions) @airports = load_up(:airports) else @brazil = {} @regions = {} @airports = {} end @places = @capitals.merge(@brazil). merge(@regions).merge(@airports) end |
Instance Attribute Details
#airports ⇒ Object (readonly)
Returns the value of attribute airports.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def airports @airports end |
#brazil ⇒ Object (readonly)
Returns the value of attribute brazil.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def brazil @brazil end |
#capitals ⇒ Object (readonly)
Returns the value of attribute capitals.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def capitals @capitals end |
#fetcher ⇒ Object (readonly)
Returns the value of attribute fetcher.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def fetcher @fetcher end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def parser @parser end |
#places ⇒ Object (readonly)
Returns the value of attribute places.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def places @places end |
#regions ⇒ Object (readonly)
Returns the value of attribute regions.
43 44 45 |
# File 'lib/climatempo/weather.rb', line 43 def regions @regions end |
Instance Method Details
#forecast_for(place) ⇒ Object
Search nominally for a given place and return its forecasts. Capital cities can be found both by ClimaTempo’s naming conventions (no spaces, state at the end separated by a slash) and their capitalized names.
69 70 71 72 73 |
# File 'lib/climatempo/weather.rb', line 69 def forecast_for(place) @places[place] || @places.fetch(CAPITALS[place]) rescue raise UnknownLocationError, "Couldn't find #{place} among the forecasts" end |