Class: WeatherJp::DayWeather
- Inherits:
-
Object
- Object
- WeatherJp::DayWeather
- Extended by:
- Forwardable
- Defined in:
- lib/weather_jp/day_weather.rb
Constant Summary collapse
- KEYS =
Canonical key names for attributes.
%i(text high low rain date date_text date_code city_name city)
Instance Attribute Summary collapse
-
#city ⇒ WeatherJp::City
readonly
The current value of city.
-
#date_code ⇒ Integer
readonly
Current is 0, today is 1, tomorrow is 2.
Instance Method Summary collapse
- #city_name ⇒ String
- #date ⇒ Date?
-
#date_text ⇒ String?
(also: #day)
Japanese date text from current day.
- #high ⇒ Integer? (also: #max_temp)
-
#initialize(attrs, city, date_code) ⇒ DayWeather
constructor
A new instance of DayWeather.
- #low ⇒ Integer? (also: #min_temp)
- #precip ⇒ Integer? (also: #rain)
-
#temperature ⇒ Integer?
Only available for current weather.
-
#text ⇒ String
(also: #forecast)
Sky status.
- #to_hash ⇒ Hash
- #to_s ⇒ String
-
#wind_speed ⇒ Integer?
Only available for current weather.
-
#wind_text ⇒ String?
Only available for current weather.
Constructor Details
#initialize(attrs, city, date_code) ⇒ DayWeather
Returns a new instance of DayWeather.
15 16 17 18 19 |
# File 'lib/weather_jp/day_weather.rb', line 15 def initialize(attrs, city, date_code) @attrs = attrs @city = city @date_code = date_code end |
Instance Attribute Details
#city ⇒ WeatherJp::City (readonly)
Returns the current value of city.
4 5 6 |
# File 'lib/weather_jp/day_weather.rb', line 4 def city @city end |
#date_code ⇒ Integer (readonly)
Current is 0, today is 1, tomorrow is 2
4 5 6 |
# File 'lib/weather_jp/day_weather.rb', line 4 def date_code @date_code end |
Instance Method Details
#city_name ⇒ String
22 23 24 |
# File 'lib/weather_jp/day_weather.rb', line 22 def city_name city.name end |
#date ⇒ Date?
67 68 69 |
# File 'lib/weather_jp/day_weather.rb', line 67 def date raw_date ? Date.parse(raw_date) : nil end |
#date_text ⇒ String? Also known as: day
Japanese date text from current day.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/weather_jp/day_weather.rb', line 73 def date_text case date_code when -1 "今" when 0 "今日" when 1 "明日" when 2 "明後日" else "#{date_code}日後" end end |
#high ⇒ Integer? Also known as: max_temp
33 34 35 |
# File 'lib/weather_jp/day_weather.rb', line 33 def high get('high').try(:to_i) end |
#low ⇒ Integer? Also known as: min_temp
38 39 40 |
# File 'lib/weather_jp/day_weather.rb', line 38 def low get('low').try(:to_i) end |
#precip ⇒ Integer? Also known as: rain
43 44 45 |
# File 'lib/weather_jp/day_weather.rb', line 43 def precip get('precip').try(:to_i) end |
#temperature ⇒ Integer?
Only available for current weather.
49 50 51 |
# File 'lib/weather_jp/day_weather.rb', line 49 def temperature get('temperature').try(:to_i) end |
#text ⇒ String Also known as: forecast
Sky status. i.e. ‘sunny’ or ‘晴れ’.
28 29 30 |
# File 'lib/weather_jp/day_weather.rb', line 28 def text @attrs['skytext'] || @attrs['skytextday'] end |
#to_hash ⇒ Hash
104 105 106 107 108 |
# File 'lib/weather_jp/day_weather.rb', line 104 def to_hash h = Hash[KEYS.map {|k| [k, public_send(k)] }] h[:city] = h[:city].to_hash h end |
#to_s ⇒ String
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/weather_jp/day_weather.rb', line 89 def to_s word ="#{date_text}の" word << "#{city_name}の天気は" word << "#{text}" word << ", 最高気温#{high}度" if high word << ", 最低気温#{low}度" if low word << ", 降水確率は#{precip}%" if precip word << "です。" word end |
#wind_speed ⇒ Integer?
Only available for current weather.
55 56 57 |
# File 'lib/weather_jp/day_weather.rb', line 55 def wind_speed get('windspeed').try(:to_i) end |
#wind_text ⇒ String?
Only available for current weather. i.e. ‘風向: 北北西 / 風速: 20 マイル’
62 63 64 |
# File 'lib/weather_jp/day_weather.rb', line 62 def wind_text get('winddisplay') end |