Class: Protonym

Inherits:
TaxonName show all
Extended by:
SoftValidationExtensions::Klass
Includes:
SoftValidationExtensions::Instance
Defined in:
app/models/protonym.rb

Overview

A monomial TaxonName, a record implies a first usage. This follows Pyle's concept almost exactly.

We inject a lot of relationship helper methods here, in this format.

subject                      object
Aus      original_genus of   bus
aus      type_species of     Bus

Defined Under Namespace

Modules: SoftValidationExtensions

Constant Summary

FAMILY_GROUP_ENDINGS =
%w{ini ina inae idae oidae odd ad oidea}.freeze

Constants included from SoftValidationExtensions::Klass

SoftValidationExtensions::Klass::VALIDATIONS

Constants inherited from TaxonName

TaxonName::ALTERNATE_VALUES_FOR, TaxonName::EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS, TaxonName::EXCEPTED_FORM_TAXON_NAME_RELATIONSHIPS, TaxonName::NOT_LATIN, TaxonName::NO_CACHED_MESSAGE, TaxonName::SPECIES_EPITHET_RANKS

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from TaxonName

#also_create_otu, #cached, #cached_author_year, #cached_classified_as, #cached_higher_classification, #cached_html, #cached_misspelling, #cached_original_combination, #cached_primary_homonym, #cached_primary_homonym_alternative_spelling, #cached_secondary_homonym, #cached_secondary_homonym_alternative_spelling, #etymology, #feminine_name, #masculine_name, #name, #neuter_name, #no_cached, #parent_id, #project_id, #rank_class, #type, #verbatim_author, #verbatim_name, #year_of_publication

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from SoftValidationExtensions::Instance

#sv_extant_children, #sv_fix_add_nominotypical_sub, #sv_fix_coordinated_names, #sv_homotypic_synonyms, #sv_missing_classifications, #sv_missing_relationships, #sv_original_combination_relationships, #sv_parent_priority, #sv_potential_homonyms, #sv_primary_types, #sv_single_sub_taxon, #sv_source_not_older_then_description, #sv_species_gender_agreement, #sv_type_placement, #sv_validate_coordinated_names, #sv_validate_parent_rank

Methods inherited from TaxonName

#all_taxon_name_relationships, #ancestor_at_rank, #ancestor_protonyms, #ancestors_through_parents, #author_string, #cached_html_name_and_author_year, #cached_name_and_author_year, #candidatus?, #check_for_children, #check_new_rank_class, #classification_invalid_or_unavailable?, #classification_valid?, #combination_list_all, #combination_list_self, #combined_statuses, #create_new_combination_if_absent, #descendant_protonyms, #first_possible_valid_taxon_name, #first_possible_valid_taxon_name_relationship, #form_name_elements, #fossil?, #full_name_array, #full_name_hash, #gbif_status_array, #gender_class, #gender_instance, #gender_name, #genus_name_elements, #get_cached_classified_as, #get_cached_misspelling, #get_full_name, #get_full_name_html, #hybrid?, #icn_author_and_year, #iczn_author_and_year, #is_combination?, #is_protonym?, #is_valid?, #list_of_invalid_taxon_names, #name_in_gender, #name_is_missapplied?, #name_with_misspelling, #next_sibling, #nomenclature_date, #not_binomial?, #parent_is_set?, #part_of_speech_class, #part_of_speech_instance, #part_of_speech_name, #previous_sibling, #rank, #rank_string, #related_taxon_names, #relationship_invalid?, #safe_self_and_ancestors, #section_name_elements, select_optimized, #series_name_elements, #set_cached_author_year, #set_cached_classified_as, #set_cached_html, #set_cached_valid_taxon_name_id, #set_cached_warnings, sort_by_rank, #species_group_name_elements, #species_name_elements, #statuses_from_classifications, #statuses_from_relationships, #subform_name_elements, #subgenus_name_elements, #subsection_name_elements, #subseries_name_elements, #subspecies_name_elements, #subvariety_name_elements, #superspecies_name_elements, #sv_combination_duplicates, #sv_fix_cached_names, #sv_fix_missing_author, #sv_fix_missing_year, #sv_fix_parent_is_valid_name, #sv_homotypic_synonyms, #sv_hybrid_name_relationships, #sv_incomplete_combination, #sv_missing_classifications, #sv_missing_fields, #sv_missing_relationships, #sv_not_synonym_of_self, #sv_parent_is_valid_name, #sv_parent_priority, #sv_potential_homonyms, #sv_primary_types, #sv_single_sub_taxon, #sv_species_gender_agreement, #sv_two_unresolved_alternative_synonyms, #sv_type_placement, #sv_validate_coordinated_names, #sv_validate_name, #sv_validate_parent_rank, #synonyms, #taxon_name_classifications_for_statuses, #unavailable_or_invalid?, used_recently, used_recently_in_classifications, used_recently_in_relationships, #validate_one_root_per_project, #validate_parent_is_set, #validate_parent_rank_is_higher, #validate_source_type, #variety_name_elements, with_taxon_name_relationship, #year_integer

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) family_group_base(name_string)



