Class: Chronicle::ETL::CSVExtractor

Inherits:
Extractor
  • Object
show all
Includes:
Extractors::Helpers::InputReader
Defined in:
lib/chronicle/etl/extractors/csv_extractor.rb

Instance Attribute Summary

Attributes included from Registry::SelfRegistering

#connector_registration

Instance Method Summary collapse

Methods included from Extractors::Helpers::InputReader

#filenames, #pathnames, #read_from_files?, #read_from_stdin?, #read_input, #read_input_as_lines

Methods inherited from Extractor

#initialize

Methods included from Registry::SelfRegistering

#register_connector

Methods included from Configurable

included

Constructor Details

This class inherits a constructor from Chronicle::ETL::Extractor

Instance Method Details

#extractObject



21
22
23
24
25
26
27
# File 'lib/chronicle/etl/extractors/csv_extractor.rb', line 21

def extract
  @csvs.each do |csv|
    csv.read.each do |row|
      yield Chronicle::ETL::Extraction.new(data: row.to_h)
    end
  end
end

#prepareObject



17
18
19
# File 'lib/chronicle/etl/extractors/csv_extractor.rb', line 17

def prepare
  @csvs = prepare_sources
end

#results_countObject



29
30
31
32
33
34
35
# File 'lib/chronicle/etl/extractors/csv_extractor.rb', line 29

def results_count
  @csvs.reduce(0) do |total_rows, csv|
    row_count = csv.readlines.size
    csv.rewind
    total_rows + row_count
  end
end