Class: Catalog::Distribution::Entry
- Inherits:
-
Entry
- Object
- Entry
- Catalog::Distribution::Entry
- Defined in:
- lib/catalog/distribution/entry.rb
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
-
#to_s_verbose ⇒ Object
Includes County records.
Constructor Details
#initialize(otus = []) ⇒ Object
Returns Array of OTUs.
11 12 13 14 |
# File 'lib/catalog/distribution/entry.rb', line 11 def initialize(otus = []) super(otus) # object set to otus! true end |
Instance Method Details
#asserted_distribution_items ⇒ Object
46 47 48 |
# File 'lib/catalog/distribution/entry.rb', line 46 def asserted_distribution_items items.select{|i| i.object.class.name == 'AssertedDistribution'} end |
#build ⇒ Object
16 17 18 19 |
# File 'lib/catalog/distribution/entry.rb', line 16 def build from_self true end |
#countries ⇒ Object
Returns Array may contain nil.
63 64 65 |
# File 'lib/catalog/distribution/entry.rb', line 63 def countries c = items.map(&:country).uniq.sort end |
#data ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/catalog/distribution/entry.rb', line 71 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
57 58 59 |
# File 'lib/catalog/distribution/entry.rb', line 57 def entry_item_matches_target?(item_object, reference_object) item_object.id == reference_object.id end |
#from_self ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/catalog/distribution/entry.rb', line 25 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.
52 53 54 |
# File 'lib/catalog/distribution/entry.rb', line 52 def paper_catalog_sources (sources + asserted_distribution_items.collect{|a| a.object.sources }.flatten).uniq end |
#raw_data ⇒ Object
67 68 69 |
# File 'lib/catalog/distribution/entry.rb', line 67 def raw_data items.collect{|a| a.geographic_name_classification}.uniq end |
#to_html_method ⇒ Object
21 22 23 |
# File 'lib/catalog/distribution/entry.rb', line 21 def to_html_method # :otu_catalog_entry_item_to_html end |
#to_s ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/catalog/distribution/entry.rb', line 136 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 nil if str == '.' str end |
#to_s_verbose ⇒ Object
Includes County records
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 133 134 |
# File 'lib/catalog/distribution/entry.rb', line 98 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 nil if str == '.' str end |