270
271
272
273
# File 'app/models/protonym.rb', line 270

def self.family_group_base(name_string)
  name_string.match(/(^.*)(ini|ina|inae|idae|oidae|odd|ad|oidea)$/)
  $1 || name_string
end

+ (Object) family_group_name_at_rank(name_string, rank_string)



275
276
277
278
279
280
281
# File 'app/models/protonym.rb', line 275

def self.family_group_name_at_rank(name_string, rank_string)
  if name_string == family_group_base(name_string)
    name_string
  else
    family_group_base(name_string) + Ranks.lookup(:iczn, rank_string).constantize.try(:valid_name_ending).to_s
  end
end

+ (Protonym) stub_root(project_id: nil, by: nil)

Returns a name ready to become the root

Returns:

  • (Protonym)

    a name ready to become the root



266
267
268
# File 'app/models/protonym.rb', line 266

def self.stub_root(project_id: nil, by: nil)
  Protonym.new(name: 'Root', rank_class: 'NomenclaturalRank', parent_id: nil, project_id: project_id, by: by)
end

Instance Method Details

- (Array of Strings) all_generic_placements

Returns genera where the species was placed

Returns:

  • (Array of Strings)

    genera where the species was placed



141
142
143
144
145
146
147
# File 'app/models/protonym.rb', line 141

def all_generic_placements
  valid_name = get_valid_taxon_name
  return nil unless valid_name.rank_string !=~/Species/
  descendants_and_self = valid_name.descendants + [self] + self.combinations
  relationships = TaxonNameRelationship.where_object_in_taxon_names(descendants_and_self).with_two_type_bases('TaxonNameRelationship::OriginalCombination::OriginalGenus', 'TaxonNameRelationship::Combination::Genus')
  (relationships.collect { |r| r.subject_taxon_name.name } + [self.ancestor_at_rank('genus').try(:name)]).uniq
end

- (Array) ancestors_and_descendants

Returns all descendant and ancestor protonyms for this Protonym

Returns:

  • (Array)

    all descendant and ancestor protonyms for this Protonym



260
261
262
# File 'app/models/protonym.rb', line 260

def ancestors_and_descendants
  Protonym.ancestors_and_descendants_of(self).not_self(self).to_a
end

- (Boolean) build_original_combination_from_biodiversity(biodiversity_result, relationship_housekeeping = {})

Returns Wraps set_original_combination with result from Biodiversity parse !!You must can optionally pre-calculate a disambiguated protonym if you wish to use one.

Parameters:

  • biodiversity_result (Biodiversity.result)
  • relationship_housekeeping (Hash) (defaults to: {})

    like `22, created_by_id: 2`

Returns:

  • (Boolean)

    Wraps set_original_combination with result from Biodiversity parse !!You must can optionally pre-calculate a disambiguated protonym if you wish to use one.



472
473
474
475
476
477
478
# File 'app/models/protonym.rb', line 472

def build_original_combination_from_biodiversity(biodiversity_result, relationship_housekeeping = {})
  br = biodiversity_result
  return false if br.nil?
  c = [br.disambiguated_combination, br.combination].first
  build_original_combinations(c, relationship_housekeeping)
  true
end

- (Boolean) build_original_combinations(combination, relationship_housekeeping)

