Class: MyWeatherForecast::Daily

Inherits:
Hourly
  • Object
show all
Defined in:
lib/myweatherforecast.rb

Instance Attribute Summary

Attributes inherited from Hourly

#today

Instance Method Summary collapse

Methods inherited from Hourly

#afternoon, #ahead, #at, #detail, #early_hours, #emoji, #evening, #humidity, #icon, #morning, #night, #noon, #summary, #time, #visibility, #windspeed

Constructor Details

#initialize(forecast, tlabel, d = 0) ⇒ Daily

Returns a new instance of Daily.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/myweatherforecast.rb', line 228

def initialize(forecast, tlabel, d=0)

  @forecast = forecast

  @x = forecast['daily']['data'][d]
  @tlabel = tlabel

  found = forecast['hourly']['data'].detect do |hour|
    Time.at(@x.time).to_date == Time.at(hour.time).to_date
  end

  @i = forecast['hourly']['data'].index found

  return if @i.nil?

  @hourly_data = forecast['hourly']['data'][@i..-1]
  @day = self

end

Instance Method Details

#dayObject



248
249
250
# File 'lib/myweatherforecast.rb', line 248

def day()
  Date::ABBR_DAYNAMES[self.time.wday]
end

#sunriseObject



260
261
262
# File 'lib/myweatherforecast.rb', line 260

def sunrise()
  Time.at @x.sunriseTime
end

#sunsetObject



264
265
266
# File 'lib/myweatherforecast.rb', line 264

def sunset()
  Time.at @x.sunsetTime
end

#temperatureObject



268
269
# File 'lib/myweatherforecast.rb', line 268

def temperature()
end

#tempmaxObject



275
276
277
# File 'lib/myweatherforecast.rb', line 275

def tempmax
  "%s°" % [@x.temperatureMax.round]
end

#tempminObject



271
272
273
# File 'lib/myweatherforecast.rb', line 271

def tempmin
  "%s°" % [@x.temperatureMin.round]
end

#to_sObject



252
253
254
255
256
257
258
# File 'lib/myweatherforecast.rb', line 252

def to_s

  label = self.time.to_date == Time.now.to_date ? 'Today' : day()
  mask = @symbols ? "%s: ▽%s ▲%s, %s" : "%s: %s %s, %s"
  mask % [label, tempmin, tempmax, @x.summary]

end