class Barometer::ForecastIo::Response::ForecastedWeather

Attributes

payload[R]
predictions[R]

Public Class Methods

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

Public Instance Methods

parse() click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 10
def parse
  each_prediction do |prediction, forecast_payload|
    prediction.starts_at = starts_at(forecast_payload)
    prediction.ends_at = Utils::Time.add_one_day(prediction.starts_at)
    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/forecast_io/response/forecasted_weather.rb, line 48
def condition(forecast_payload)
  forecast_payload.fetch('summary')
end
each_prediction() { |prediction, forecast_payload| ... } click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 32
def each_prediction
  payload.fetch_each('daily', 'data') do |forecast_payload|
    predictions.build do |prediction|
      yield prediction, forecast_payload
    end
  end
end
high(forecast_payload) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 52
def high(forecast_payload)
  [units, forecast_payload.fetch('temperatureMax')]
end
icon(forecast_payload) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 44
def icon(forecast_payload)
  forecast_payload.fetch('icon')
end
low(forecast_payload) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 56
def low(forecast_payload)
  [units, forecast_payload.fetch('temperatureMin')]
end
starts_at(forecast_payload) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 40
def starts_at(forecast_payload)
  time(forecast_payload.fetch('time'))
end
sun(forecast_payload, starts_at, ends_at) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 60
def sun(forecast_payload, starts_at, ends_at)
  utc_rise_time = time(forecast_payload.fetch('sunriseTime'))
  utc_set_time = time(forecast_payload.fetch('sunsetTime'))
  Data::Sun.new(rise: utc_rise_time, set: utc_set_time)
end
time(timestamp) click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 66
def time(timestamp)
  Time.at(timestamp.to_i)
end
units() click to toggle source
# File lib/barometer/forecast_io/response/forecasted_weather.rb, line 28
def units
  payload.units
end