Parameters:

  • combination (Combination)
  • relationship_housekeeping (Hash)

    like `22, created_by_id: 2` builds, but does not save, original relationships for all corresponding protonyms in a combination !! Replaces existing relationship without checking identify if they are there!

Returns:

  • (Boolean)


485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'app/models/protonym.rb', line 485

def build_original_combinations(combination, relationship_housekeeping)
  return false if combination.nil?
  combination.protonyms_by_rank.each do |rank, p|
    send("original_#{rank}=", p)
  end 

  if !relationship_housekeeping.empty? 
    combination.protonyms_by_rank.each do |rank, p|
      r = send("original_#{rank}_relationship")
      r.write_attributes(relationship_housekeeping)
    end
  end
  true
end

- (Object) check_new_parent_class (protected)

TODO: move to Protonym



682
683
684
685
686
687
688
689
690
# File 'app/models/protonym.rb', line 682

def check_new_parent_class
  if is_protonym? && parent_id != parent_id_was && !parent_id_was.nil? && nomenclatural_code == :iczn
    if old_parent = TaxonName.find_by(id: parent_id_was)
      if (rank_name == 'subgenus' || rank_name == 'subspecies') && old_parent.name == name
        errors.add(:parent_id, "The nominotypical #{rank_name} #{name} can not be moved out of the nominal #{old_parent.rank_name}")
      end
    end
  end
end

- (Object) create_otu (protected)



700
701
702
# File 'app/models/protonym.rb', line 700

def create_otu
  Otu.create(by: self.creator, project: self.project, taxon_name_id: self.id)
end

- (Object) genus_suggested_gender



448
449
450
451
452
453
454
455
456
# File 'app/models/protonym.rb', line 448

def genus_suggested_gender
  return nil unless rank_string =~/Genus/
  TAXON_NAME_CLASSIFICATION_GENDER_CLASSES.each do |g|
    g.possible_genus_endings.each do |e|
      return g.name.demodulize.underscore.humanize.downcase if self.name =~ /^[a-zA-Z]*#{e}$/
    end
  end
  nil
end

- (String?) get_author_and_year

Returns a string, without parenthesis, that includes author and year

Returns:

  • (String, nil)

    a string, without parenthesis, that includes author and year



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/models/protonym.rb', line 205

def get_author_and_year
  # times_called
  case rank_class.try(:nomenclatural_code)
    when :iczn
      ay = iczn_author_and_year
    when :ictv
      ay = icn_author_and_year
    when :icnb
      ay = icn_author_and_year
    when :icn
      ay = icn_author_and_year
    else
      ay = ([author_string] + [year_integer]).compact.join(' ')
  end
  ay.blank? ? nil : ay
end

- (Object) get_genus_species(genus_option, self_option)



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'app/models/protonym.rb', line 222

def get_genus_species(genus_option, self_option)
  return nil if rank_class.nil?
  genus = nil
  name1 = nil

  if self.rank_string =~ /Species/
    if genus_option == :original
      genus = self.original_genus
    elsif genus_option == :current
      genus = self.ancestor_at_rank('genus')
    else
      return false
    end
    genus = genus.name unless genus.blank?
    return nil if genus.blank?
  end
  if self_option == :self
    name1 = self.name
  elsif self_option == :alternative
    name1 = name_with_alternative_spelling
  end

  return nil if genus.nil? && name1.nil?
  (genus.to_s + ' ' + name1.to_s).squish
end

- (String?) get_original_combination

TODO: refactor to use us a hash!

Returns:

  • (String, nil)

    the string representing the name as originally published



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'app/models/protonym.rb', line 503

