Class: MyWeatherForecast::Hourly
- Inherits:
-
Object
- Object
- MyWeatherForecast::Hourly
- Defined in:
- lib/myweatherforecast.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#today ⇒ Object
readonly
Returns the value of attribute today.
Instance Method Summary collapse
- #afternoon ⇒ Object
- #ahead(advance = 2) ⇒ Object
- #at(raw_hour) ⇒ Object
- #detail ⇒ Object
- #early_hours ⇒ Object
- #emoji ⇒ Object
- #evening ⇒ Object
- #humidity ⇒ Object
- #icon ⇒ Object
-
#initialize(forecast, tlabel, i = 0) ⇒ Hourly
constructor
A new instance of Hourly.
- #morning ⇒ Object
- #night ⇒ Object
- #noon ⇒ Object (also: #midday)
- #summary ⇒ Object
- #sunrise ⇒ Object
- #sunset ⇒ Object (also: #night_time)
- #temperature ⇒ Object (also: #temp)
- #time ⇒ Object
- #to_s ⇒ Object
- #visibility ⇒ Object
- #windspeed ⇒ Object
Constructor Details
#initialize(forecast, tlabel, i = 0) ⇒ Hourly
Returns a new instance of Hourly.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/myweatherforecast.rb', line 65 def initialize(forecast, tlabel, i=0) @forecast, @tlabel, @i = forecast, tlabel, i @x, @hourly_data = if i > 0 then [forecast['hourly']['data'][i], forecast['hourly']['data'][i..-1]] else [forecast.currently, forecast['hourly']['data']] end #@speed_label = 'kph' @speed_label = 'mph' #if @forecast['flags']['units'][/^uk2$/] end |
Instance Attribute Details
#today ⇒ Object (readonly)
Returns the value of attribute today.
63 64 65 |
# File 'lib/myweatherforecast.rb', line 63 def today @today end |
Instance Method Details
#afternoon ⇒ Object
114 |
# File 'lib/myweatherforecast.rb', line 114 def afternoon() period(12, 17) end |
#ahead(advance = 2) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/myweatherforecast.rb', line 93 def ahead(advance=2) current_hour = Time.at(@hourly_data[0]['time']).hour + advance name = case current_hour when 12..17 :afternoon when 0..5 :early_hours when 17..(night_time.hour+1) :evening when 6..12 :morning when night_time.hour..23 :night end method(name).call end |
#at(raw_hour) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/myweatherforecast.rb', line 80 def at(raw_hour) hour = Time.parse(raw_hour).hour i = 0 return if Time.at(@hourly_data[i]['time']).hour > hour i += 1 until Time.at(@hourly_data[i]['time']).hour == hour Hourly.new(@forecast, @tlabel, i+@i) end |
#detail ⇒ Object
115 |
# File 'lib/myweatherforecast.rb', line 115 def detail() period(0, 23) end |
#early_hours ⇒ Object
116 |
# File 'lib/myweatherforecast.rb', line 116 def early_hours() period(0, 5) end |
#emoji ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/myweatherforecast.rb', line 118 def emoji() h = { 'clear-day' => :sun, 'clear-night' => :night_with_stars, 'rain' => :cloud_with_rain, 'snow' => :cloud_with_snow, 'sleet' => :cloud_with_rain, 'wind' => :leaf_fluttering_in_wind, 'fog' => :fog, 'cloudy' => :cloud, 'partly-cloudy-day' => :sun_behind_cloud, 'partly-cloudy-night' => :cloud } Emoji2020.new(h[icon()]).to_s end |
#evening ⇒ Object
137 |
# File 'lib/myweatherforecast.rb', line 137 def evening() period(17, night_time.hour+1) end |
#humidity ⇒ Object
145 146 147 |
# File 'lib/myweatherforecast.rb', line 145 def humidity() @x.humidity end |
#icon ⇒ Object
149 150 151 |
# File 'lib/myweatherforecast.rb', line 149 def icon() @x.icon end |
#morning ⇒ Object
138 |
# File 'lib/myweatherforecast.rb', line 138 def morning() period(6, 12) end |
#night ⇒ Object
139 |
# File 'lib/myweatherforecast.rb', line 139 def night() period(night_time.hour, 23) end |
#noon ⇒ Object Also known as: midday
153 154 155 |
# File 'lib/myweatherforecast.rb', line 153 def noon() at_hour 12 end |
#summary ⇒ Object
166 167 168 |
# File 'lib/myweatherforecast.rb', line 166 def summary() @x.summary end |
#sunrise ⇒ Object
170 171 172 |
# File 'lib/myweatherforecast.rb', line 170 def sunrise() @day.sunrise end |
#sunset ⇒ Object Also known as: night_time
174 175 176 |
# File 'lib/myweatherforecast.rb', line 174 def sunset() @day.sunset end |
#temperature ⇒ Object Also known as: temp
180 181 182 |
# File 'lib/myweatherforecast.rb', line 180 def temperature "%s°" % @x.temperature.round end |
#time ⇒ Object
186 187 188 |
# File 'lib/myweatherforecast.rb', line 186 def time Time.at @x.time end |
#to_s ⇒ Object
159 160 161 162 163 164 |
# File 'lib/myweatherforecast.rb', line 159 def to_s r = "%s: %d%s, %s" % [self.time.strftime("%-I%P"), @x.temperature.round, \ @tlabel, @x.summary] r << ", %s" % [windspeed] if r[/windy|breezy/i] r end |
#visibility ⇒ Object
190 191 192 |
# File 'lib/myweatherforecast.rb', line 190 def visibility() @x.visibility end |
#windspeed ⇒ Object
194 195 196 |
# File 'lib/myweatherforecast.rb', line 194 def windspeed() "%s%s" % [@x.windSpeed.round, @speed_label] end |