Class: Protonym

Inherits:
TaxonName
  • Object
show all
Defined in:
app/models/protonym.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TaxonName

#all_generic_placements, #all_taxon_name_relationships, #ancestor_at_rank, #cached_name_and_author_year, #gender_class, #gender_name, #get_author_and_year, #get_cached_misspelling, #get_classified_as, #get_combination, #get_full_name, #get_genus_species, #get_higher_classification, #get_original_combination, #get_valid_taxon_name, #name_in_gender, #name_with_alternative_spelling, #name_with_misspelling, #nomenclature_date, #part_of_speech_class, #part_of_speech_name, #rank, #rank_class, #rank_class=, #rank_string, #related_taxon_names, #set_cached_author_year, #set_cached_classified_as, #set_cached_full_name, #set_cached_higher_classification, #set_cached_misspelling, #set_cached_names, #set_cached_original_combination, #set_primary_homonym_alt, #set_primaty_homonym, #set_secondary_homonym, #set_secondary_homonym_alt, #set_type_if_empty, #unavailable?, #unavailable_or_invalid?

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?

Class Method Details

.family_group_base(name_string) ⇒ Object



153
154
155
156
# File 'app/models/protonym.rb', line 153

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

Instance Method Details

#ancestors_and_descendantsObject



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

def ancestors_and_descendants
  Protonym.ancestors_and_descendants_of(self).to_a
end

#get_primary_typeObject



158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/models/protonym.rb', line 158

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

#list_of_coordinated_namesObject



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
# File 'app/models/protonym.rb', line 106

def list_of_coordinated_names
  if self.incorrect_original_spelling.nil?
    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 : NomenclaturalRank::Iczn::FamilyGroup::ENDINGS.collect{|i| z+i}
        #search_name = z.nil? ? nil : "#{z}(ini|ina|inae|idae|oidae|odd|ad|oidea)"
      else
        search_name = self.name
      end
    else
      search_name = nil
    end

    unless search_name.nil?
      list = Protonym.ancestors_and_descendants_of(self).
          with_rank_class_including(search_rank).
          with_name_in_array(search_name).
          as_subject_without_taxon_name_relationship_base('TaxonNameRelationship::Iczn::Invalidating::Synonym') # <- use this
      #list1 = self.ancestors_and_descendants                               # scope with parens
      #list1 = list1.select{|i| /#{search_rank}.*/.match(i.rank_class.to_s)} # scope on rank_class
      #list1 = list1.select{|i| /#{search_name}/.match(i.name)}              # scope on named
      #list1 = list1.reject{|i| i.unavailable_or_invalid?}                   # scope with join on taxon_name_relationships and where > 1 on them
    else
      list = []
    end
  else
    list = [self.incorrect_original_spelling.object_taxon_name]
  end
  return list
end

#lowest_rank_coordinated_taxonObject



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

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

#matching_primary_types(taxon1, taxon2) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'app/models/protonym.rb', line 171

def matching_primary_types(taxon1, taxon2)
  return true unless self.rank_class.parent.to_s =~ /Species/
  taxon1_types = taxon1.get_primary_type
  taxon2_types = taxon2.get_primary_type
  if taxon1_types.empty? && taxon2_types.empty? # both are empty
    true
  elsif taxon1_types.count != taxon2_types.count
    false
  elsif TypeMaterial.primary_with_protonym_array([taxon1.id, taxon2.id]).to_a.count == taxon1_types.count
    true
  else
    false
  end
end