def get_original_combination
  # strategy is to get the original hash, and swap in values for pertinent relationships
  str = nil

  if is_genus_or_species_rank?
    relationships = self.original_combination_relationships.reload

    return nil if relationships.count == 0

    # This can be greatly simplified by swapping in names to the hash method

    relationships = relationships.sort_by{|r| r.type_class.order_index }
    genus         = ''
    subgenus      = ''
    superspecies  = ''
    species       = ''
    gender        = nil
    g1 = nil
    s1 = nil

    relationships.each do |i|
      if i.object_taxon_name_id == i.subject_taxon_name_id && !i.object_taxon_name.verbatim_name.blank?
        misspelling = i.subject_taxon_name.cached_misspelling ? ' [sic]' : ''
        case i.type # subject_status
          when /OriginalGenus/ #'original genus'
            genus  = '<i>' + i.subject_taxon_name.verbatim_name + misspelling +'</i> ' # why verbatim_name?
            gender = i.subject_taxon_name.gender_name
            g1 = true
          when /OriginalSubgenus/ # 'original subgenus'
            subgenus += '<i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
          when /OriginalSpecies/ #  'original species'
            species += '<i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
            s1 = true
          when /OriginalSubspecies/ # 'original subspecies'
            species += '<i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
          when /OriginalVariety/ #  'original variety'
            species += 'var. <i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
          when /OriginalSubvariety/ # 'original subvariety'
            species += 'subvar. <i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
          when /OriginalForm/ # 'original form'
            species += 'f. <i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
          when /OriginalSubform/ #  'original subform'
            species += 'subf. <i>' + i.subject_taxon_name.verbatim_name + misspelling + '</i> '
        end
      else
        case i.type # subject_status
          when /OriginalGenus/ #'original genus'
            genus  = '<i>' + i.subject_taxon_name.name_with_misspelling(nil) + '</i> '
            gender = i.subject_taxon_name.gender_name
            g1 = true
          when /OriginalSubgenus/ # 'original subgenus'
            subgenus += '<i>' + i.subject_taxon_name.name_with_misspelling(nil) + '</i> '
          when /OriginalSpecies/ #  'original species'
            species += '<i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
            s1 = true
          when /OriginalSubspecies/ # 'original subspecies'
            species += '<i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
          when /OriginalVariety/ #  'original variety'
            species += 'var. <i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
          when /OriginalSubvariety/ # 'original subvariety'
            species += 'subvar. <i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
          when /OriginalForm/ # 'original form'
            species += 'f. <i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
          when /OriginalSubform/ #  'original subform'
            species += 'subf. <i>' + i.subject_taxon_name.name_with_misspelling(gender) + '</i> '
        end
      end
    end

    original_name = self.verbatim_name.nil? ? self.name_with_misspelling(nil) : self.verbatim_name
    if !relationships.empty? && relationships.collect{|i| i.subject_taxon_name}.last.lowest_rank_coordinated_taxon.id != self.lowest_rank_coordinated_taxon.id
      if self.rank_string =~ /Genus/
        if genus.blank?
          genus += '<i>' + original_name + '</i> '
          g1 = true
        else
          subgenus += '<i>' + original_name + '</i> '
        end
      elsif self.rank_string =~ /Species/
        species += '<i>' + original_name + '</i> '
        s1 = true
        # genus = '<i>' + self.ancestor_at_rank('genus').name_with_misspelling(nil) + '</i> ' if genus.empty? && !self.ancestor_at_rank('genus').nil?
      end
    end

    subgenus = '(' + subgenus.squish + ') ' unless subgenus.empty?
    genus = '[GENUS NOT SPECIFIED]' + genus.to_s if g1.nil?
    genus = '' if not_binomial?
    species = '[SPECIES NOT SPECIFIED]' + species.to_s if s1.nil? && !species.empty?
    str = (genus + subgenus + superspecies + species).gsub(' [sic]', '</i> [sic]<i>').gsub('</i> <i>', ' ').gsub('<i></i>', '').gsub('<i> ', ' <i>').squish
    str = species if rank_class =~ /Ictv/
  end
  str.blank? ? nil : str
end

- (TypeMaterial, []) get_primary_type

Returns ?!

Returns:



284
285
286
287
288
289
290
291
292
293
294
295
# File 'app/models/protonym.rb', line 284

def get_primary_type
  return [] unless self.rank_class.parent.to_s =~ /Species/
  s = self.type_materials.syntypes
  p = self.type_materials.primary
  if s.empty? && p.count == 1
    p
  elsif p.empty? && !s.empty?
    s
  else
    []
  end
end

- (Protonym) get_valid_taxon_name

Returns the accepted “valid” version of this name in the present classification

Returns:

  • (Protonym)

    the accepted “valid” version of this name in the present classification



