Class: JMACode::WmoObservingStation

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

Constant Summary collapse

HEADERS =
%i(
  code 
  name 
  name_phonetic
  lat_major
  lat_minor
  lng_major
  lng_minor
  long_name
  used_by_bioseasonal
  used_by_seasonal
  used_by_special
  name_used_by_uv
  name_used_by_marine_live_forecast
  name_used_by_flood_forecast
  name_used_by_weather
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def code
  @code
end

#latObject

Returns the value of attribute lat

Returns:

  • (Object)

    the current value of lat



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def lat
  @lat
end

#lngObject

Returns the value of attribute lng

Returns:

  • (Object)

    the current value of lng



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def lng
  @lng
end

#long_nameObject

Returns the value of attribute long_name

Returns:

  • (Object)

    the current value of long_name



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def long_name
  @long_name
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def name
  @name
end

#name_phoneticObject

Returns the value of attribute name_phonetic

Returns:

  • (Object)

    the current value of name_phonetic



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def name_phonetic
  @name_phonetic
end

#used_byObject

Returns the value of attribute used_by

Returns:

  • (Object)

    the current value of used_by



6
7
8
# File 'lib/jma_code/wmo_observing_station.rb', line 6

def used_by
  @used_by
end

Class Method Details

.build_by_csv_row(row) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jma_code/wmo_observing_station.rb', line 47

def build_by_csv_row(row)
  new(
    code: row[:code], 
    name: row[:name], 
    name_phonetic: row[:name_phonetic],
    lat: "#{row[:lat_major]}.#{row[:lat_minor]}".to_f,
    lng: "#{row[:lng_major]}.#{row[:lng_minor]}".to_f,
    long_name: row[:long_name],
    used_by: [
      row[:used_by_bioseasonal].present? ? :bioseasonal : nil,
      row[:used_by_seasonal].present? ? :seasonal : nil,
      row[:used_by_special].present? ? :special : nil,
      row[:name_used_by_uv].present? ? :uv : nil,
      row[:name_used_by_marine_live_forecast].present? ? :marine_live_forecast : nil,
      row[:name_used_by_flood_forecast].present? ? :flood_forecast : nil,
      row[:name_used_by_weather].present? ? :weather : nil,
    ].compact,
  )
end

.load(csv, num_headers: 3) ⇒ Object



41
42
43
44
45
# File 'lib/jma_code/wmo_observing_station.rb', line 41

def load(csv, num_headers: 3)
  csv.drop(num_headers).map do |row|
    build_by_csv_row(row)
  end
end

.load_20201026(&block) ⇒ Object



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

def load_20201026(&block)
  path = File.join(File.dirname(__FILE__), "../../data/20201026_WmoObservingStations.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