Class: Catalog::Nomenclature::Entry

Inherits:
Entry
  • Object
show all
Defined in:
lib/catalog/nomenclature/entry.rb

Instance Attribute Summary collapse

Attributes inherited from Entry

#dates, #item_index, #items, #object, #sort_order, #sources, #topics

Instance Method Summary collapse

Methods inherited from Entry

#all_dates, #all_topics, #citations, #coordinate_entry_items, #date_range, #first_item?, #index_items, #is_subsequent_entry_item?, #items_by_object, #last_item?, #original_citation_present?, #to_json, #topics_for_source, #year_hash

Constructor Details

#initialize(taxon_name) ⇒ Entry

Returns a new instance of Entry.



17
18
19
20
# File 'lib/catalog/nomenclature/entry.rb', line 17

def initialize(taxon_name)
  super(taxon_name)
  true
end

Instance Attribute Details

#all_protonymsArray (protected)

Returns:

  • (Array)


247
248
249
# File 'lib/catalog/nomenclature/entry.rb', line 247

def all_protonyms
  @all_protonyms
end

#citations_with_namesHash

Returns this is a very object heavy summary.

Returns:

  • (Hash)

    this is a very object heavy summary



122
123
124
# File 'lib/catalog/nomenclature/entry.rb', line 122

def citations_with_names
  @citations_with_names
end

#relationship_itemsArray of EntryItems (protected)

Returns only those entry items that reference a TaxonNameRelationship.

Returns:

  • (Array of EntryItems)

    only those entry items that reference a TaxonNameRelationship



253
254
255
# File 'lib/catalog/nomenclature/entry.rb', line 253

def relationship_items
  @relationship_items
end

Instance Method Details

#all_citationsArray of Citations (protected)

Returns:

  • (Array of Citations)


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/catalog/nomenclature/entry.rb', line 222

def all_citations
  c  = items.collect{|i| i.citation}

  if !object.nil?
    relationship_items.each do |i|
      c << i.object.object_taxon_name.origin_citation if i.object.subject_taxon_name != object  # base_object?
      c << i.object.subject_taxon_name.origin_citation if i.object.object_taxon_name != object
    end
  end

  # TODO: Why aren't these first-class EntryItems? I think they should be.
  # This is here because they are cross-referenced (referenced inline) in (HTML) rendering
  c += ::TaxonNameClassification.where(taxon_name_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tnc| tnc.citations}

  c += TaxonNameRelationship::Typification.where(object_taxon_name_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tr| tr.citations}

  c += TypeMaterial.where(protonym_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tm| tm.citations}

  c.flatten.compact.uniq.sort_by{|s| s.source.cached}
end

#all_namesArray of TaxonName (protected)

Returns a summary of all names referenced in this entry.

Returns:

  • (Array of TaxonName)

    a summary of all names referenced in this entry



187
188
189
190
191
192
193
194
# File 'lib/catalog/nomenclature/entry.rb', line 187

def all_names
  n = [ object ]
  items.each do |i|
    n.push item_names(i)
  end
  n = n.flatten.uniq.sort_by!(&:cached)
  n
end

#all_sourcesArray of Sources (protected)

Returns as extracted for all EntryItems, ordered alphabetically by full citation.

Returns:

  • (Array of Sources)

    as extracted for all EntryItems, ordered alphabetically by full citation



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/catalog/nomenclature/entry.rb', line 198

def all_sources
  s  = items.collect{|i| i.source}
  if !object.nil?
    relationship_items.each do |i|
      s << i.object.object_taxon_name.origin_citation.try(:source) if i.object.subject_taxon_name != object  # base_object?
      s << i.object.subject_taxon_name.origin_citation.try(:source) if i.object.object_taxon_name != object
    end
  end

  # TODO: Why aren't these first-class EntryItems?  I think they should be.
  # This is here because they are cross-referenced in HTML rendering
  s += ::TaxonNameClassification.where(taxon_name_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tnc| tnc.citations.collect{|c| c.source}}.flatten

  s += TaxonNameRelationship::Typification.where(object_taxon_name_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tnc| tnc.citations.collect{|c| c.source}}.flatten

  s += TypeMaterial.where(protonym_id: all_protonyms.collect{|p| p.object}).all.
    collect{|tnc| tnc.citations.collect{|c| c.source}}.flatten

  s.compact.uniq.sort_by{|s| s.cached}