190
191
192
193
194
195
196
197
198
199
200
201
# File 'app/models/protonym.rb', line 190

def get_valid_taxon_name
  v = first_possible_valid_taxon_name
  if v == self
    self
  elsif v.cached_valid_taxon_name_id == v.id
    v
  elsif !v.cached_valid_taxon_name_id.nil?
    v.valid_taxon_name
  else
    self
  end
end

- (Boolean) has_latinized_exceptions?

Returns whether this name has one of the TaxonNameClassifications that except it from being tested as latinized

Returns:

  • (Boolean)

    whether this name has one of the TaxonNameClassifications that except it from being tested as latinized



344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'app/models/protonym.rb', line 344

def has_latinized_exceptions?
  # The second half of this handles classifications in memory, as required to save a non-latinized name (i.e. don't tune it to .any?)
  # !((type == 'Protonym') && (taxon_name_classifications.collect{|t| t.type} & EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS).empty?)

  # Is faster than above?
  taxon_name_classifications.each do |tc| # ! find_each
    return true if TaxonName::EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS.include?(tc.type)
  end
  taxon_name_relationships.each do |tr|
    return true if TaxonName::EXCEPTED_FORM_TAXON_NAME_RELATIONSHIPS.include?(tr.type)
  end
  false
end

- (Boolean) has_same_primary_type(taxon2)

!! TODO: Should not be possible- fix the incoming data

Returns:

  • (Boolean)

    true if taxon2 has the same primary type



300
301
302
303
304
305
306
307
308
309
# File 'app/models/protonym.rb', line 300

def has_same_primary_type(taxon2)
  return true unless rank_class.parent.to_s =~ /Species/

  taxon1_types = get_primary_type.sort_by{|i| i.id}
  taxon2_types = taxon2.get_primary_type.sort_by{|i| i.id}
  return true if taxon1_types.empty? && taxon2_types.empty? # both are empty !! If they are both empty then they don't have the same type, the have no types  !!
  return false if taxon1_types.empty? || taxon2_types.empty? # one is empty

  taxon1_types.map(&:biological_object_id) == taxon2_types.map(&:biological_object_id) # collect{|i| i.biological_object_id}
end

- (Boolean) is_family_rank?

Returns:

  • (Boolean)


374
375
376
# File 'app/models/protonym.rb', line 374

def is_family_rank?
  FAMILY_RANK_NAMES.include?(rank_string)
end

- (boolean) is_fossil?

Returns:

  • (boolean)


150
151
152
# File 'app/models/protonym.rb', line 150

def is_fossil?
  taxon_name_classifications.with_type_contains('::Fossil').any?
end

- (Boolean) is_genus_or_species_rank?

Returns:

  • (Boolean)


370
371
372
# File 'app/models/protonym.rb', line 370

def is_genus_or_species_rank?
  is_species_rank? || is_genus_rank?
end

- (Boolean) is_genus_rank?

Returns:

  • (Boolean)


366
367
368
# File 'app/models/protonym.rb', line 366

def is_genus_rank?
  GENUS_RANK_NAMES.include?(rank_string)
end

- (Boolean) is_latin?

Returns:

  • (Boolean)


358
359
360
# File 'app/models/protonym.rb', line 358

def is_latin?
  !NOT_LATIN.match(name) || has_latinized_exceptions?
end

- (Boolean) is_species_rank?

Returns:

  • (Boolean)


362
363
364
# File 'app/models/protonym.rb', line 362

def is_species_rank?
  SPECIES_RANK_NAMES.include?(rank_string)
end

- (Object) list_of_coordinated_names



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/models/protonym.rb', line 154

