Class: JMACode::AreaForecastLocal

Inherits:
Struct
  • Object
show all
Defined in:
lib/jma_code/area_forecast_local.rb

Constant Summary collapse

HEADERS =
%i(
  code
  name
  name_phonetic
)

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.area_information_citiesObject

Returns the value of attribute area_information_cities.



16
17
18
# File 'lib/jma_code/area_forecast_local.rb', line 16

def area_information_cities
  @area_information_cities
end

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



5
6
7
# File 'lib/jma_code/area_forecast_local.rb', line 5

def code
  @code
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/jma_code/area_forecast_local.rb', line 5

def name
  @name
end

#name_phoneticObject

Returns the value of attribute name_phonetic

Returns:

  • (Object)

    the current value of name_phonetic



5
6
7
# File 'lib/jma_code/area_forecast_local.rb', line 5

def name_phonetic
  @name_phonetic
end

#used_byObject

Returns the value of attribute used_by

Returns:

  • (Object)

    the current value of used_by



5
6
7
# File 'lib/jma_code/area_forecast_local.rb', line 5

def used_by
  @used_by
end

Class Method Details

.build_by_csv_row(row) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/jma_code/area_forecast_local.rb', line 39

def build_by_csv_row(row)
  new(
    code: row[:code], 
    name: row[:name], 
    name_phonetic: row[:name_phonetic],
  )
end

.load(csv, num_headers: 3) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/jma_code/area_forecast_local.rb', line 30

def load(csv, num_headers: 3)
  list = []
  csv.each.with_index do |row, i|
    next if i < num_headers
    list << build_by_csv_row(row)
  end
  list
end

.load_20240216(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jma_code/area_forecast_local.rb', line 18

def load_20240216(&block)
  path = File.join(File.dirname(__FILE__), "../../data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(コード表).csv")
  File.open(path) do |f|
    csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
    if block_given?
      yield(csv)
    else
      load(csv, num_headers: 3, &block)
    end
  end
end

Instance Method Details

#area_information_cityObject



48
49
50
# File 'lib/jma_code/area_forecast_local.rb', line 48

def area_information_city
  @area_information_city ||= (self.class.area_information_cities || []).find{|x| x.area_forecast_local_code == code}
end