Class: Catalog::Distribution::Entry
- Defined in:
- lib/catalog/distribution/entry.rb
Overview
A Catalog::Entry has many entry items. Together CatalogEntrys form a Catalog
Instance Attribute Summary
Attributes inherited from Entry
#dates, #item_index, #items, #object, #sort_order, #sources, #topics
Instance Method Summary collapse
- #asserted_distribution_items ⇒ Object
- #build ⇒ Object
-
#countries ⇒ Object
Array may contain nil.
- #data ⇒ Object
- #entry_item_matches_target?(item_object, reference_object) ⇒ Boolean
- #from_self ⇒ Object
-
#initialize(otus = []) ⇒ Object
constructor
Array of OTUs.
-
#paper_catalog_sources ⇒ Object
#sources is origin sources for TypeMaterial and CollectionObject Otherwise we report all sources.
- #raw_data ⇒ Object
- #to_html_method ⇒ Object
-
#to_s ⇒ Object
String.
-
#to_s_verbose ⇒ Object
Includes County records.
Methods inherited from Entry
#all_citations, #all_dates, #all_sources, #all_topics, #citations, #coordinate_entry_items, #date_range, #first_item?, #index_items, #is_subsequent_entry_item?, #items_by_object, #last_item?, #ordered_by_nomenclature_date, #original_citation_present?, #to_json, #topics_for_source, #year_hash
Constructor Details
#initialize(otus = []) ⇒ Object
Returns Array of OTUs.
8 9 10 11 |
# File 'lib/catalog/distribution/entry.rb', line 8 def initialize(otus = []) super(otus) # object set to otus! true end |
Instance Method Details
#asserted_distribution_items ⇒ Object
43 44 45 |
# File 'lib/catalog/distribution/entry.rb', line 43 def asserted_distribution_items items.select{|i| i.object.class.name == 'AssertedDistribution'} end |
#build ⇒ Object
13 14 15 16 |
# File 'lib/catalog/distribution/entry.rb', line 13 def build from_self true end |
#countries ⇒ Object
Returns Array may contain nil.
60 61 62 |
# File 'lib/catalog/distribution/entry.rb', line 60 def countries c = items.map(&:country).uniq.sort end |
#data ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/catalog/distribution/entry.rb', line 68 def data r = raw_data d = {} # country => [state => [county]] items.each do |i| c = i.country s = i.state y = i.county if !d.dig(c) d[c] = {} end if !d.dig(c,s) d[c][s] = {} end if !d.dig(c,s,y) d[c][s][y] = nil end end d end |
#entry_item_matches_target?(item_object, reference_object) ⇒ Boolean
54 55 56 |
# File 'lib/catalog/distribution/entry.rb', line 54 def entry_item_matches_target?(item_object, reference_object) item_object.id == reference_object.id end |
#from_self ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/catalog/distribution/entry.rb', line 22 def from_self # scoping should be done outside this function ! # a = ::Otu.descendant_of_taxon_name(otu.taxon_name_id).load # coordinate_otus(otu.id).load a = object # an Array of Otus, predetermined at this point current_collection_objects = CollectionObject.joins(:taxon_determinations).where(taxon_determinations: {position: 1, otu: a}) asserted_distributions = AssertedDistribution.where(otu: a) type_materials = TypeMaterial.joins(protonym: [:otus]).where('otus.id' => a) [current_collection_objects, asserted_distributions, type_materials].flatten.each do |c| @items << Catalog::Distribution::EntryItem.new( object: c, # base_object: otu, citation: c.origin_citation, nomenclature_date: c.source&.cached_nomenclature_date, # current_target: entry_item_matches_target?(o, otu) ) end end |
#paper_catalog_sources ⇒ Object
#sources is origin sources for TypeMaterial and CollectionObject Otherwise we report all sources. See asserted_distribution/dwc_extensions.rb #dwc_associated_references if this is modified.
49 50 51 |
# File 'lib/catalog/distribution/entry.rb', line 49 def paper_catalog_sources (sources + asserted_distribution_items.collect{|a| a.object.sources }.flatten).uniq end |
#raw_data ⇒ Object
64 65 66 |
# File 'lib/catalog/distribution/entry.rb', line 64 def raw_data items.collect{|a| a.geographic_name_classification}.uniq end |
#to_html_method ⇒ Object
18 19 20 |
# File 'lib/catalog/distribution/entry.rb', line 18 def to_html_method # :otu_catalog_entry_item_to_html end |
#to_s ⇒ Object
Returns String.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/catalog/distribution/entry.rb', line 135 def to_s d = data str = '' d.keys.sort{|a,b| (a || 'zzz') <=> (b || 'zzz')}.each do |c| str << ', ' unless str.size == 0 str << (c.nil? ? 'UNPARSED' : c.to_s) z = d[c].keys.compact.sort if z.size > 0 str << ' (' + z.join(', ') + ')' end end str << '.' str.gsub!(/,\sUNPARSED\.$/, '.') return '' if str == '.' str end |
#to_s_verbose ⇒ Object
Includes County records
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/catalog/distribution/entry.rb', line 96 def to_s_verbose d = data str = '' d.keys.sort{|a,b| (a || 'zzz') <=> (b || 'zzz')}.each do |c| str << ', ' unless str.size == 0 str << (c.nil? ? 'UNPARSED' : c.to_s) states = [] semi = false d[c].keys.sort{|a,b| (a || 'zzz') <=> (b || 'zzz')}.each do |s| next if s.nil? && d[c][s] == {nil => nil} s1 = s.to_s.dup s1 = 'STATE' if s1 == '' z = d[c][s].keys.compact.sort if z.size > 0 s1 << ': ' + z.join(', ') semi = true end states.push s1 end if states.any? str << ' (' + states.join( semi ? '; ' : ', ') + ')' end end str << '.' str.gsub!(/,\sUNPARSED\.$/, '.') return '' if str == '.' str end |