Class: Catalog::Distribution::Entry

Inherits:
Entry
  • Object
show all
Defined in:
lib/catalog/distribution/entry.rb

Instance Attribute Summary

Attributes inherited from Entry

#dates, #item_index, #items, #object, #sort_order, #sources, #topics

Instance Method Summary collapse

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.

Parameters:

  • object


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_itemsObject



46
47
48
# File 'lib/catalog/distribution/entry.rb', line 46

def asserted_distribution_items
  items.select{|i| i.object.class.name == 'AssertedDistribution'}
end

#buildObject



16
17
18
19
# File 'lib/catalog/distribution/entry.rb', line 16

def build
  from_self
  true
end

#countriesObject

Returns Array may contain nil.

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

#dataObject



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

Returns:

  • (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_selfObject



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_sourcesObject

#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_dataObject



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_methodObject



21
22
23
# File 'lib/catalog/distribution/entry.rb', line 21

def to_html_method
  # :otu_catalog_entry_item_to_html
end

#to_sObject



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_verboseObject

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