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
- #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
112 |
# File 'lib/myweatherforecast.rb', line 112 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 |
# File 'lib/myweatherforecast.rb', line 93 def ahead(advance=2) current_hour = Time.at(@hourly_data[0]['time']).hour + advance 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 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 |
#early_hours ⇒ Object
113 |
# File 'lib/myweatherforecast.rb', line 113 def early_hours() period(0, 5) end |
#emoji ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/myweatherforecast.rb', line 115 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
134 |
# File 'lib/myweatherforecast.rb', line 134 def evening() period(17, night_time.hour+1) end |
#humidity ⇒ Object
142 143 144 |
# File 'lib/myweatherforecast.rb', line 142 def humidity() @x.humidity end |
#icon ⇒ Object
146 147 148 |
# File 'lib/myweatherforecast.rb', line 146 def icon() @x.icon end |
#morning ⇒ Object
135 |
# File 'lib/myweatherforecast.rb', line 135 def morning() period(6, 12) end |
#night ⇒ Object
136 |
# File 'lib/myweatherforecast.rb', line 136 def night() period(night_time.hour, 23) end |
#noon ⇒ Object Also known as: midday
150 151 152 |
# File 'lib/myweatherforecast.rb', line 150 def noon() at_hour 12 end |
#summary ⇒ Object
163 164 165 |
# File 'lib/myweatherforecast.rb', line 163 def summary() @x.summary end |
#sunrise ⇒ Object
167 168 169 |
# File 'lib/myweatherforecast.rb', line 167 def sunrise() @day.sunrise end |
#sunset ⇒ Object Also known as: night_time
171 172 173 |
# File 'lib/myweatherforecast.rb', line 171 def sunset() @day.sunset end |
#temperature ⇒ Object Also known as: temp
177 178 179 |
# File 'lib/myweatherforecast.rb', line 177 def temperature "%s°" % @x.temperature.round end |
#time ⇒ Object
183 184 185 |
# File 'lib/myweatherforecast.rb', line 183 def time Time.at @x.time end |
#to_s ⇒ Object
156 157 158 159 160 161 |
# File 'lib/myweatherforecast.rb', line 156 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
187 188 189 |
# File 'lib/myweatherforecast.rb', line 187 def visibility() @x.visibility end |
#windspeed ⇒ Object
191 192 193 |
# File 'lib/myweatherforecast.rb', line 191 def windspeed() "%s%s" % [@x.windSpeed.round, @speed_label] end |