end

#buildObject



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
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/catalog/nomenclature/entry.rb', line 22

def build
  v = object.valid_taxon_name
  base_names = v.historical_taxon_names

  base_names.each do |t|

    matches_target = entry_item_matches_target?(t, object)

    if !t.citations.load.any?
      items << Catalog::Nomenclature::EntryItem.new(
        object: t,
        base_object: t,
        citation: nil,
        nomenclature_date: t.cached_nomenclature_date,
        year_suffix: nil,
        pages: nil,
        current_target: matches_target)
    end

    t.citations.each do |c|
      items << Catalog::Nomenclature::EntryItem.new(
        object: t,
        base_object: t,
        citation: c,
        nomenclature_date: c.source.cached_nomenclature_date,
        year_suffix: c.source.year_suffix,
        pages: c.source.pages,
        current_target: matches_target)
    end

    ::TaxonNameRelationship.where_subject_is_taxon_name(t).with_type_array(STATUS_TAXON_NAME_RELATIONSHIP_NAMES + TAXON_NAME_RELATIONSHIP_NAMES_CLASSIFICATION).each do |r|

      matches_target = entry_item_matches_target?(r.subject_taxon_name, object)

      if !r.citations.load.any?
        items << Catalog::Nomenclature::EntryItem.new(
          object: r,
          base_object: r.subject_taxon_name,
          citation: nil,
          nomenclature_date: r.subject_taxon_name.cached_nomenclature_date,
          year_suffix: nil,
          pages: nil,
          current_target: matches_target
        )
      end

      r.citations.each do |c|
        items << Catalog::Nomenclature::EntryItem.new(
          object: r,
          base_object: r.subject_taxon_name,
          citation: c,
          nomenclature_date: (c.try(:source).try(:cached_nomenclature_date) || r.subject_taxon_name.cached_nomenclature_date),
          year_suffix: (c.try(:source).try(:year_suffix) || nil),
          pages: (c.try(:source).try(:pages) || nil),
          current_target: matches_target
        )
      end
    end
  end

  true
end

#entry_item_matches_target?(item_object, reference_object) ⇒ Boolean

Returns this is the MM result. Only return true when the protonym that is the focus of the Entry is referenced in the EntryItem.

Returns:

  • (Boolean)

    this is the MM result. Only return true when the protonym that is the focus of the Entry is referenced in the EntryItem



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/catalog/nomenclature/entry.rb', line 89

def entry_item_matches_target?(item_object, reference_object)
  case item_object.class.to_s
  when 'Protonym'
    return item_object.id == reference_object.id
  when 'Combination'
    item_object.combination_taxon_names.each do |p|
      return true if p.id == reference_object.id
    end
    return false
  else
    if object_class =~ /^TaxonNameRelationship/
      # Technically we only want misspellings here?
      return true if item_object.subject_taxon_name.id == reference_object.id
    end
    return false
  end
end

#item_names(catalog_item) ⇒ Array (protected)

Parameters:

  • catalog_item (CatalogEntry)

Returns:

  • (Array)


180
181
182
# File 'lib/catalog/nomenclature/entry.rb', line 180

def item_names(catalog_item)
  [object, catalog_item.base_object, catalog_item.other_name].compact.uniq
end

#namesArray

Returns:

  • (Array)


115
116
117
118
# File 'lib/catalog/nomenclature/entry.rb', line 115

def names
  @names ||= all_names
  @names
end

#ordered_by_nomenclature_dateArray of NomenclatureCatalog::EntryItem

Returns sorted by date, then taxon name name as rendered for this item.

Returns:



109
110
111
112
# File 'lib/catalog/nomenclature/entry.rb', line 109

def ordered_by_nomenclature_date
  now = Time.now
  items.sort{|a,b| [(a.nomenclature_date&.to_time || now), a.year_suffix.to_s + 'z', a.pages.to_s + 'z', a.object_class, a.base_object.cached_original_combination.to_s ] <=> [(b.nomenclature_date&.to_time || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] }
end