Class: ClimaTempo::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/climatempo/weather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#airportsObject (readonly)

Returns the value of attribute airports.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def airports
  @airports
end

#brazilObject (readonly)

Returns the value of attribute brazil.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def brazil
  @brazil
end

#capitalsObject (readonly)

Returns the value of attribute capitals.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def capitals
  @capitals
end

#fetcherObject (readonly)

Returns the value of attribute fetcher.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def fetcher
  @fetcher
end

#parserObject (readonly)

Returns the value of attribute parser.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def parser
  @parser
end

#placesObject (readonly)

Returns the value of attribute places.



43
44
45
# File 'lib/climatempo/weather.rb', line 43

def places
  @places
end

#regionsObject (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