Class: Catalog::Entry
- Inherits:
-
Object
- Object
- Catalog::Entry
- Defined in:
- lib/catalog/entry.rb
Overview
A Catalog::Entry has many entry items. Together Catalog::Entries form a Catalog
!! Make sure to add a dependency for all Entry types to the bottom of this file !! or ‘build` may not inherit correctly (would otherwise need to be above `def initialize`
Direct Known Subclasses
Instance Attribute Summary collapse
- #dates ⇒ Array
-
#item_index ⇒ Hash
An index of all the EntryItems by global_id taken from “object”.
-
#items ⇒ Array
Each item is a line item in the Entry.
-
#object ⇒ Object
The target object(s) for this entry.
-
#sort_order ⇒ Array
Of strings, the array determines nesting order all entries in the catalog should have ‘sorts` of the same length !! Not yet implemented !!.
- #sources ⇒ Array
- #topics ⇒ Scope
Instance Method Summary collapse
- #all_citations ⇒ Object protected
-
#all_dates ⇒ Array of Date
protected
Some duplication here.
-
#all_sources ⇒ Array of Source
protected
Here .source is item.source, not item.object.source, i.e.
- #all_topics ⇒ Array of Topics protected
-
#build ⇒ Object
Redefined in subclasses! !! This is default only, it should be (re)defined in subclasses.
- #citations ⇒ Object
- #coordinate_entry_items ⇒ Object
- #date_range ⇒ Array
-
#first_item?(item) ⇒ Boolean
Named “first` to avoid conflice with ‘citation#is_original` Returns true if * it’s the only item with this object * the citation is_original * there is no original citation in any item for this object, and it’s the first in the list chronologically Inversely, returns false (in all other cases): * its not the only one item with this object * it doesn’t have a citation that is_original * there is no indication of the original citaiton, and the item isn’t first in the list chronologically.
- #index_items ⇒ Object
-
#initialize(object, sort_order = []) ⇒ Entry
constructor
A new instance of Entry.
- #is_subsequent_entry_item?(entry_item) ⇒ Boolean
- #items_by_object(object) ⇒ Object
-
#last_item?(item) ⇒ Boolean
Returns true if * it’s the only item with this object * it’s the last citation chronologically Inversely, returns false in all other cases:.
-
#ordered_by_nomenclature_date ⇒ Array of NomenclatureCatalog::EntryItem
Sorted by date, then taxon name name as rendered for this item.
- #original_citation_present? ⇒ Boolean
- #to_json ⇒ Object
-
#topics_for_source(source) ⇒ Array of Topics
An extraction of all Topics referenced in citations that were observed in this CatalogEntry for the source TODO: SET/BUILD?.
- #year_hash ⇒ Hash
Constructor Details
#initialize(object, sort_order = []) ⇒ Entry
Returns a new instance of Entry.
37 38 39 40 41 42 43 |
# File 'lib/catalog/entry.rb', line 37 def initialize(object, sort_order = []) @object = object @items = [] @sort_order = sort_order build index_items end |
Instance Attribute Details
#dates ⇒ Array
21 22 23 |
# File 'lib/catalog/entry.rb', line 21 def dates @dates end |
#item_index ⇒ Hash
An index of all the EntryItems by global_id taken from “object”
17 18 19 |
# File 'lib/catalog/entry.rb', line 17 def item_index @item_index end |
#items ⇒ Array
Each item is a line item in the Entry
12 13 14 |
# File 'lib/catalog/entry.rb', line 12 def items @items end |
#object ⇒ Object
The target object(s) for this entry
8 9 10 |
# File 'lib/catalog/entry.rb', line 8 def object @object end |
#sort_order ⇒ Array
Returns of strings, the array determines nesting order all entries in the catalog should have ‘sorts` of the same length !! Not yet implemented !!.
35 36 37 |
# File 'lib/catalog/entry.rb', line 35 def sort_order @sort_order end |
#sources ⇒ Array
25 26 27 |
# File 'lib/catalog/entry.rb', line 25 def sources @sources end |
#topics ⇒ Scope
29 30 31 |
# File 'lib/catalog/entry.rb', line 29 def topics @topics end |
Instance Method Details
#all_citations ⇒ Object (protected)
189 190 191 |
# File 'lib/catalog/entry.rb', line 189 def all_citations items.map(&:citation).compact end |
#all_dates ⇒ Array of Date (protected)
Some duplication here
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/catalog/entry.rb', line 195 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.uniq.sort end |
#all_sources ⇒ Array of Source (protected)
Here .source is item.source, not item.object.source, i.e. it comes from a specific citation, not one of many citations for the object.
!! Redefined in some subclasses
185 186 187 |
# File 'lib/catalog/entry.rb', line 185 def all_sources items.collect{|i| i.source}.compact end |
#all_topics ⇒ Array of Topics (protected)
209 210 211 212 213 214 215 |
# File 'lib/catalog/entry.rb', line 209 def all_topics t = [] sources.each do |s| t.push topics_for_source(s) end t.flatten.uniq.compact.sort end |
#build ⇒ Object
Redefined in subclasses! !! This is default only, it should be (re)defined in subclasses.
47 48 49 50 |
# File 'lib/catalog/entry.rb', line 47 def build @items << Catalog::EntryItem.new(object:, citation: object.origin_citation) true end |
#citations ⇒ Object
171 172 173 174 |
# File 'lib/catalog/entry.rb', line 171 def citations @citations ||= all_citations @citations end |
#coordinate_entry_items ⇒ Object
168 169 |
# File 'lib/catalog/entry.rb', line 168 def coordinate_entry_items end |
#date_range ⇒ Array
130 131 132 |
# File 'lib/catalog/entry.rb', line 130 def date_range [dates.first, dates.last].compact end |
#first_item?(item) ⇒ Boolean
Named “first` to avoid conflice with ‘citation#is_original` Returns true if
* it's the only item with this object
* the citation is_original
* there is no original citation in any item for this object, and it's the first in the list chronologically
Inversely, returns false (in all other cases):
* its not the only one item with this object
* it doesn't have a citation that is_original
* there is no indication of the original citaiton, and the item isn't first in the list chronologically
70 71 72 73 74 75 76 77 |
# File 'lib/catalog/entry.rb', line 70 def first_item?(item) o = items_by_object(item.object) return true if o.size == 1 return true if item.citation&.is_original? return true if !original_citation_present? && o.index(item) == 0 false end |
#index_items ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/catalog/entry.rb', line 52 def index_items items.each do |i| i.is_first = first_item?(i) i.is_last = last_item?(i) end true end |
#is_subsequent_entry_item?(entry_item) ⇒ Boolean
165 166 |
# File 'lib/catalog/entry.rb', line 165 def is_subsequent_entry_item?(entry_item) end |
#items_by_object(object) ⇒ Object
99 100 101 |
# File 'lib/catalog/entry.rb', line 99 def items_by_object(object) ::Catalog.chronological_item_sort( items.select{|i| i.object == object } ) end |
#last_item?(item) ⇒ Boolean
Returns true if
* it's the only item with this object
* it's the last citation chronologically
Inversely, returns false in all other cases:
84 85 86 87 88 89 90 |
# File 'lib/catalog/entry.rb', line 84 def last_item?(item) o = items_by_object(item.object) return true if o.size == 1 return true if o.last == item false end |
#ordered_by_nomenclature_date ⇒ Array of NomenclatureCatalog::EntryItem
Returns sorted by date, then taxon name name as rendered for this item.
105 106 107 |
# File 'lib/catalog/entry.rb', line 105 def ordered_by_nomenclature_date ::Catalog.chronological_item_sort(items) end |
#original_citation_present? ⇒ Boolean
92 93 94 95 96 97 |
# File 'lib/catalog/entry.rb', line 92 def original_citation_present? items.each do |i| return true if i.citation&.is_original end false end |
#to_json ⇒ Object
159 160 161 162 163 |
# File 'lib/catalog/entry.rb', line 159 def to_json return { item_count: items.count, } 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 TODO: SET/BUILD?.
114 115 116 117 118 119 120 121 |
# File 'lib/catalog/entry.rb', line 114 def topics_for_source(source) topics = [] items.each do |i| # topics += i.object.topics if i.source == source topics += i.topics if i.source == source end topics.uniq end |
#year_hash ⇒ Hash
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/catalog/entry.rb', line 147 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 |