Class: Catalog::Nomenclature::Entry

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

Overview

EntryItems for this Entry must follow the pattern:

  • The `base_object` is always a TaxonName

  • The `object` may be a Protony, TaxonNameRelationship, or Combination

Instance Method Summary collapse

Constructor Details

#initialize(taxon_name) ⇒ Entry

Returns a new instance of Entry



10
11
12
13
# File 'lib/catalog/nomenclature/entry.rb', line 10

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



124
125
126
127
128
129
130
131
# File 'lib/catalog/nomenclature/entry.rb', line 124

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)


158
159
160
# File 'lib/catalog/nomenclature/entry.rb', line 158

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



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

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



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

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



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

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)


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

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

#namesArray

Returns:

  • (Array)


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

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:



102
103
104
105
# File 'lib/catalog/nomenclature/entry.rb', line 102

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



164
165
166
# File 'lib/catalog/nomenclature/entry.rb', line 164

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