Class: BatchLoad::Import::TaxonNames::CastorInterpreter
- Inherits:
-
BatchLoad::Import
- Object
- BatchLoad::Import
- BatchLoad::Import::TaxonNames::CastorInterpreter
- Defined in:
- lib/batch_load/import/taxon_names/castor_interpreter.rb
Instance Attribute Summary collapse
-
#also_create_otu ⇒ Object
Whether to create an OTU as well.
-
#nomenclature_code ⇒ Object
The code (Rank Class) that new names will use.
- #parent_taxon_name ⇒ String
- #parent_taxon_name_id ⇒ Integer
-
#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
Instance Method Summary collapse
- #author_info(author_string) ⇒ Hash private
- #build ⇒ Boolean
-
#build_taxon_names ⇒ Integer
rubocop:disable Metrics/MethodLength.
-
#initialize(nomenclature_code: nil, parent_taxon_name_id: nil, also_create_otu: false, **args) ⇒ CastorInterpreter
constructor
A new instance of CastorInterpreter.
- #taxon_name_authors_attributes(author_info) ⇒ Array private
- #verbatim_author(author_year) ⇒ String? private
- #year_of_publication(author_year) ⇒ String? private
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) ⇒ CastorInterpreter
Returns a new instance of CastorInterpreter.
20 21 22 23 24 25 26 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 20 def initialize(nomenclature_code: nil, parent_taxon_name_id: nil, also_create_otu: false, **args) @nomenclature_code = nomenclature_code @parent_taxon_name_id = parent_taxon_name_id @also_create_otu = also_create_otu super(args) end |
Instance Attribute Details
#also_create_otu ⇒ Object
Whether to create an OTU as well
14 15 16 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 14 def also_create_otu @also_create_otu end |
#nomenclature_code ⇒ Object
The code (Rank Class) that new names will use
11 12 13 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 11 def nomenclature_code @nomenclature_code end |
#parent_taxon_name ⇒ String
5 6 7 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 5 def parent_taxon_name @parent_taxon_name end |
#parent_taxon_name_id ⇒ Integer
8 9 10 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 8 def parent_taxon_name_id @parent_taxon_name_id end |
#project_id ⇒ Object
Required to handle some defaults
17 18 19 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 17 def project_id @project_id end |
Instance Method Details
#author_info(author_string) ⇒ Hash (private)
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 207 def () seperator_query = ' ' separator_index = .index(seperator_query) last_name = first_name = '' if !separator_index.nil? separator_index += seperator_query.length = .split(seperator_query) last_name = [0] first_name = [1] end { last_name: last_name, first_name: first_name, suffix: 'suffix' } end |
#build ⇒ Boolean
162 163 164 165 166 167 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 162 def build if valid? build_taxon_names @processed = true end end |
#build_taxon_names ⇒ Integer
rubocop:disable Metrics/MethodLength
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 40 def build_taxon_names @total_data_lines = 0 i = 0 taxon_names = {} csv.each do |row| i += 1 parse_result = BatchLoad::RowParse.new parse_result.objects[:original_taxon_name] = [] parse_result.objects[:taxon_name] = [] parse_result.objects[:taxon_name_relationship] = [] parse_result.objects[:otu] = [] @processed_rows[i] = parse_result begin next if row['rank'] == 'complex' next if row['rank'] == 'species group' next if row['rank'] == 'series' next if row['rank'] == 'variety' next if row['taxon_name'] == 'unidentified' protonym_attributes = { name: row['taxon_name'], year_of_publication: year_of_publication(row['author_year']), rank_class: Ranks.lookup(@nomenclature_code.to_sym, row['rank']), by: @user, also_create_otu: false, project: @project, verbatim_author: (row['author_year']), taxon_name_authors_attributes: ((row['author_year'])) } if row['original_name'] original_protonym_attributes = { verbatim_name: row['original_name'], name: row['original_name'].split(' ')[-1], year_of_publication: year_of_publication(row['author_year']), rank_class: Ranks.lookup(@nomenclature_code.to_sym, row['original_rank']), parent: parent_taxon_name, by: @user, also_create_otu: false, project: @project, verbatim_author: (row['author_year']), taxon_name_authors_attributes: ((row['author_year'])) } original_protonym = Protonym.new(original_protonym_attributes) if row['original_rank'] == 'genus' protonym_attributes[:original_genus] = original_protonym elsif row['original_rank'] == 'subgenus' protonym_attributes[:original_subgenus] = original_protonym elsif row['original_rank'] == 'species' protonym_attributes[:original_species] = original_protonym elsif row['original_rank'] == 'subspecies' protonym_attributes[:original_subspecies] = original_protonym end parse_result.objects[:original_taxon_name].push original_protonym end p = Protonym.new(protonym_attributes) taxon_name_id = row['id'] parent_taxon_name_id = row['parent_id'] taxon_names[taxon_name_id] = p if taxon_names[parent_taxon_name_id].nil? p.parent = parent_taxon_name else p.parent = taxon_names[parent_taxon_name_id] end # TaxonNameRelationship = row['related_name_id'] if !taxon_names[].nil? = nil begin = row['related_name_nomen_class'].constantize if .ancestors.include?(TaxonNameRelationship) p.name = row['taxon_name'].split(' ')[-1] p.verbatim_name = row['taxon_name'] taxon_name_relationship = .new(subject_taxon_name: p, object_taxon_name: taxon_names[]) parse_result.objects[:taxon_name_relationship].push taxon_name_relationship end rescue NameError end end # TaxonNameClassification name_nomen_classification = row['name_nomen_classification'] p.taxon_name_classifications.new(type: name_nomen_classification) if EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS.include?(name_nomen_classification) taxon_concept_identifier_castor_text = row['guid'] if taxon_concept_identifier_castor_text.present? taxon_concept_identifier_castor = { type: 'Identifier::Global::Uri', identifier: taxon_concept_identifier_castor_text } taxon_concept_identifiers = [] taxon_concept_identifiers.push(taxon_concept_identifier_castor) otu = Otu.new(name: row['taxon_concept_name'], taxon_name: p, identifiers_attributes: taxon_concept_identifiers) parse_result.objects[:otu].push(otu) end parse_result.objects[:taxon_name].push p @total_data_lines += 1 if p.present? end end @total_lines = i end |
#taxon_name_authors_attributes(author_info) ⇒ Array (private)
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 191 def () return [] if .blank? = 'and' = .index() = .nil? ? [] : .split() = [] .each do || .push(()) if != 'NA' && != 'unpublished' end end |
#verbatim_author(author_year) ⇒ String? (private)
182 183 184 185 186 187 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 182 def () return nil if .blank? = .rindex(' ') ||= .length [0...] end |
#year_of_publication(author_year) ⇒ String? (private)
173 174 175 176 177 178 |
# File 'lib/batch_load/import/taxon_names/castor_interpreter.rb', line 173 def year_of_publication() return nil if .blank? = .split(' ') year = [.length - 1] year =~ /\A\d+\z/ ? year : '' end |