Class: JMACode::AreaInformationCity
- Inherits:
-
Struct
- Object
- Struct
- JMACode::AreaInformationCity
- Defined in:
- lib/jma_code/area_information_city.rb
Constant Summary collapse
- CSV_ROW_SEP =
"\r\n"- NUM_HEADER_ROWS =
3- HEADERS =
%i( code long_name name_used_by_weather name_phonetic_used_by_weather area_forecast_local_code used_by_weather used_by_tornado used_by_storm_surge used_by_high_wave used_by_landslide used_by_flood name_used_by_earthquake name_phonetic_used_by_earthquake name_used_by_volcano name_phonetic_used_by_volcano name_used_by_uv name_phonetic_used_by_uv name_used_by_rainstorm name_phonetic_used_by_rainstorm )
Class Attribute Summary collapse
-
.data ⇒ Object
Returns the value of attribute data.
Instance Attribute Summary collapse
-
#alt_name ⇒ Object
Returns the value of attribute alt_name.
-
#alt_name_phonetic ⇒ Object
Returns the value of attribute alt_name_phonetic.
-
#area_forecast_local_code ⇒ Object
Returns the value of attribute area_forecast_local_code.
-
#code ⇒ Object
Returns the value of attribute code.
-
#long_name ⇒ Object
Returns the value of attribute long_name.
-
#used_by ⇒ Object
Returns the value of attribute used_by.
Class Method Summary collapse
- .build_by_csv_row(row) ⇒ Object
- .get ⇒ Object
- .load(**args) ⇒ Object
- .load_csv(version: "20240216") ⇒ Object
Instance Method Summary collapse
- #area_forecast_local ⇒ Object
- #child_of?(area_or_city) ⇒ Boolean
- #name ⇒ Object
- #name_phonetic ⇒ Object
- #prefecture_code ⇒ Object
- #to_h ⇒ Object
Class Attribute Details
.data ⇒ Object
Returns the value of attribute data.
35 36 37 |
# File 'lib/jma_code/area_information_city.rb', line 35 def data @data end |
Instance Attribute Details
#alt_name ⇒ Object
Returns the value of attribute alt_name
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def alt_name @alt_name end |
#alt_name_phonetic ⇒ Object
Returns the value of attribute alt_name_phonetic
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def alt_name_phonetic @alt_name_phonetic end |
#area_forecast_local_code ⇒ Object
Returns the value of attribute area_forecast_local_code
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def area_forecast_local_code @area_forecast_local_code end |
#code ⇒ Object
Returns the value of attribute code
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def code @code end |
#long_name ⇒ Object
Returns the value of attribute long_name
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def long_name @long_name end |
#used_by ⇒ Object
Returns the value of attribute used_by
5 6 7 |
# File 'lib/jma_code/area_information_city.rb', line 5 def used_by @used_by end |
Class Method Details
.build_by_csv_row(row) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/jma_code/area_information_city.rb', line 57 def build_by_csv_row(row) alt_name, alt_name_phonetic = if row[:name_used_by_weather].present? [row[:name_used_by_weather], row[:name_phonetic_used_by_weather]] elsif row[:name_used_by_earthquake].present? [row[:name_used_by_earthquake], row[:name_phonetic_used_by_earthquake]] elsif row[:name_used_by_volcano].present? [row[:name_used_by_volcano], row[:name_phonetic_used_by_volcano]] elsif row[:name_used_by_uv].present? [row[:name_used_by_uv], row[:name_phonetic_used_by_uv]] elsif row[:name_used_by_rainstorm].present? [row[:name_used_by_rainstorm], row[:name_phonetic_used_by_rainstorm]] else [] end new( code: row[:code], long_name: row[:long_name], alt_name: alt_name, alt_name_phonetic: alt_name_phonetic, area_forecast_local_code: row[:area_forecast_local_code], used_by: [ row[:used_by_weather] == '1' ? :weather : nil, row[:used_by_tornado] == '1' ? :tornado : nil, row[:used_by_storm_surge] == '1' ? :storm_surge : nil, row[:used_by_high_wave] == '1' ? :high_wave : nil, row[:used_by_landslide] == '1' ? :landslide : nil, row[:used_by_flood] == '1' ? :flood : nil, row[:name_used_by_earthquake].present? ? :earthquake : nil, row[:name_used_by_volcano].present? ? :volcano : nil, row[:name_used_by_uv].present? ? :uv : nil, row[:name_used_by_rainstorm].present? ? :rainstorm : nil, ].compact ) end |
.get ⇒ Object
53 54 55 |
# File 'lib/jma_code/area_information_city.rb', line 53 def get @data ||= load end |
.load(**args) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/jma_code/area_information_city.rb', line 45 def load(**args) load_csv(**args) do |csv| csv.drop(NUM_HEADER_ROWS).map do |row| build_by_csv_row(row) end end end |
.load_csv(version: "20240216") ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/jma_code/area_information_city.rb', line 37 def load_csv(version: "20240216") path = File.join(File.dirname(__FILE__), "../../data/#{version}_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv") File.open(path) do |f| csv = CSV.new(f, headers: HEADERS, row_sep: CSV_ROW_SEP) yield(csv) end end |
Instance Method Details
#area_forecast_local ⇒ Object
106 107 108 |
# File 'lib/jma_code/area_information_city.rb', line 106 def area_forecast_local @area_forecast_local ||= AreaForecastLocal.get.find{|x| x.code == area_forecast_local_code} end |
#child_of?(area_or_city) ⇒ Boolean
110 111 112 |
# File 'lib/jma_code/area_information_city.rb', line 110 def child_of?(area_or_city) area_forecast_local_code == area_or_city.code end |
#name ⇒ Object
94 95 96 |
# File 'lib/jma_code/area_information_city.rb', line 94 def name alt_name.presence || long_name end |
#name_phonetic ⇒ Object
98 99 100 |
# File 'lib/jma_code/area_information_city.rb', line 98 def name_phonetic alt_name_phonetic end |
#prefecture_code ⇒ Object
102 103 104 |
# File 'lib/jma_code/area_information_city.rb', line 102 def prefecture_code @prefecture_code ||= code[0, 2] end |
#to_h ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/jma_code/area_information_city.rb', line 114 def to_h { code: code, name: name, name_phonetic: name_phonetic, area_forecast_local_code: area_forecast_local_code, used_by: used_by, } end |