Class: BatchLoad::Import::TaxonifiToTaxonworks
- Inherits:
-
BatchLoad::Import
- Object
- BatchLoad::Import
- BatchLoad::Import::TaxonifiToTaxonworks
- Defined in:
- lib/batch_load/import/taxonifi_to_taxonworks.rb
Overview
Batch loading of CSV formatted taxon names via Taxonifi
Instance Attribute Summary collapse
-
#also_create_otu ⇒ Object
Whether to create an OTU as well.
-
#name_collection ⇒ Object
The Taxonifi Name collection.
- #nomenclature_code ⇒ Symbol
- #parent_taxon_name ⇒ TaxonName
-
#parent_taxon_name_id ⇒ Object
The id of the parent taxon name, computed automatically as Root if not provided.
-
#project_id ⇒ Object
Required to handle some defaults.
Attributes inherited from BatchLoad::Import
#create_attempted, #csv, #errors, #file, #file_errors, #import_level, #processed, #processed_rows, #project, #successful_rows, #total_data_lines, #total_lines, #user, #user_header_map, #user_id
Instance Method Summary collapse
- #build ⇒ Boolean
- #build_name_collection ⇒ Object protected
- #build_protonyms ⇒ Integer protected
-
#initialize(nomenclature_code: nil, parent_taxon_name_id: nil, also_create_otu: false, **args) ⇒ TaxonifiToTaxonworks
constructor
A new instance of TaxonifiToTaxonworks.
- #taxon_name_authors_hash(taxonifi_name) ⇒ Array protected
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(nomenclature_code: nil, parent_taxon_name_id: nil, also_create_otu: false, **args) ⇒ TaxonifiToTaxonworks
Returns a new instance of TaxonifiToTaxonworks.
25 26 27 28 29 30 31 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 25 def initialize(nomenclature_code: nil, parent_taxon_name_id: nil, also_create_otu: false, **args) @nomenclature_code = nomenclature_code @also_create_otu = also_create_otu @parent_taxon_name_id = parent_taxon_name_id super(**args) end |
Instance Attribute Details
#also_create_otu ⇒ Object
Whether to create an OTU as well
19 20 21 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 19 def also_create_otu @also_create_otu end |
#name_collection ⇒ Object
The Taxonifi Name collection
7 8 9 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 7 def name_collection @name_collection end |
#nomenclature_code ⇒ Symbol
16 17 18 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 16 def nomenclature_code @nomenclature_code end |
#parent_taxon_name ⇒ TaxonName
10 11 12 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 10 def parent_taxon_name @parent_taxon_name end |
#parent_taxon_name_id ⇒ Object
The id of the parent taxon name, computed automatically as Root if not provided
13 14 15 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 13 def parent_taxon_name_id @parent_taxon_name_id end |
#project_id ⇒ Object
Required to handle some defaults
22 23 24 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 22 def project_id @project_id end |
Instance Method Details
#build ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 49 def build if valid? build_name_collection build_protonyms @processed = true end end |
#build_name_collection ⇒ Object (protected)
59 60 61 62 63 64 65 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 59 def build_name_collection begin @name_collection ||= ::Taxonifi::Lumper.create_name_collection(csv: csv) rescue Taxonifi::Assessor::RowAssessor::RowAssessorError => e @file_errors.push "Error assessing a row of data in the inputfile: #{e}." end end |
#build_protonyms ⇒ Integer (protected)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 68 def build_protonyms if name_collection.nil? @file_errors.push 'No names were readable in the file.' return end parents = {} total_lines = 0 name_collection.collection.each do |n| i = n.row_number + 1 rp = nil if processed_rows[i] rp = processed_rows[i] else rp = BatchLoad::RowParse.new @processed_rows[i] = rp end p = Protonym.new( name: n.name, rank_class: Ranks.lookup(nomenclature_code, n.rank), also_create_otu: also_create_otu, verbatim_author: (n.parens ? n. : nil), year_of_publication: n.year.to_s, by: user, project_id: project_id # taxon_name_authors_attributes: taxon_name_authors_hash(n) ) p.parent = (n.parent.nil? ? parent_taxon_name : parents[n.parent.id] ) rp.objects[:protonyms] ||= [] rp.objects[:protonyms].push(p) parents[n.id] = p total_lines = i if total_lines < i end @total_data_lines = total_lines true end |
#taxon_name_authors_hash(taxonifi_name) ⇒ Array (protected)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/batch_load/import/taxonifi_to_taxonworks.rb', line 117 def (taxonifi_name) = [] taxonifi_name..each_with_index do |a,i| suffix = a.suffix.join(' ') if !a.suffix.nil? .push({ last_name: a.last_name, first_name: a.first_name, prefix: a.initials_string, suffix: suffix, }) end # author_attributes.reverse end |