Class: NomenclatureCatalog::CatalogEntry

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

Overview

A Catalog Entry contains the metadata the nomenclatural history of a single “reference” taxon name. Mutiple CatalogEntries would make up a catalog.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taxon_name = nil) ⇒ CatalogEntry

Returns a new instance of CatalogEntry

Parameters:

  • args (Hash)


23
24
25
26
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 23

def initialize(taxon_name = nil)
  @items = []
  @reference_taxon_name = taxon_name
end

Instance Attribute Details

#datesScope

Returns:

  • (Scope)


14
15
16
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 14

def dates
  @dates
end

#itemsObject

Each item is a line item in the Entry



8
9
10
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 8

def items
  @items
end

#reference_taxon_nameObject

The taxon name being referenced in this entry (think of it as the header)



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

def reference_taxon_name
  @reference_taxon_name
end

#sourcesScope

Returns:

  • (Scope)


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

def sources
  @sources
end

#topicsScope

Returns:

  • (Scope)


11
12
13
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 11

def topics
  @topics
end

Instance Method Details

#all_datesArray (protected)

Returns:

  • (Array)


136
137
138
139
140
141
142
143
144
145
146
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 136

def all_dates
  d = []
  sources.each do |s|
    d.push s.cached_nomenclature_date
  end

  items.each do |i|
    d.push i.nomenclature_date
  end
  d.compact.sort
end

#all_namesArray (protected)

Returns:

  • (Array)


104
105
106
107
108
109
110
111
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 104

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

#all_protonymsArray (protected)

Returns:

  • (Array)


131
132
133
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 131

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



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 115

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

  s += TaxonNameClassification.where(taxon_name_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

#all_topicsArray (protected)

Returns:

  • (Array)


149
150
151
152
153
154
155
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 149

def all_topics
  t = []
  sources.each do |s|
    t.push topics_for_source(s)
  end
  t.flatten.uniq.compact.sort
end

#date_rangeArray

Returns:

  • (Array)


60
61
62
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 60

def date_range
  [dates.first, dates.last].compact
end

#item_names(catalog_item) ⇒ Array (protected)

Parameters:

Returns:

  • (Array)


99
100
101
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 99

def item_names(catalog_item)
  [reference_taxon_name, catalog_item.taxon_name, catalog_item.other_name].compact.uniq
end

#namesScope

Returns:

  • (Scope)


77
78
79
80
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 77

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:



30
31
32
33
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 30

def ordered_by_nomenclature_date
  now = Time.now
  items.sort{|a,b| [(a.nomenclature_date || now), a.object_class, a.taxon_name.cached_original_combination.to_s ] <=> [(b.nomenclature_date || now), b.object_class, b.taxon_name.cached_original_combination.to_s ] }
end

#relationship_itemsArray of EntryItems

Returns only those entry items that reference a TaxonNameRelationship

Returns:

  • (Array of EntryItems)

    only those entry items that reference a TaxonNameRelationship



37
38
39
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 37

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

#topics_for_source(source) ⇒ Array of Topics

Returns an extraction of all Topics referenced in citations that were observed in this CatalogEntry for the source

Parameters:

Returns:

  • (Array of Topics)

    an extraction of all Topics referenced in citations that were observed in this CatalogEntry for the source



45
46
47
48
49
50
51
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 45

def topics_for_source(source)
  topics = []
  items.each do |i|
    topics += i.object.topics if i.source == source
  end
  topics.uniq
end

#year_hashHash

Returns:

  • (Hash)


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 83

def year_hash
  h = {}
  dates.each do |d|
    if h[d.year]
      h[d.year] += 1
    else
      h[d.year] = 1
    end
  end
  h
end