class Darlingtonia::CsvParser
A parser for CSV files. A single `InputRecord` is returned for each row parsed from the input.
Validates the format of the CSV, generating a single error the file is malformed. This error gives the line number and a message for the first badly formatted row.
@see CsvFormatValidator
Constants
- DEFAULT_VALIDATORS
- EXTENSION
Public Class Methods
match?(file:, **_opts)
click to toggle source
Matches all '.csv' filenames.
# File lib/darlingtonia/parsers/csv_parser.rb, line 22 def match?(file:, **_opts) File.extname(file) == EXTENSION rescue TypeError false end
Public Instance Methods
records() { |from(metadata: row)| ... }
click to toggle source
Gives a record for each line in the .csv
@see Parser#records
# File lib/darlingtonia/parsers/csv_parser.rb, line 33 def records return enum_for(:records) unless block_given? file.rewind CSV.parse(file.read, headers: true).each do |row| yield InputRecord.from(metadata: row) end rescue CSV::MalformedCSVError [] end