Class: TaxonNameClassification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping, Shared::Citable, SoftValidation
Defined in:
app/models/taxon_name_classification.rb

Direct Known Subclasses

Icn, Iczn, Latinized

Defined Under Namespace

Classes: Icn, Iczn, Latinized

Class Method Summary collapse

Instance Method Summary collapse

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

.applicable_ranksObject



35
36
37
# File 'app/models/taxon_name_classification.rb', line 35

def self.applicable_ranks
  []
end

.class_nameObject

Return a String with the “common” name for this class.



44
45
46
# File 'app/models/taxon_name_classification.rb', line 44

def self.class_name
  self.name.demodulize.underscore.humanize.downcase
end

.code_applicability_end_yearObject



31
32
33
# File 'app/models/taxon_name_classification.rb', line 31

def self.code_applicability_end_year
  9999
end

.code_applicability_start_yearObject

years of applicability for each class



27
28
29
# File 'app/models/taxon_name_classification.rb', line 27

def self.code_applicability_start_year
  1
end

.disjoint_taxon_name_classesObject



39
40
41
# File 'app/models/taxon_name_classification.rb', line 39

def self.disjoint_taxon_name_classes
  []
end

.possible_genus_endingsObject



56
57
58
# File 'app/models/taxon_name_classification.rb', line 56

def self.possible_genus_endings
  nil
end

.possible_species_endingsObject



48
49
50
# File 'app/models/taxon_name_classification.rb', line 48

def self.possible_species_endings
  nil
end

.questionable_species_endingsObject



52
53
54
# File 'app/models/taxon_name_classification.rb', line 52

def self.questionable_species_endings
  nil
end

Instance Method Details

#sv_not_specific_classesObject



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

def sv_not_specific_classes
  case self.type_name
    when 'TaxonNameClassification::Iczn::Available'
      soft_validations.add(:type, 'Please specify if the name is valid or invalid')
    when 'TaxonNameClassification::Iczn::Unavailable'
      soft_validations.add(:type, 'Please specify the reasons for the name being unavailable')
    when 'TaxonNameClassification::Iczn::Available::Invalid'
      soft_validations.add(:type, 'Please replace with appropriate relationship')
    when 'TaxonNameClassification::Iczn::Available::Invalid::Homonym'
      soft_validations.add(:type, 'Please replace with appropriate relationship')
    when 'TaxonNameClassification::Iczn::Available::Valid'
      soft_validations.add(:type, 'Please replace with appropriate relationship')
    when 'TaxonNameClassification::Iczn::Unavailable::Suppressed'
      soft_validations.add(:type, 'Please specify the reasons for the name being suppressed')
    when 'TaxonNameClassification::Iczn::Unavailable::Excluded'
      soft_validations.add(:type, 'Please specify the reasons for the name being excluded')
    when 'TaxonNameClassification::Iczn::Unavailable::NomenNudum'
      soft_validations.add(:type, 'Please specify the reasons for the name being nomen nudum')
    when 'TaxonNameClassification::Iczn::Unavailable::NonBinomial'
      soft_validations.add(:type, 'Please specify the reasons for the name being non binomial')
    when 'TaxonNameClassification::Icn::EffectivelyPublished'
      soft_validations.add(:type, 'Please specify if the name is validly or invalidly published')
    when 'TaxonNameClassification::Icn::EffectivelyPublished::InvalidlyPublished'
      soft_validations.add(:type, 'Please specify the reasons for the name being invalidly published')
    when 'TaxonNameClassification::Icn::EffectivelyPublished::ValidlyPublished'

      soft_validations.add(:type, 'Please specify if the name is legitimate or illegitimate')
    when 'TaxonNameClassification::Icn::EffectivelyPublished::ValidlyPublished::Legitimate'
      soft_validations.add(:type, 'Please specify the reasons for the name being Legitimate')
    when 'TaxonNameClassification::Icn::EffectivelyPublished::ValidlyPublished::Illegitimate'
      soft_validations.add(:type, 'Please specify the reasons for the name being Illegitimate')
  end
end

#sv_proper_classificationObject

region Soft validation



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/taxon_name_classification.rb', line 83

def sv_proper_classification
  # type is a string already 
  if TAXON_NAME_CLASS_NAMES.include?(self.type)
    # self.type_class is a Class
    if not self.type_class.applicable_ranks.include?(self.taxon_name.rank_class.to_s)
      soft_validations.add(:type, 'The status is unapplicable to the name of ' + self.taxon_name.rank_class.rank_name + ' rank')
    end
  end
  y = self.taxon_name.year_of_publication
  if not y.nil?
    if y > self.type_class.code_applicability_end_year || y < self.type_class.code_applicability_start_year
      soft_validations.add(:type, 'The status is unapplicable to the name published in ' + y.to_s)
    end
  end
end

#sv_validate_disjoint_classesObject



99
100
101
102
103
104
# File 'app/models/taxon_name_classification.rb', line 99

def sv_validate_disjoint_classes
  classifications = TaxonNameClassification.where_taxon_name(self.taxon_name).not_self(self)
  classifications.each  do |i|
    soft_validations.add(:type, "Conflicting with another status: '#{i.type_name}'") if self.type_class.disjoint_taxon_name_classes.include?(i.type_name)
  end
end

#type_classObject



69
70
71
72
73
# File 'app/models/taxon_name_classification.rb', line 69

def type_class
  r = read_attribute(:type).to_s
  r = TAXON_NAME_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  r
end

#type_class=(value) ⇒ Object



65
66
67
# File 'app/models/taxon_name_classification.rb', line 65

def type_class=(value)
  write_attribute(:type, value.to_s)
end

#type_nameObject



60
61
62
63
# File 'app/models/taxon_name_classification.rb', line 60

def type_name
  r = self.type.to_s
  TAXON_NAME_CLASS_NAMES.include?(r) ? r : nil
end

#validate_taxon_name_classlassificationObject



75
76
77
# File 'app/models/taxon_name_classification.rb', line 75

def validate_taxon_name_classlassification
  errors.add(:type, "Status not found") if !self.type.nil? and !TAXON_NAME_CLASS_NAMES.include?(self.type.to_s)
end