Class: JMACode::PointAmedas::Ame

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

Constant Summary collapse

HEADERS =
%i(
  government_branch_name
  code
  type
  name
  name_phonetic
  location
  lat_major
  lat_minor
  lng_major
  lng_minor
  altitude
  altitude_anemometer
  altitude_thermometer
  observation_started_since
  memo1
  memo2
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#altitudeObject

Returns the value of attribute altitude

Returns:

  • (Object)

    the current value of altitude



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

def altitude
  @altitude
end

#altitude_anemometerObject

Returns the value of attribute altitude_anemometer

Returns:

  • (Object)

    the current value of altitude_anemometer



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

def altitude_anemometer
  @altitude_anemometer
end

#altitude_thermometerObject

Returns the value of attribute altitude_thermometer

Returns:

  • (Object)

    the current value of altitude_thermometer



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

def altitude_thermometer
  @altitude_thermometer
end

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



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

def code
  @code
end

#government_branch_nameObject

Returns the value of attribute government_branch_name

Returns:

  • (Object)

    the current value of government_branch_name



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

def government_branch_name
  @government_branch_name
end

#latObject

Returns the value of attribute lat

Returns:

  • (Object)

    the current value of lat



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

def lat
  @lat
end

#lngObject

Returns the value of attribute lng

Returns:

  • (Object)

    the current value of lng



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

def lng
  @lng
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



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

def location
  @location
end

#managed_byObject

Returns the value of attribute managed_by

Returns:

  • (Object)

    the current value of managed_by



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

def managed_by
  @managed_by
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/jma_code/point_amedas.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_amedas.rb', line 4

def name_phonetic
  @name_phonetic
end

#observation_started_sinceObject

Returns the value of attribute observation_started_since

Returns:

  • (Object)

    the current value of observation_started_since



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

def observation_started_since
  @observation_started_since
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



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

def type
  @type
end

Class Method Details

.build_by_csv_row(row, managed_by: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jma_code/point_amedas.rb', line 56

def build_by_csv_row(row, managed_by: nil)
  new(
    code: row[:code], 
    name: row[:name], 
    name_phonetic: row[:name_phonetic],
    managed_by: managed_by,
    government_branch_name: row[:government_branch_name],
    type: row[:type],
    location: row[:location],
    lat: "#{row[:lat_major]}.#{row[:lat_minor]}".to_f,
    lng: "#{row[:lng_major]}.#{row[:lng_minor]}".to_f,
    altitude: row[:altitude],
    altitude_anemometer: row[:altitude_anemometer],
    altitude_thermometer: row[:altitude_thermometer],
    observation_started_since: row[:observation_started_since],
  )
end

.load(csv, num_headers: 2) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jma_code/point_amedas.rb', line 41

def load(csv, num_headers: 2)
  managed_by = nil
  list = []
  csv.each.with_index do |row, i|
    next if i < num_headers
    branch = row[:government_branch_name]
    if branch && branch.end_with?('管理')
      managed_by = branch
    else
      list << build_by_csv_row(row, managed_by: managed_by)
    end
  end
  list
end

.load_20240325(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jma_code/point_amedas.rb', line 29

def load_20240325(&block)
  path = File.join(File.dirname(__FILE__), "../../data/20240325_PointAmedas/ame_master.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: 2, &block)
    end
  end
end