Class: Jensen::Product::CSVSource

Inherits:
Object
  • Object
show all
Defined in:
lib/jensen/csv_source.rb

Overview

Note:

This is a constructor/wrapper class for stdlib CSV::Table class with formatting options.

Source class for Jensen's CSV product files. Intended for use with kiba.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_file:) ⇒ Jensen::Product::CSVSource

Make a new source instance for a Jensen formatted CSV file

Examples:

csv = File.new('jensen.csv', 'r')
Jensen::Product::CSVSource.new(input_file: csv)

Parameters:

  • input_file (IO)

    Takes an IO object, usually File, and anything acceptable as 'data' by CSV::Table.parse


22
23
24
# File 'lib/jensen/csv_source.rb', line 22

def initialize(input_file:)
  @csv = CSV.parse(input_file, headers: true, row_sep: :auto)
end

Instance Attribute Details

#csvCSV::Table (readonly)

The wrapped CSV::Table instance

Returns:

  • (CSV::Table)

13
14
15
# File 'lib/jensen/csv_source.rb', line 13

def csv
  @csv
end

Instance Method Details

#eachObject

Forwards to #csv.each

See Also:


28
29
30
# File 'lib/jensen/csv_source.rb', line 28

def each
  csv.each
end