def list_of_coordinated_names
  list = []
  if self.rank_string
    r = self.iczn_set_as_incorrect_original_spelling_of_relationship
    if r.blank?
      search_rank = NomenclaturalRank::Iczn.group_base(self.rank_string)
      if !!search_rank
        if search_rank =~ /Family/
          z = Protonym.family_group_base(self.name)
          search_name = z.nil? ? nil : Protonym::FAMILY_GROUP_ENDINGS.collect{|i| z+i}
        else
          search_name = self.name
        end
      else
        search_name = nil
      end

      unless search_name.nil?
        list = Protonym.ancestors_and_descendants_of(self).not_self(self).
          with_rank_class_including(search_rank).
          # TODO @proceps Rails 5.0 makes this scope fail, for reasons I have not yet investigated. @tuckerjd
          # with_name_in_array(search_name).
          where('name in (?)', search_name).
          as_subject_without_taxon_name_relationship_base('TaxonNameRelationship::Iczn::Invalidating::Synonym')
      else
        list = []
      end
    else
      list = [r.object_taxon_name]
    end
  end
  return list
end

- (Object) lowest_rank_coordinated_taxon



248
249
250
251
252
253
254
255
256
# File 'app/models/protonym.rb', line 248

def lowest_rank_coordinated_taxon
  list = [self] + list_of_coordinated_names
  if list.count == 1
    self
  else
    parents = list.collect{|i| i.parent.id}
    list.detect{|t| !parents.include?(t.id)}
  end
end

- (Object) name_is_latinized (protected)



692
693
694
# File 'app/models/protonym.rb', line 692

def name_is_latinized
  errors.add(:name, 'Name must be latinized, no digits or spaces allowed') if !is_latin?
end

- (Object) name_is_valid_format (protected)



696
697
698
# File 'app/models/protonym.rb', line 696

def name_is_valid_format
  rank_class.validate_name_format(self) if rank_class && rank_class.respond_to?(:validate_name_format) && !has_latinized_exceptions?
end

- (Object) name_with_alternative_spelling



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'app/models/protonym.rb', line 390

def name_with_alternative_spelling
  if rank_class.nil? || nomenclatural_code != :iczn
    # rank_string =~ /::Icn::/ # self.class != Protonym
    return nil
  elsif is_species_rank? # rank_string =~ /Species/
    n = name.squish # remove extra spaces and line brakes
    n = n.split(' ').last
    n = n[0..-4] + 'ae' if n =~ /^[a-z]*iae$/ # -iae > -ae in the end of word
    n = n[0..-6] + 'orum' if n =~ /^[a-z]*iorum$/ # -iorum > -orum
    n = n[0..-6] + 'arum' if n =~ /^[a-z]*iarum$/ # -iarum > -arum
    n = n[0..-3] + 'a' if n =~ /^[a-z]*um$/ # -um > -a
    n = n[0..-3] + 'a' if n =~ /^[a-z]*us$/ # -us > -a
    n = n[0..-3] + 'e' if n =~ /^[a-z]*is$/ # -is > -e
    n = n[0..-3] + 'ra' if n =~ /^[a-z]*er$/ # -er > -ra
    n = n[0..-7] + 'ensis' if n =~ /^[a-z]*iensis$/ # -iensis > -ensis
    n = n[0..-5] + 'ana' if n =~ /^[a-z]*iana$/ # -iana > -ana
    n = n.gsub('ae', 'e').
          gsub('oe', 'e').
          gsub('ai', 'i').
          gsub('ei', 'i').
          gsub('ej', 'i').
          gsub('ii', 'i').
          gsub('ij', 'i').
          gsub('jj', 'i').
          gsub('j', 'i').
          gsub('y', 'i').
          gsub('v', 'u').
          gsub('rh', 'r').
          gsub('th', 't').
          gsub('k', 'c').
          gsub('ch', 'c').
          gsub('tt', 't').
          gsub('bb', 'b').
          gsub('rr', 'r').
          gsub('nn', 'n').
          gsub('mm', 'm').
          gsub('pp', 'p').
          gsub('ss', 's').
          gsub('ff', 'f').
          gsub('ll', 'l').
          gsub('ct', 't').
          gsub('ph', 'f').
          gsub('-', '')
    n = n[0, 3] + n[3..-4].gsub('o', 'i') + n[-3, 3] if n.length > 6 # connecting vowel in the middle of the word (nigrocinctus vs. nigricinctus)
  elsif rank_string =~ /Family/
    n_base = Protonym.family_group_base(self.name)
    if n_base.nil? || n_base == self.name
      n = self.name
    else
      n = n_base + 'idae'
    end
  else
    n = self.name.squish
  end

  return n
end

