Class: BatchLoad::Import::CollectionObjects::BufferedInterpreter
- Inherits:
-
BatchLoad::Import
- Object
- BatchLoad::Import
- BatchLoad::Import::CollectionObjects::BufferedInterpreter
- Defined in:
- lib/batch_load/import/collection_objects/buffered_interpreter.rb
Instance Attribute Summary collapse
-
#otu ⇒ Object
Returns the value of attribute otu.
-
#otu_id ⇒ Object
Returns the value of attribute otu_id.
-
#source ⇒ Object
Returns the value of attribute source.
-
#source_id ⇒ Object
Returns the value of attribute source_id.
Attributes inherited from BatchLoad::Import
#create_attempted, #csv, #errors, #file, #file_errors, #import_level, #processed, #processed_rows, #project, #project_id, #successful_rows, #total_data_lines, #total_lines, #user, #user_header_map, #user_id
Instance Method Summary collapse
- #build ⇒ Boolean
-
#build_collection_objects ⇒ Integer
rubocop:disable Metrics/MethodLength.
-
#initialize(**args) ⇒ BufferedInterpreter
constructor
A new instance of BufferedInterpreter.
Methods inherited from BatchLoad::Import
#all_objects, #create, #create_attempted?, #import_level_ok?, #line_strict_level_ok?, #processed?, #ready_to_create?, #save_order, #sorted_processed_rows, #strict_level_ok?, #total_records_created, #user_map, #valid?, #valid_objects, #warn_level_ok?
Constructor Details
#initialize(**args) ⇒ BufferedInterpreter
Returns a new instance of BufferedInterpreter.
7 8 9 10 11 12 13 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 7 def initialize(**args) @source_id = args.delete(:source_id) @otu_id = args.delete(:otu_id) @source = @source_id.present? ? Source.find(@source_id) : nil @otu = @otu_id.present? ? Otu.find(@otu_id) : nil super(**args) end |
Instance Attribute Details
#otu ⇒ Object
Returns the value of attribute otu.
4 5 6 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 4 def otu @otu end |
#otu_id ⇒ Object
Returns the value of attribute otu_id.
4 5 6 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 4 def otu_id @otu_id end |
#source ⇒ Object
Returns the value of attribute source.
4 5 6 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 4 def source @source end |
#source_id ⇒ Object
Returns the value of attribute source_id.
4 5 6 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 4 def source_id @source_id end |
Instance Method Details
#build ⇒ Boolean
62 63 64 65 66 67 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 62 def build if valid? build_collection_objects @processed = true end end |
#build_collection_objects ⇒ Integer
rubocop:disable Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/batch_load/import/collection_objects/buffered_interpreter.rb', line 17 def build_collection_objects @total_data_lines = 0 i = 0 # loop through rows csv.each do |row| i += 1 parse_result = BatchLoad::RowParse.new parse_result.objects[:specimen] = [] @processed_rows[i] = parse_result c_e = row['collecting_event'] det = row['determinations'] o_l = row['other_labels'] if c_e.blank? && det.blank? && o_l.blank? parse_result.parse_errors << 'No strings provided for any buffered data.' next end specimen_args = {buffered_collecting_event: c_e, buffered_determinations: det, buffered_other_labels: o_l} if otu_id.present? specimen_args.merge!(taxon_determinations_attributes: [otu_id: otu_id]) end if source_id.present? specimen_args.merge!(citations_attributes: [source_id: source_id]) end begin # processing s = Specimen.new(specimen_args) parse_result.objects[:specimen].push(s) rescue => _e raise(_e) end end @total_lines = i end |