Class: Catalog::Nomenclature::Entry
- Defined in:
- lib/catalog/nomenclature/entry.rb
Instance Attribute Summary
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_protonyms ⇒ Array protected
-
#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
Sorted by date, then taxon name name as rendered for this item.
-
#relationship_items ⇒ Array of EntryItems
protected
Only those entry items that reference a TaxonNameRelationship.
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.
13 14 15 16 |
# File 'lib/catalog/nomenclature/entry.rb', line 13 def initialize(taxon_name) super(taxon_name) true end |
Instance Method Details
#all_citations ⇒ Array of Citations (protected)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/catalog/nomenclature/entry.rb', line 165 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 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{|tnc| tnc.citations} c += TypeMaterial.where(protonym_id: all_protonyms.collect{|p| p.object}).all. collect{|tnc| tnc.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.
130 131 132 133 134 135 136 137 |
# File 'lib/catalog/nomenclature/entry.rb', line 130 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_protonyms ⇒ Array (protected)
191 192 193 |
# File 'lib/catalog/nomenclature/entry.rb', line 191 def all_protonyms items.select{|i| i.origin == 'protonym' } end |
#all_sources ⇒ Array of Sources (protected)
Returns as extracted for all EntryItems, ordered alphabetically by full citation.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/catalog/nomenclature/entry.rb', line 141 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
18 19 20 21 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 |
# File 'lib/catalog/nomenclature/entry.rb', line 18 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.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.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.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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/catalog/nomenclature/entry.rb', line 88 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)
123 124 125 |
# File 'lib/catalog/nomenclature/entry.rb', line 123 def item_names(catalog_item) [object, catalog_item.base_object, catalog_item.other_name].compact.uniq end |
#names ⇒ Array
114 115 116 117 |
# File 'lib/catalog/nomenclature/entry.rb', line 114 def names @names ||= all_names @names end |
#ordered_by_nomenclature_date ⇒ Array of NomenclatureCatalog::EntryItem
Returns sorted by date, then taxon name name as rendered for this item.
108 109 110 111 |
# File 'lib/catalog/nomenclature/entry.rb', line 108 def ordered_by_nomenclature_date now = Time.now items.sort{|a,b| [(a.nomenclature_date || 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 || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] } end |
#relationship_items ⇒ Array of EntryItems (protected)
Returns only those entry items that reference a TaxonNameRelationship.
197 198 199 |
# File 'lib/catalog/nomenclature/entry.rb', line 197 def relationship_items items.select{|i| i.object_class =~ /TaxonNameRelationship/} end |