Class: Catalog::Nomenclature::Entry

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

Instance Attribute Summary

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, #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.



13
14
15
16
# File 'lib/catalog/nomenclature/entry.rb', line 13

def initialize(taxon_name)
  super(taxon_name)
  true
end

Instance Method Details

#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



127
128
129
130
131
132
133
134
# File 'lib/catalog/nomenclature/entry.rb', line 127

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_protonymsArray (protected)

Returns:

  • (Array)


161
162
163
# File 'lib/catalog/nomenclature/entry.rb', line 161

def all_protonyms
  items.select{|i| i.origin == 'protonym' }
end

#all_sourcesArray of Sources (protected)

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

Returns:

  • (Array of Sources)

    as extracted for all EntryItems, orderd alphabetically by full citation



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/catalog/nomenclature/entry.rb', line 138

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

  # 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



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

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) # maybe 'v'

    if !t.citations.load.any?
      items << Catalog::Nomenclature::EntryItem.new(
        object: t,
        base_object: t,
        citation: nil,
        nomenclature_date: t.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) # maybe 'v'

      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.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.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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/catalog/nomenclature/entry.rb', line 85

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)


120
121
122
# File 'lib/catalog/nomenclature/entry.rb', line 120

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

#namesArray

Returns:

  • (Array)


111
112
113
114
# File 'lib/catalog/nomenclature/entry.rb', line 111

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:



105
106
107
108
# File 'lib/catalog/nomenclature/entry.rb', line 105

def ordered_by_nomenclature_date
  now = Time.now
  items.sort{|a,b| [(a.nomenclature_date || 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 || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] }
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



167
168
169
# File 'lib/catalog/nomenclature/entry.rb', line 167

def relationship_items
  items.select{|i| i.object_class =~ /TaxonNameRelationship/}
end