- (Object) new_parent_taxon_name (protected)



704
705
706
707
708
709
710
711
# File 'app/models/protonym.rb', line 704

def new_parent_taxon_name
  r = self.iczn_uncertain_placement_relationship
  unless r.blank?
    if self.parent != r.object_taxon_name
      errors.add(:parent_id, "Taxon has a relationship 'incertae sedis' - delete the relationship before changing the parent")
    end
  end
end

- (boolean) nominotypical_sub_of?(protonym)

Returns:

  • (boolean)


675
676
677
# File 'app/models/protonym.rb', line 675

def nominotypical_sub_of?(protonym)
  is_genus_or_species_rank? && parent == protonym && parent.name == protonym.name
end

- (Object) original_combination_class_relationships

return [Array]

TaxonNameRelationship classes that are applicable to this name, as deterimined by Rank


313
314
315
316
317
318
319
# File 'app/models/protonym.rb', line 313

def original_combination_class_relationships
  relations = []
  TaxonNameRelationship::OriginalCombination.descendants.each do |r|
    relations.push(r) if r.valid_object_ranks.include?(self.rank_string)
  end
  relations
end

- (Array) original_combination_relationships_and_stubs

Returns A relationships for each possible original combination relationship

Returns:

  • (Array)

    A relationships for each possible original combination relationship



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'app/models/protonym.rb', line 323

def original_combination_relationships_and_stubs
  # TODO: figure out where to really put this, likely in one big sort
  display_order = [
    :original_genus, :original_subgenus, :original_species, :original_subspecies, :original_variety, :original_form
  ]

  defined_relations = self.original_combination_relationships.all
  created_already   = defined_relations.collect{|a| a.class}
  new_relations     = []

  original_combination_class_relationships.each do |r|
    new_relations.push( r.new(object_taxon_name: self) ) if !created_already.include?(r)
  end

  (new_relations + defined_relations).sort{|a,b|
    display_order.index(a.class.inverse_assignment_method) <=> display_order.index(b.class.inverse_assignment_method)
  }
end

- (Object) reduce_list_of_synonyms(list)



378
379
380
381
382
383
384
385
386
387
388
# File 'app/models/protonym.rb', line 378

def reduce_list_of_synonyms(list)
  return [] if list.empty?
  list1 = list.select{|s| s.id == s.lowest_rank_coordinated_taxon.id}
  unless list1.empty?
    date1 = self.nomenclature_date
    unless date1.nil?
      list1.reject!{|s| date1 < (s.year_of_publication ? s.nomenclature_date : Time.utc(1))}
    end
  end
  list1
end

- (Object) set_cached (protected)



727
728
729
730
731
732
733
734
# File 'app/models/protonym.rb', line 727

def set_cached
  super
  set_cached_names_for_dependants # !!! do we run set cached names 2 x !?!
  set_cached_original_combination
  set_cached_homonymy
  set_cached_species_homonym if is_species_rank?
  set_cached_misspelling
end

- (Object) set_cached_homonymy (protected)



737
738
739
740
741
742
# File 'app/models/protonym.rb', line 737

def set_cached_homonymy
  update_columns(
    cached_primary_homonym: get_genus_species(:original, :self),
    cached_primary_homonym_alternative_spelling: get_genus_species(:original, :alternative)
  )
end

- (Object) set_cached_misspelling (protected)

all three in one update here



745
746
747
# File 'app/models/protonym.rb', line 745

def set_cached_misspelling
  update_column(:cached_misspelling, get_cached_misspelling)
end

- (Object) set_cached_names_for_dependants

TODO: @proceps - confirm this is only applicable to Protonym, NOT Combination Should this be in Protonym



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'app/models/protonym.rb', line 615

