class MyWeatherForecast::Daily

Public Class Methods

new(forecast, tlabel, d=0) click to toggle source
# 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

Public Instance Methods

day() click to toggle source
# File lib/myweatherforecast.rb, line 248
def day()
  Date::ABBR_DAYNAMES[self.time.wday]
end
sunrise() click to toggle source
# File lib/myweatherforecast.rb, line 260
def sunrise()
  Time.at @x.sunriseTime
end
sunset() click to toggle source
# File lib/myweatherforecast.rb, line 264
def sunset()
  Time.at @x.sunsetTime
end
temperature() click to toggle source
# File lib/myweatherforecast.rb, line 268
def temperature()
end
tempmax() click to toggle source
# File lib/myweatherforecast.rb, line 275
def tempmax
  "%s°" % [@x.temperatureMax.round]
end
tempmin() click to toggle source
# File lib/myweatherforecast.rb, line 271
def tempmin
  "%s°" % [@x.temperatureMin.round]
end
to_s() click to toggle source
# 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