Class: JMACode::RiverOffice
- Inherits:
-
Struct
- Object
- Struct
- JMACode::RiverOffice
- Defined in:
- lib/jma_code/river_office.rb
Constant Summary collapse
- HEADERS =
%i(code name)
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code
4 5 6 |
# File 'lib/jma_code/river_office.rb', line 4 def code @code end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/jma_code/river_office.rb', line 4 def name @name end |
Class Method Details
.load(csv, num_headers: 3) ⇒ Object
23 24 25 26 27 |
# File 'lib/jma_code/river_office.rb', line 23 def load(csv, num_headers: 3) csv.drop(num_headers).map do |row| new(code: row[:code], name: row[:name]) end end |
.load_20240315(&block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jma_code/river_office.rb', line 11 def load_20240315(&block) path = File.join(File.dirname(__FILE__), "../../data/20240315_RiverOffice.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 |