Class: JMACode::PointSeismicIntensity

Inherits:
Struct
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.dataObject

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_codeObject

Returns the value of attribute area_information_city_code

Returns:

  • (Object)

    the current value of 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

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



4
5
6
# File 'lib/jma_code/point_seismic_intensity.rb', line 4

def code
  @code
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/jma_code/point_seismic_intensity.rb', line 4

def name
  @name
end

#name_phoneticObject

Returns the value of attribute name_phonetic

Returns:

  • (Object)

    the current value of name_phonetic



4
5
6
# File 'lib/jma_code/point_seismic_intensity.rb', line 4

def name_phonetic
  @name_phonetic
end

#used_byObject

Returns the value of attribute used_by

Returns:

  • (Object)

    the current value of 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

.getObject



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_cityObject

def prefecture

@prefecture ||= Prefecture.get.find{|pref| pref.code == prefecture_code}

end



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_rowObject



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