/
combination.rb
72 lines (56 loc) · 1.72 KB
/
combination.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
# The class relationships used to create Combinations.
class TaxonNameRelationship::Combination < TaxonNameRelationship
validates_uniqueness_of :object_taxon_name_id, scope: :type
validate :subject_is_protonym
# This is over-writing the assignment in taxon_name.rb, which restricts destroy.
# In this case we want to destroy all the relationships.
has_many :related_taxon_name_relationships, class_name: 'TaxonNameRelationship',
foreign_key: :object_taxon_name_id,
inverse_of: :object_taxon_name
# @return [Integer, nil]
def self.order_index
RANKS.index(::ICN_LOOKUP[self.name.demodulize.underscore.humanize.downcase])
end
def self.disjoint_classes
self.collect_descendants_to_s(TaxonNameClassification)
end
def self.disjoint_subject_classes
self.disjoint_classes
end
def self.disjoint_object_classes
self.disjoint_classes
end
def self.nomenclatural_priority
:reverse
end
# @return [String]
# the human readable rank this relationship pertains to
def self.rank_name
name.demodulize.humanize.downcase
end
def rank_name
type_name.demodulize.humanize.downcase
end
# @return String
# the status inferred by the relationship to the object name
def object_status
rank_name + ' in combination'
end
# @return String
# the status inferred by the relationship to the subject name
def subject_status
' as ' + rank_name + ' in combination'
end
# @return String
def subject_status_connector_to_object
''
end
# @return String
def object_status_connector_to_subject
' with'
end
protected
def subject_is_protonym
errors.add(:subject_taxon_name, 'Must be a protonym') if subject_taxon_name.type == 'Combination'
end
end