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

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

- (Scope) dates

Returns:

  • (Scope)


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

- (Scope) sources

Returns:

  • (Scope)


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

def sources
  @sources
end

- (Scope) topics

Returns:

  • (Scope)


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

def topics
  @topics
end

Instance Method Details

- (Array) all_dates (protected)

Returns:

  • (Array)


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

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

- (Array) all_names (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

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



115
116
117
118
119
120
121
122
123
124
# 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.compact.uniq.sort_by {|a| a.cached}
end

- (Array) all_topics (protected)

Returns:

  • (Array)


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

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

- (Array) date_range

Returns:

  • (Array)


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

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

- (Array) item_names(catalog_item) (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

- (Scope) names

Returns:

  • (Scope)


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

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:



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

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



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

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

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

- (Hash) year_hash

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