Class: Slcsp::PlanParser
- Inherits:
-
Object
- Object
- Slcsp::PlanParser
- Defined in:
- lib/slcsp/plan_parser.rb
Overview
parses the csv with plans and save data to Index in the form e.g. 11’ => [102.1, 192.3] for the defined metal level
Constant Summary collapse
- KEY_FIELDS =
%w[state rate_area].freeze
- VALUE_FIELDS =
%w[rate].freeze
Instance Method Summary collapse
-
#initialize(path, index) ⇒ PlanParser
constructor
A new instance of PlanParser.
- #parse_and_record ⇒ Object
Constructor Details
#initialize(path, index) ⇒ PlanParser
Returns a new instance of PlanParser.
12 13 14 15 |
# File 'lib/slcsp/plan_parser.rb', line 12 def initialize(path, index) @path = path @index = index end |
Instance Method Details
#parse_and_record ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/slcsp/plan_parser.rb', line 17 def parse_and_record File.open(@path) do |file| CSV.foreach(file, headers: true) do |row| next if row['metal_level'] && row['metal_level'] != Slcsp::Config.target_level key, value = "#{row[KEY_FIELDS[0]]} #{row[KEY_FIELDS[1]]}", row[VALUE_FIELDS.join(' ')] @index.set(key, value) end end end |