class WeatherSage::Weather::Forecast

Numerical weather forecast.

Attributes

data[RW]

Public Class Methods

new(ctx, data) click to toggle source

Create new forecast object from given data.

# File lib/weather-sage/weather/forecast.rb, line 20
def initialize(ctx, data)
  # cache context and data, get properties
  @ctx, @data = ctx, data.freeze
  props = @data['properties']

  # log data
  @ctx.log.debug('Forecast#initialize') do
    'data = %p' % [@data]
  end

  @updated_at = Time.parse(props['updated'])
  @units = props['units']
  @generator = props['generator']
  @generated_at = Time.parse(props['generatedAt'])
  @update_time = Time.parse(props['updateTime'])
  @valid_times = props['validTimes']
  @elevation = props['elevation']['value']
end

Public Instance Methods

periods() click to toggle source

Return an array of periods for this forecast.

# File lib/weather-sage/weather/forecast.rb, line 42
def periods
  @periods ||= @data['properties']['periods'].map { |row|
    ::WeatherSage::Weather::Period.new(@ctx, row)
  }
end