Class: Cards::CsvParser

Inherits:
Object show all
Defined in:
lib/cards/csv_parser.rb

Defined Under Namespace

Classes: Row

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ CsvParser

Returns a new instance of CsvParser.



5
6
7
# File 'lib/cards/csv_parser.rb', line 5

def initialize(file)
  @file = file
end

Instance Method Details

#default_output_fileObject



26
27
28
# File 'lib/cards/csv_parser.rb', line 26

def default_output_file
  File.basename(@file).sub(/\..*/, '')
end

#each_rowObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/cards/csv_parser.rb', line 15

def each_row
  header = nil
  CSV.open(@file, 'r') do |row|
    if header.nil?
      header = define_header(row)
    else
      yield Row.new(header, row)
    end
  end
end

#rowsObject



9
10
11
12
13
# File 'lib/cards/csv_parser.rb', line 9

def rows
  rows = []
  each_row {|row| rows << row}
  rows
end