class WeatherReport::Day
Attributes
date[R]
telop[R]
temperature_max[R]
temperature_min[R]
Public Class Methods
new(forecasts, dateLabel)
click to toggle source
# File lib/weather-report/day.rb, line 6 def initialize(forecasts, dateLabel) raise ArgumentError, "dateLabel must be 今日, 明日 or 明後日" unless dateLabel =~ /(今日|明日|明後日)/ forecast = forecast(forecasts, dateLabel) @telop = forecast['telop'] year, month, day = forecast['date'].split('-') @date = Date.new(year.to_i, month.to_i, day.to_i) temperature = forecast['temperature'] min = temperature['min'] max = temperature['max'] @temperature_min = min ? min['celsius'].to_i : nil @temperature_max = max ? max['celsius'].to_i : nil end
Public Instance Methods
rain?()
click to toggle source
@return [Boolean] return true if it rains.
# File lib/weather-report/day.rb, line 22 def rain? telop =~ /[雨]/ ? true : false end
snow?()
click to toggle source
@return [Boolean] return true if it snows.
# File lib/weather-report/day.rb, line 27 def snow? telop =~ /[雪]/ ? true : false end
to_h()
click to toggle source
@return [Hash] return with hash format.
# File lib/weather-report/day.rb, line 37 def to_h { "date" => date.to_s, "telop" => telop, "temperature_min" => temperature_min, "temperature_max" => temperature_max } end
umbrella?()
click to toggle source
@return [Boolean] return true if it will be rainy or snowy or sleety or hailstorm
# File lib/weather-report/day.rb, line 32 def umbrella? telop =~ /[雨雪霙雹]/ ? true : false end
Private Instance Methods
forecast(forecasts, dateLabel)
click to toggle source
# File lib/weather-report/day.rb, line 48 def forecast(forecasts, dateLabel) forecasts["forecasts"].each {|elem| return elem if elem["dateLabel"] == dateLabel} raise NoForecastError end