def set_cached_names_for_dependants
  dependants = []
  related_through_original_combination_relationships = []
  combination_relationships = []

  TaxonName.transaction do
    if is_genus_or_species_rank?
      dependants = Protonym.descendants_of(self).to_a
      related_through_original_combination_relationships = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_contains('OriginalCombination')
      combination_relationships = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_contains('::Combination')
    end

   #  dependants.push(self) # combination does hit here

    # Combination can hit here
    classified_as_relationships = TaxonNameRelationship.where_object_is_taxon_name(self).with_type_contains('SourceClassifiedAs')

    # TODO: not used!?
    # hybrid_relationships = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_contains('Hybrid')

    dependants.each do |i|
      columns_to_update = {
        cached: i.get_full_name,
        cached_html: i.get_full_name_html
      }

      if i.is_species_rank?
        columns_to_update[:cached_secondary_homonym] = i.get_genus_species(:current, :self)
        columns_to_update[:cached_secondary_homonym_alternative_spelling] = i.get_genus_species(:current, :alternative)
      end

      i.update_columns(columns_to_update)
    end

    related_through_original_combination_relationships.collect{|i| i.object_taxon_name}.uniq.each do |i|
      i.update_cached_original_combinations
    end

    # Update values in Combinations
    combination_relationships.collect{|i| i.object_taxon_name}.uniq.each do |i|
      i.update_columns(
        cached: i.get_full_name,
        cached_html: i.get_full_name_html)
    end

    classified_as_relationships.collect{|i| i.subject_taxon_name}.uniq.each do |i|
      i.update_column(:cached_classified_as, i.get_cached_classified_as)
    end

    classified_as_relationships.collect{|i| i.object_taxon_name}.uniq.each do |i|
      i.update_columns(
        cached: i.get_full_name,
        cached_html: i.get_full_name_html
      )
    end

  end
end

- (Object) set_cached_original_combination (protected)



749
750
751
# File 'app/models/protonym.rb', line 749

def set_cached_original_combination
  update_column(:cached_original_combination, get_original_combination)
end

- (Object) set_cached_species_homonym



606
607
608
609
610
611
# File 'app/models/protonym.rb', line 606

def set_cached_species_homonym
  update_columns(
    cached_secondary_homonym: get_genus_species(:current, :self),
    cached_secondary_homonym_alternative_spelling: get_genus_species(:current, :alternative)
  )
end

- (Object) species_questionable_ending(taxon_name_classification_class, tested_name)



458
459
460
461
462
463
464
# File 'app/models/protonym.rb', line 458

def species_questionable_ending(taxon_name_classification_class, tested_name)
  return nil unless is_species_rank?
  taxon_name_classification_class.questionable_species_endings.each do |e|
    return e if tested_name =~ /^[a-z]*#{e}$/
  end
  nil
end

- (Object) sv_cached_names (protected)

Validate whether cached names need to be rebuilt.

TODO: this is kind of pointless, we generate all the alues need for cached, names, at that point the cached values should just be persisted The logic here also duplicates the tracking needed for building cached names.

Refactor this to single methods, one each to validate cached name?



766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
# File 'app/models/protonym.rb', line 766

def sv_cached_names
  is_cached = true
  is_cached = false if cached_author_year != get_author_and_year

  if is_cached && cached_html != get_full_name_html ||
    cached_misspelling != get_cached_misspelling ||
    cached_original_combination != get_original_combination ||
    cached_primary_homonym != get_genus_species(:original, :self) ||
    cached_primary_homonym_alternative_spelling != get_genus_species(:original, :alternative) ||
    rank_string =~ /Species/ &&
      (cached_secondary_homonym != get_genus_species(:current, :self) ||
        cached_secondary_homonym_alternative_spelling != get_genus_species(:current,
                                                                           :alternative))
    is_cached = false
  end

  soft_validations.add(
    :base, 'Cached values should be updated',
    fix: :sv_fix_cached_names, success_message: 'Cached values were updated'
  ) if !is_cached
end

- (Object) update_cached_original_combinations

TODO: @proceps - confirm this is only applicable to Protonym, NOT Combination



599
600
601
602
603
604
# File 'app/models/protonym.rb', line 599

def update_cached_original_combinations
  update_columns(
    cached_original_combination: get_original_combination,
    cached_primary_homonym: get_genus_species(:original, :self),
    cached_primary_homonym_alternative_spelling: get_genus_species(:original, :alternative))
end

- (Object) validate_rank_class_class (protected)



723
724
725
# File 'app/models/protonym.rb', line 723

def validate_rank_class_class
  errors.add(:rank_class, 'Rank not found') unless RANKS.include?(rank_string)
end