class ReindeerETL::Sources::CSVSource

Public Class Methods

new(path, opts = {}) click to toggle source
Calls superclass method ReindeerETL::Sources::BaseSource::new
# File lib/reindeer-etl/sources/csv_source.rb, line 5
def initialize path, opts = {}
    super
    @csv_opts = {headers: true, col_sep: ','}.merge(opts)
end

Public Instance Methods

each() { |row| ... } click to toggle source
# File lib/reindeer-etl/sources/csv_source.rb, line 10
def each
    first_run = true
    CSV.foreach(@path, @csv_opts) do |row|
        if first_run
            first_run = false
            if row.headers.count != row.headers.uniq.count
                raise ReindeerETL::Errors::RecordInvalid.new('Duplicate columns')
            end
        end
        row = row.to_hash
        simple_transforms(row)
        yield(row)
    end
end