Class: WeatherReport::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/weather-report/day.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forecasts, dateLabel) ⇒ Day

Returns a new instance of Day.

Raises:



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

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/weather-report/day.rb', line 5

def date
  @date
end

#telopObject (readonly)

Returns the value of attribute telop.



5
6
7
# File 'lib/weather-report/day.rb', line 5

def telop
  @telop
end

#temperature_maxObject (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_minObject (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.

Returns:

  • (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.

Returns:

  • (Boolean)

    return true if it snows.



28
29
30
# File 'lib/weather-report/day.rb', line 28

def snow?
  telop =~ /[雪]/ ? true : false
end

#to_hHash

Return with hash format.

Returns:

  • (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

Returns:

  • (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