Class: Cure::Extract::Extractor
- Inherits:
-
Object
- Object
- Cure::Extract::Extractor
- Includes:
- Configuration, Database, Helpers::FileHelpers, Helpers::PerfHelpers, Log
- Defined in:
- lib/cure/extract/extractor.rb
Instance Attribute Summary collapse
-
#opts ⇒ Hash
readonly
Opts.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Extractor
constructor
A new instance of Extractor.
- #parse_csv(file, ref_name:) ⇒ Object
Methods included from Helpers::PerfHelpers
#print_memory_usage, #print_time_spent
Methods included from Helpers::FileHelpers
#clean_dir, #open_file, #read_file, #with_file, #with_temp_dir
Methods included from Configuration
#config, #create_config, #register_config
Methods included from Database
#database_service, #init_database
Methods included from Log
#log_debug, #log_error, #log_info, #log_trace, #log_warn
Constructor Details
#initialize(opts) ⇒ Extractor
Returns a new instance of Extractor.
28 29 30 |
# File 'lib/cure/extract/extractor.rb', line 28 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Hash (readonly)
Returns opts.
25 26 27 |
# File 'lib/cure/extract/extractor.rb', line 25 def opts @opts end |
Instance Method Details
#parse_csv(file, ref_name:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cure/extract/extractor.rb', line 34 def parse_csv(file, ref_name:) nr_processor = named_range_processor(ref_name: ref_name) v_processor = variable_processor(ref_name: ref_name) sample_rows = config.template.extraction.sample_rows row_count = 0 database_service.with_transaction do CSV.foreach(file, liberal_parsing: true) do |row| next if sample_rows && row_count >= sample_rows nr_processor.process_row(row_count, row) v_processor.process_row(row_count, row) row_count += 1 log_info "#{row_count} rows processed [#{Time.now}]" if (row_count % 1_000).zero? end nr_processor.after_process end log_info "[#{row_count}] total rows parsed from CSV" end |