class Barometer::Yahoo::Response::ForecastedWeather

Attributes

current_sun[R]
payload[R]
predictions[R]
timezone[R]

Public Class Methods

new(payload, timezone, current_sun) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 5
def initialize(payload, timezone, current_sun)
  @payload = payload
  @timezone = timezone
  @current_sun = current_sun
  @predictions = Barometer::Response::PredictionCollection.new
end

Public Instance Methods

parse() click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 12
def parse
  each_prediction do |prediction, forecast_payload|
    prediction.date = date(forecast_payload), timezone
    prediction.icon = icon(forecast_payload)
    prediction.condition = condition(forecast_payload)
    prediction.high = high(forecast_payload)
    prediction.low = low(forecast_payload)
    prediction.sun = sun(forecast_payload, prediction.starts_at, prediction.ends_at)
  end

  predictions
end

Private Instance Methods

condition(forecast_payload) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 49
def condition(forecast_payload)
  forecast_payload.fetch('@text')
end
date(forecast_payload) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 41
def date(forecast_payload)
  forecast_payload.fetch('@date')
end
each_prediction() { |prediction, forecast_payload| ... } click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 33
def each_prediction
  payload.fetch_each('item', 'forecast') do |forecast_payload|
    predictions.build do |prediction|
      yield prediction, forecast_payload
    end
  end
end
high(forecast_payload) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 53
def high(forecast_payload)
  [units, forecast_payload.fetch('@high')]
end
icon(forecast_payload) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 45
def icon(forecast_payload)
  forecast_payload.fetch('@code')
end
low(forecast_payload) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 57
def low(forecast_payload)
  [units, forecast_payload.fetch('@low')]
end
sun(forecast_payload, starts_at, ends_at) click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 61
def sun(forecast_payload, starts_at, ends_at)
  utc_rise_time = Utils::Time.utc_merge_base_plus_time(starts_at, current_sun.rise)
  utc_set_time = Utils::Time.utc_merge_base_plus_time(ends_at, current_sun.set)
  Data::Sun.new(rise: utc_rise_time, set: utc_set_time)
end
units() click to toggle source
# File lib/barometer/yahoo/response/forecasted_weather.rb, line 29
def units
  payload.units
end