class NoaaWeatherClient::Responses::Forecast
Constants
- TimePeriod
Attributes
body[R]
Public Class Methods
new(hashed_response)
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 11 def initialize(hashed_response) @body = XmlParserFactory.build_parser.parse hashed_response[:ndf_dgen_by_day_response][:dwml_by_day_out] validate! @body, :dwml end
Public Instance Methods
days()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 24 def days @days ||= build_days end
each() { |d| ... }
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 16 def each days.each { |d| yield d } end
size()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 20 def size days.size end
Private Instance Methods
build_day_params(period, index)
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 69 def build_day_params(period, index) { start_time: Time.parse(period.start_time.to_s), end_time: Time.parse(period.end_time.to_s), name: Time.parse(period.start_time.to_s).strftime("%A"), maximum_temperature: parameters.css('temperature[type=maximum] value')[index].text.to_f, minimum_temperature: parameters.css('temperature[type=minimum] value')[index].text.to_f, weather_summary: parameters.css('weather weather-conditions')[index]['weather-summary'] } end
build_days()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 58 def build_days unless @days @day = [].tap do |arr| time_layout_periods.each_with_index do |p, i| params = build_day_params p, i arr << Day.new(params) end end end end
layout_key()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 36 def layout_key @layout_key ||= time_layout.css('layout-key').text end
parameters()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 40 def parameters @paramteters ||= body.css('parameters') end
time_layout()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 32 def time_layout @time_layout ||= body.css("time-layout[summarization='24hourly']").first end
time_layout_periods()
click to toggle source
# File lib/noaa_weather_client/responses/forecast.rb, line 44 def time_layout_periods unless @time_layout_periods periods = time_layout.element_children.to_a periods.shift #remove layout-key @time_layout_periods = [].tap do |arr| periods.each_slice(2) do |slice| name = slice.first['period-name'] arr << TimePeriod.new(*slice, name) end end end @time_layout_periods end