Class: Cards::CsvParser
Defined Under Namespace
Classes: Row
Instance Method Summary collapse
- #default_output_file ⇒ Object
- #each_row ⇒ Object
-
#initialize(file) ⇒ CsvParser
constructor
A new instance of CsvParser.
- #rows ⇒ Object
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_file ⇒ Object
26 27 28 |
# File 'lib/cards/csv_parser.rb', line 26 def default_output_file File.basename(@file).sub(/\..*/, '') end |
#each_row ⇒ Object
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 |
#rows ⇒ Object
9 10 11 12 13 |
# File 'lib/cards/csv_parser.rb', line 9 def rows rows = [] each_row {|row| rows << row} rows end |