Sha256: 13f84bd82f00feafd2e5e3c184da2c1c448e81b030a0fafc1e8e5a55adae7001
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
# -*- coding: utf-8 -*- module WeatherReport class Day attr_reader :date, :telop, :temperature_min, :temperature_max def initialize(forecasts, dateLabel) @forecast = forecast(forecasts, dateLabel) end # @return [Date] the date def date year, month, day = @forecast["date"].split('-') @date ||= Date.new(year.to_i, month.to_i, day.to_i) end # @return [String] the telop def telop @telop ||= @forecast["telop"] end # @return [Fixnum] the minimum temperature. # Temperature of today could be nil. def temperature_min min = @forecast["temperature"]["min"] @temperature ||= min ? min["celsius"].to_i : nil end # @return [Fixnum] the maximum temperature. # Temperature of today could be nil. def temperature_max max = @forecast["temperature"]["max"] @temperature_max ||= max ? max["celsius"].to_i : nil end def to_h { "date" => date.to_s, "telop" => telop, "temperature_min" => temperature_min, "temperature_max" => temperature_max } end private def forecast(forecasts, dateLabel) forecasts["forecasts"].each {|elem| return elem if elem["dateLabel"] == dateLabel} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
weather-report-0.2.1 | lib/weather-report/day.rb |
weather-report-0.2.0 | lib/weather-report/day.rb |