class Barometer::WeatherBug::Response::ForecastedWeather

Attributes

payload[R]
predictions[R]

Public Class Methods

new(payload) click to toggle source
# File lib/barometer/weather_bug/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/weather_bug/response/forecasted_weather.rb, line 10
def parse
  each_prediction do |prediction, forecast_payload, index|
    prediction.starts_at = starts_at(forecast_payload)
    prediction.ends_at = ends_at(prediction.starts_at)
    prediction.condition = condition(forecast_payload)
    prediction.icon = icon(forecast_payload)
    prediction.pop = pop(forecast_payload)

    if is_day?(forecast_payload)
      prediction.high = high(forecast_payload)
    else
      prediction.low = low(forecast_payload)
    end
  end

  predictions
end

Private Instance Methods

condition(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 53
def condition(forecast_payload)
  forecast_payload.fetch('summaryDescription')
end
each_prediction() { |prediction, forecast_payload, index| ... } click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 36
def each_prediction
  payload.fetch_each_with_index('dailyForecastPeriods') do |forecast_payload, index|
    predictions.build do |prediction|
      yield prediction, forecast_payload, index
    end
  end
end
ends_at(starts_at) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 48
def ends_at(starts_at)
  half_a_day_minus_one_second = (12 * 60 * 60 - 1)
  starts_at + half_a_day_minus_one_second
end
high(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 61
def high(forecast_payload)
  [units, forecast_payload.fetch('temperature')]
end
icon(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 57
def icon(forecast_payload)
  forecast_payload.fetch('iconCode')
end
is_day?(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 73
def is_day?(forecast_payload)
  !forecast_payload.fetch('isNightTimePeriod')
end
low(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 65
def low(forecast_payload)
  [units, forecast_payload.fetch('temperature')]
end
pop(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 69
def pop(forecast_payload)
  forecast_payload.fetch('precipProbability')
end
starts_at(forecast_payload) click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 44
def starts_at(forecast_payload)
  Utils::Time.parse(forecast_payload.fetch('forecastDateUtcStr'), '%Y-%m-%dT%H:%M:%S%z')
end
units() click to toggle source
# File lib/barometer/weather_bug/response/forecasted_weather.rb, line 32
def units
  payload.units
end