Sha256: 097906ad44aa8c1eb9020cd9ac8fb181862ccec380617a39caa34dc37d24f1fe

Contents?: true

Size: 739 Bytes

Versions: 2

Compression:

Stored size: 739 Bytes

Contents

require "csv"
require "active_support/core_ext"

require "flex_station_data/services/parse_plate"

module FlexStationData
  class LoadPlates
    include Concerns::Service

    attr_reader :file

    def initialize(file)
      @file = file
    end

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

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

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

    private

    def plate_row?(row)
      row[0].to_s =~ /\A\s*Plate:\s*/i
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flex-station-data-1.0.1 lib/flex_station_data/services/load_plates.rb
flex-station-data-1.0.0 lib/flex_station_data/services/load_plates.rb