Class: JMACode::PointAmedas::Snow

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
  observation_started_since
)

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



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def altitude
  @altitude
end

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def code
  @code
end

#government_branch_nameObject

Returns the value of attribute government_branch_name

Returns:

  • (Object)

    the current value of government_branch_name



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def government_branch_name
  @government_branch_name
end

#latObject

Returns the value of attribute lat

Returns:

  • (Object)

    the current value of lat



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def lat
  @lat
end

#lngObject

Returns the value of attribute lng

Returns:

  • (Object)

    the current value of lng



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def lng
  @lng
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def location
  @location
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def name
  @name
end

#name_phoneticObject

Returns the value of attribute name_phonetic

Returns:

  • (Object)

    the current value of name_phonetic



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

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



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def observation_started_since
  @observation_started_since
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



76
77
78
# File 'lib/jma_code/point_amedas.rb', line 76

def type
  @type
end

Class Method Details

.build_by_csv_row(row) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/jma_code/point_amedas.rb', line 118

def build_by_csv_row(row)
  new(
    code: row[:code], 
    name: row[:name], 
    name_phonetic: row[:name_phonetic],
    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],
    observation_started_since: row[:observation_started_since],
  )
end

.load(csv, num_headers: 2) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/jma_code/point_amedas.rb', line 109

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

.load_20240325(&block) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/jma_code/point_amedas.rb', line 97

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