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

- (CatalogEntry) initialize(taxon_name = nil)

Returns a new instance of CatalogEntry



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

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

Instance Attribute Details

- (Object) dates

All observed dates for this entry



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

def dates
  @dates
end

- (Object) items

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

- (Object) reference_taxon_name

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

- (Object) sources

All sources



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

def sources
  @sources
end

- (Object) topics

Topics are extracted from each item and cached here



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

def topics
  @topics
end

Instance Method Details

- (Object) all_dates (protected)



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

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

- (Object) all_names (protected)



93
94
95
96
97
98
99
100
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 93

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

- (Array of Sources) all_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



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

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.compact.uniq.sort_by {|a| a.cached}
end

- (Object) all_topics (protected)



127
128
129
130
131
132
133
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 127

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

- (Object) date_range



56
57
58
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 56

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

- (Object) item_names(catalog_item) (protected)



89
90
91
# File 'lib/nomenclature_catalog/catalog_entry.rb', line 89

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

- (Object) names



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

def names
  @names ||= all_names
  @names
end

- (Array of NomenclatureCatalog::EntryItem) ordered_by_nomenclature_date

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

Returns:



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

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

- (Array of EntryItems) relationship_items

Returns only those entry items that reference a TaxonNameRelationship

Returns:

  • (Array of EntryItems)

    only those entry items that reference a TaxonNameRelationship



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

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

- (Array of Topics) topics_for_source(source)

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

Returns:

  • (Array of Topics)

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



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

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

- (Object) year_hash



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

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