Class: WeatherReport::Day
- Inherits:
-
Object
- Object
- WeatherReport::Day
- Defined in:
- lib/weather-report/day.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#telop ⇒ Object
readonly
Returns the value of attribute telop.
-
#temperature_max ⇒ Object
readonly
Returns the value of attribute temperature_max.
-
#temperature_min ⇒ Object
readonly
Returns the value of attribute temperature_min.
Instance Method Summary collapse
-
#initialize(forecasts, dateLabel) ⇒ Day
constructor
A new instance of Day.
-
#rain? ⇒ Boolean
Return true if it rains.
-
#snow? ⇒ Boolean
Return true if it snows.
-
#to_h ⇒ Hash
Return with hash format.
-
#umbrella? ⇒ Boolean
Return true if it will be rainy or snowy or sleety or hailstorm.
Constructor Details
#initialize(forecasts, dateLabel) ⇒ Day
Returns a new instance of Day.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/weather-report/day.rb', line 7 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 |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
5 6 7 |
# File 'lib/weather-report/day.rb', line 5 def date @date end |
#telop ⇒ Object (readonly)
Returns the value of attribute telop.
5 6 7 |
# File 'lib/weather-report/day.rb', line 5 def telop @telop end |
#temperature_max ⇒ Object (readonly)
Returns the value of attribute temperature_max.
5 6 7 |
# File 'lib/weather-report/day.rb', line 5 def temperature_max @temperature_max end |
#temperature_min ⇒ Object (readonly)
Returns the value of attribute temperature_min.
5 6 7 |
# File 'lib/weather-report/day.rb', line 5 def temperature_min @temperature_min end |
Instance Method Details
#rain? ⇒ Boolean
Return true if it rains.
23 24 25 |
# File 'lib/weather-report/day.rb', line 23 def rain? telop =~ /[雨]/ ? true : false end |
#snow? ⇒ Boolean
Return true if it snows.
28 29 30 |
# File 'lib/weather-report/day.rb', line 28 def snow? telop =~ /[雪]/ ? true : false end |
#to_h ⇒ Hash
Return with hash format.
38 39 40 41 42 43 44 45 |
# File 'lib/weather-report/day.rb', line 38 def to_h { "date" => date.to_s, "telop" => telop, "temperature_min" => temperature_min, "temperature_max" => temperature_max } end |
#umbrella? ⇒ Boolean
Return true if it will be rainy or snowy or sleety or hailstorm
33 34 35 |
# File 'lib/weather-report/day.rb', line 33 def umbrella? telop =~ /[雨雪霙雹]/ ? true : false end |