Class: Catalog::Nomenclature::Entry
- Defined in:
- lib/catalog/nomenclature/entry.rb
Instance Attribute Summary collapse
- #all_protonyms ⇒ Array protected
-
#citations_with_names ⇒ Hash
This is a very object heavy summary.
-
#relationship_items ⇒ Array of EntryItems
protected
Only those entry items that reference a TaxonNameRelationship.
Attributes inherited from Entry
#dates, #item_index, #items, #object, #sort_order, #sources, #topics
Instance Method Summary collapse
- #all_citations ⇒ Array of Citations protected
-
#all_names ⇒ Array of TaxonName
protected
A summary of all names referenced in this entry.
-
#all_sources ⇒ Array of Sources
protected
As extracted for all EntryItems, ordered alphabetically by full citation.
- #build ⇒ Object
-
#entry_item_matches_target?(item_object, reference_object) ⇒ Boolean
This is the MM result.
-
#initialize(taxon_name) ⇒ Entry
constructor
A new instance of Entry.
- #item_names(catalog_item) ⇒ Array protected
- #names ⇒ Array
-
#ordered_by_nomenclature_date ⇒ Array of NomenclatureCatalog::EntryItem
item.base_object (Protonym or Combination) item.object (Protonym, Combination, Relationship).
Methods inherited from Entry
#all_dates, #all_topics, #citations, #coordinate_entry_items, #date_range, #first_item?, #index_items, #is_subsequent_entry_item?, #items_by_object, #last_item?, #original_citation_present?, #to_json, #topics_for_source, #year_hash
Constructor Details
#initialize(taxon_name) ⇒ Entry
Returns a new instance of Entry.
17 18 19 20 |
# File 'lib/catalog/nomenclature/entry.rb', line 17 def initialize(taxon_name) super(taxon_name) true end |
Instance Attribute Details
#all_protonyms ⇒ Array (protected)
250 251 252 |
# File 'lib/catalog/nomenclature/entry.rb', line 250 def all_protonyms @all_protonyms end |
#citations_with_names ⇒ Hash
Returns this is a very object heavy summary.
125 126 127 |
# File 'lib/catalog/nomenclature/entry.rb', line 125 def citations_with_names @citations_with_names end |
#relationship_items ⇒ Array of EntryItems (protected)
Returns only those entry items that reference a TaxonNameRelationship.
256 257 258 |
# File 'lib/catalog/nomenclature/entry.rb', line 256 def relationship_items @relationship_items end |
Instance Method Details
#all_citations ⇒ Array of Citations (protected)
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/catalog/nomenclature/entry.rb', line 225 def all_citations c = items.collect{|i| i.citation} if !object.nil? relationship_items.each do |i| c << i.object.object_taxon_name.origin_citation if i.object.subject_taxon_name != object # base_object? c << i.object.subject_taxon_name.origin_citation if i.object.object_taxon_name != object end end # TODO: Why aren't these first-class EntryItems? I think they should be. # This is here because they are cross-referenced (referenced inline) in (HTML) rendering c += ::TaxonNameClassification.where(taxon_name_id: all_protonyms.collect{|p| p.object}).all. collect{|tnc| tnc.citations} c += TaxonNameRelationship::Typification.where(object_taxon_name_id: all_protonyms.collect{|p| p.object}).all. collect{|tr| tr.citations} c += TypeMaterial.where(protonym_id: all_protonyms.collect{|p| p.object}).all. collect{|tm| tm.citations} c.flatten.compact.uniq.sort_by{|s| s.source.cached} end |
#all_names ⇒ Array of TaxonName (protected)
Returns a summary of all names referenced in this entry.
190 191 192 193 194 195 196 197 |
# File 'lib/catalog/nomenclature/entry.rb', line 190 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_sources ⇒ Array of Sources (protected)
Returns as extracted for all EntryItems, ordered alphabetically by full citation.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/catalog/nomenclature/entry.rb', line 201 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 # TODO: Why aren't these first-class EntryItems? I think they should be. # 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 |
#build ⇒ Object
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 77 78 79 80 81 82 83 |
# File 'lib/catalog/nomenclature/entry.rb', line 22 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) if !t.citations.load.any? items << Catalog::Nomenclature::EntryItem.new( object: t, base_object: t, citation: nil, nomenclature_date: t.cached_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) 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.cached_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.cached_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.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/catalog/nomenclature/entry.rb', line 89 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)
183 184 185 |
# File 'lib/catalog/nomenclature/entry.rb', line 183 def item_names(catalog_item) [object, catalog_item.base_object, catalog_item.other_name].compact.uniq end |
#names ⇒ Array
118 119 120 121 |
# File 'lib/catalog/nomenclature/entry.rb', line 118 def names @names ||= all_names @names end |
#ordered_by_nomenclature_date ⇒ Array of NomenclatureCatalog::EntryItem
item.base_object (Protonym or Combination) item.object (Protonym, Combination, Relationship)
111 112 113 114 115 |
# File 'lib/catalog/nomenclature/entry.rb', line 111 def ordered_by_nomenclature_date now = Time.now #items.sort{|a,b| [(a.nomenclature_date&.to_time || 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&.to_time || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] } items.sort_by{|a| [(a.nomenclature_date&.to_time || now), a.base_object.cached_is_valid.to_s.gsub('true', '1'), a.object_class.to_s.gsub('Combination', 'z'), a.year_suffix.to_s + 'z', a.pages.to_s + 'z', a.base_object.cached_original_combination.to_s ] } end |