Class: JMACode::PointSeismicIntensity
- Inherits:
-
Struct
- Object
- Struct
- JMACode::PointSeismicIntensity
- Defined in:
- lib/jma_code/point_seismic_intensity.rb
Constant Summary collapse
- CSV_ROW_SEP =
"\r\n"
- NUM_HEADER_ROWS =
1
- HEADERS =
%i( code name name_phonetic area_information_city_code used_by_regular_seismic_intensity used_by_realtime_seismic_intensity used_by_long_seismic_intensity )
Class Attribute Summary collapse
-
.data ⇒ Object
Returns the value of attribute data.
Instance Attribute Summary collapse
-
#area_information_city_code ⇒ Object
Returns the value of attribute area_information_city_code.
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_phonetic ⇒ Object
Returns the value of attribute name_phonetic.
-
#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: "20240618-completed") ⇒ Object
Instance Method Summary collapse
-
#area_information_city ⇒ Object
def prefecture @prefecture ||= Prefecture.get.find{|pref| pref.code == prefecture_code} end.
- #to_csv_row ⇒ Object
Class Attribute Details
.data ⇒ Object
Returns the value of attribute data.
23 24 25 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 23 def data @data end |
Instance Attribute Details
#area_information_city_code ⇒ Object
Returns the value of attribute area_information_city_code
4 5 6 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 4 def area_information_city_code @area_information_city_code end |
#code ⇒ Object
Returns the value of attribute code
4 5 6 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 4 def code @code end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 4 def name @name end |
#name_phonetic ⇒ Object
Returns the value of attribute name_phonetic
4 5 6 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 4 def name_phonetic @name_phonetic end |
#used_by ⇒ Object
Returns the value of attribute used_by
4 5 6 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 4 def used_by @used_by end |
Class Method Details
.build_by_csv_row(row) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 45 def build_by_csv_row(row) used_by_fields = HEADERS.select{|n| n.to_s.start_with?('used_by_')} new( code: row[:code], name: row[:name], name_phonetic: row[:name_phonetic], area_information_city_code: row[:area_information_city_code], used_by: used_by_fields.select{|f| row[f] == '1'}.map{|f| f.to_s.sub(/\Aused_by_/, '').to_sym} ) end |
.get ⇒ Object
41 42 43 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 41 def get @data ||= load end |
.load(**args) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 33 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: "20240618-completed") ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 25 def load_csv(version: "20240618-completed") path = File.join(File.dirname(__FILE__), "../../data/#{version}_Volcano-Earthquake/PointSeismicIntensity.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_information_city ⇒ Object
65 66 67 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 65 def area_information_city @area_information_city ||= AreaInformationCity.get.find{|x| x.code == area_information_city_code} end |
#to_csv_row ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jma_code/point_seismic_intensity.rb', line 69 def to_csv_row HEADERS.map do |k| if respond_to?(k) public_send(k) else if k.to_s.start_with?("used_by_") x = k.to_s.sub('used_by_', '').to_sym used_by.include?(x) ? '1' : nil end end end end |