Class: WeatherWeasel::Forecast

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_weasel/forecast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(city, state, client) ⇒ Forecast

Returns a new instance of Forecast.



5
6
7
8
9
# File 'lib/weather_weasel/forecast.rb', line 5

def initialize(city, state, client)
  @city = city
  @state = state
  @client = client
end

Instance Attribute Details

#rain_formatObject

Returns the value of attribute rain_format.



3
4
5
# File 'lib/weather_weasel/forecast.rb', line 3

def rain_format
  @rain_format
end

#temperature_formatObject

Returns the value of attribute temperature_format.



3
4
5
# File 'lib/weather_weasel/forecast.rb', line 3

def temperature_format
  @temperature_format
end

Instance Method Details

#all_highs(scale) ⇒ Object



53
54
55
56
57
58
# File 'lib/weather_weasel/forecast.rb', line 53

def all_highs(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["high"][@temperature_format].to_i
  end
end

#all_lows(scale) ⇒ Object



46
47
48
49
50
51
# File 'lib/weather_weasel/forecast.rb', line 46

def all_lows(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["low"][@temperature_format].to_i
  end
end

#all_max_wind(scale) ⇒ Object



65
66
67
68
69
70
# File 'lib/weather_weasel/forecast.rb', line 65

def all_max_wind(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["maxwind"][@wind_format]
  end
end

#all_snow_allday(scale) ⇒ Object



95
96
97
98
99
100
# File 'lib/weather_weasel/forecast.rb', line 95

def all_snow_allday(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["snow_allday"][@snow_format]
  end
end

#all_snow_day(scale) ⇒ Object

snow methods



73
74
75
76
77
78
# File 'lib/weather_weasel/forecast.rb', line 73

def all_snow_day(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["snow_day"][@snow_format]
  end
end

#all_snow_night(scale) ⇒ Object



88
89
90
91
92
93
# File 'lib/weather_weasel/forecast.rb', line 88

def all_snow_night(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["snow_night"][@snow_format]
  end
end

#day_high(day_index, format = @rain_format) ⇒ Object



38
39
40
# File 'lib/weather_weasel/forecast.rb', line 38

def day_high(day_index, format = @rain_format)
  all_highs(format)[day_index]
end

#forecast_condition(day_index) ⇒ Object

Forecast Condition methods



103
104
105
# File 'lib/weather_weasel/forecast.rb', line 103

def forecast_condition(day_index)
  forecast_conditions[day_index]
end

#forecast_conditionsObject



107
108
109
110
111
# File 'lib/weather_weasel/forecast.rb', line 107

def forecast_conditions
  forecast_days.collect do |day|
    day["conditions"]
  end
end

#forecast_daysObject



15
16
17
# File 'lib/weather_weasel/forecast.rb', line 15

def forecast_days    
  raw_data["forecast"]["simpleforecast"]["forecastday"]
end

#high(scale) ⇒ Object

Highs and lows methods



34
35
36
# File 'lib/weather_weasel/forecast.rb', line 34

def high(scale)
  all_highs(scale).max
end

#highest_snow_day(scale) ⇒ Object



80
81
82
# File 'lib/weather_weasel/forecast.rb', line 80

def highest_snow_day(scale)
  all_snow_day(scale).max
end

#low(scale) ⇒ Object



42
43
44
# File 'lib/weather_weasel/forecast.rb', line 42

def low(scale)
  all_lows(scale).min
end

#max_wind(scale) ⇒ Object

wind methods



61
62
63
# File 'lib/weather_weasel/forecast.rb', line 61

def max_wind(scale)
  all_max_wind(scale).max
end

#popsObject

POPs methods



133
134
135
136
137
# File 'lib/weather_weasel/forecast.rb', line 133

def pops
  forecast_days.collect do |day|
    day["pop"]
  end
end

#qpf_alldays(scale) ⇒ Object

QPF Methods



114
115
116
117
118
119
# File 'lib/weather_weasel/forecast.rb', line 114

def qpf_alldays(scale)
  set_scale(scale)
  forecast_days.collect do |day|
    day["qpf_allday"][@rain_format]
  end
end

#raw_dataObject



11
12
13
# File 'lib/weather_weasel/forecast.rb', line 11

def raw_data
  @data ||= @client.parse_url("forecast/q/#{@state}/#{@city}.json")
end

#set_scale(scale) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/weather_weasel/forecast.rb', line 19

def set_scale(scale)
  if scale == "imperial"  
    @temperature_format = "fahrenheit" 
    @wind_format = "mph"
    @snow_format = "in"
    @rain_format = "in"
  else
    @temperature_format = "celsius" 
    @wind_format = "kph"
    @snow_fomrat = "cm"
    @rain_format = "mm"
  end
end

#skyicon(day_index = 0) ⇒ Object

Skyicon Methods



122
123
124
# File 'lib/weather_weasel/forecast.rb', line 122

def skyicon(day_index = 0)
  skyicons[day_index]
end

#skyiconsObject



126
127
128
129
130
# File 'lib/weather_weasel/forecast.rb', line 126

def skyicons
  forecast_days.collect do |day|
    day["skyicon"]
  end
end

#snow_day(day_index, scale) ⇒ Object



84
85
86
# File 'lib/weather_weasel/forecast.rb', line 84

def snow_day(day_index, scale)
  all_snow_day(scale)[day_index]
end