Class: WeatherCli::Weather

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, *options) ⇒ Weather



8
9
10
11
# File 'lib/weathercli/weather.rb', line 8

def initialize(location, *options)
  @options = Hash[options.map { |o| [o, true] }]
  get_weather(location)
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



6
7
8
# File 'lib/weathercli/weather.rb', line 6

def conditions
  @conditions
end

#forecastsObject (readonly)

Returns the value of attribute forecasts.



6
7
8
# File 'lib/weathercli/weather.rb', line 6

def forecasts
  @forecasts
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/weathercli/weather.rb', line 6

def location
  @location
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/weathercli/weather.rb', line 6

def options
  @options
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/weathercli/weather.rb', line 6

def title
  @title
end

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/weathercli/weather.rb', line 13

def to_s
  todays_forecast = forecasts.first
  tomorrows_forecast = forecasts.last
  [
    title,
    "#{conditions['temp']} degrees Farenheit; #{conditions['text']}",
    "Today's forecast: High of #{todays_forecast['high']}, Low of #{todays_forecast['low']}; #{todays_forecast['text']}",
    "Tomorrow's forecast: High of #{tomorrows_forecast['high']}, Low of #{tomorrows_forecast['low']}; #{tomorrows_forecast['text']}"
  ].join("\n")
end