Class: FlexStationData::LoadPlates

Inherits:
Object
  • Object
show all
Includes:
Callable
Defined in:
lib/flex_station_data/services/load_plates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ LoadPlates

Returns a new instance of LoadPlates.



14
15
16
# File 'lib/flex_station_data/services/load_plates.rb', line 14

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/flex_station_data/services/load_plates.rb', line 12

def file
  @file
end

Instance Method Details

#callObject



29
30
31
32
33
# File 'lib/flex_station_data/services/load_plates.rb', line 29

def call
  data_blocks.each_with_index.map do |data_block, index|
    FlexStationData::ParsePlate.call(index + 1, data_block)
  end
end

#dataObject



18
19
20
# File 'lib/flex_station_data/services/load_plates.rb', line 18

def data
  CSV.read(file, headers: false).to_a
end

#data_blocksObject



22
23
24
25
26
27
# File 'lib/flex_station_data/services/load_plates.rb', line 22

def data_blocks
  @data_blocks ||= data.each_with_object([]) do |row, blocks|
    blocks << [] if plate_row?(row)
    blocks.last&.push(row)
  end
end