Class: NomenclatureCatalog::EntryItem

Inherits:
Object
  • Object
show all
Defined in:
lib/nomenclature_catalog/entry_item.rb

Overview

Is 1:1 with a Citation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object: nil, taxon_name: nil, citation: nil, nomenclature_date: nil, citation_date: nil) ⇒ EntryItem

Returns a new instance of EntryItem.



22
23
24
25
26
27
28
29
30
31
# File 'lib/nomenclature_catalog/entry_item.rb', line 22

def initialize(object: nil, taxon_name: nil, citation: nil, nomenclature_date: nil, citation_date: nil)
  raise if object.nil? || taxon_name.nil?
  # raise if nomenclature_date.nil? && !(object.class.to_s == 'Protonym' || 'Combination' || 'TaxonNameRelationship')

  @object = object
  @taxon_name = taxon_name
  @nomenclature_date = nomenclature_date
  @citation_date = citation_date
  @citation = citation
end

Instance Attribute Details

#citation ⇒ Object

Optional



9
10
11
# File 'lib/nomenclature_catalog/entry_item.rb', line 9

def citation
  @citation
end

#citation_date ⇒ None

Returns:

  • (None)


17
18
19
# File 'lib/nomenclature_catalog/entry_item.rb', line 17

def citation_date
  @citation_date
end

#nomenclature_date ⇒ Date

Returns:

  • (Date)


13
14
15
# File 'lib/nomenclature_catalog/entry_item.rb', line 13

def nomenclature_date
  @nomenclature_date
end

#object ⇒ Object

Returns the value of attribute object.



6
7
8
# File 'lib/nomenclature_catalog/entry_item.rb', line 6

def object
  @object
end

#taxon_name ⇒ Object

Required



20
21
22
# File 'lib/nomenclature_catalog/entry_item.rb', line 20

def taxon_name
  @taxon_name
end

Instance Method Details

#cited? ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/nomenclature_catalog/entry_item.rb', line 34

def cited?
  !citation.nil? # object.class.name == 'Citation'
end

#cited_class ⇒ String (protected)

Returns:

  • (String)


112
113
114
115
116
117
118
# File 'lib/nomenclature_catalog/entry_item.rb', line 112

def cited_class
  if citation
    citation.annotated_object.class.name
  else
    object.class.name
  end
end

#from_relationship? ⇒ Regex::Match

Returns:

  • (Regex::Match)


58
59
60
# File 'lib/nomenclature_catalog/entry_item.rb', line 58

def from_relationship?
  object_class =~ /^TaxonNameRelationship/
end

#is_subsequent? ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/nomenclature_catalog/entry_item.rb', line 63

def is_subsequent?
 #     object == taxon_name && !citation.try(:is_original?)
  object == taxon_name && !citation.nil? && !citation.is_original?
end

#is_valid_name? ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/nomenclature_catalog/entry_item.rb', line 105

def is_valid_name?
  object_class == 'Protonym' && object.is_valid?
end

#object_class ⇒ String

Returns:

  • (String)


53
54
55
# File 'lib/nomenclature_catalog/entry_item.rb', line 53

def object_class
  object.class.name
end

#origin ⇒ String

Returns:

  • (String)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/nomenclature_catalog/entry_item.rb', line 89

def origin
  case object_class
  when 'Protonym'
    'protonym'
  when 'Hybrid'
    'hybrid'
  when 'Combination'
    'combination'
  when /TaxonNameRelationship/
    'taxon_name_relationship'
  else
    'error'
  end
end

#other_name ⇒ String

Returns:

  • (String)


69
70
71
72
73
# File 'lib/nomenclature_catalog/entry_item.rb', line 69

def other_name
  if from_relationship?
    ([object.subject_taxon_name, object.object_taxon_name] - [taxon_name]).first
  end
end

#protonym_ids ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/nomenclature_catalog/entry_item.rb', line 75

def protonym_ids
  case object_class
  when 'Protonym'
    [object.id]
  when 'Hybrid'
    [object.id]
  when 'Combination'
    object.combination_relationships.pluck(:subject_taxon_name_id)
  when /TaxonNameRelationship/
    [object.subject_taxon_name_id, object.object_taxon_name_id]
  end
end

#source ⇒ Source?

Returns:



39
40
41
# File 'lib/nomenclature_catalog/entry_item.rb', line 39

def source
  citation.try(:source)
end