Class: Catalog::Inventory

Inherits:
Catalog
  • Object
show all
Defined in:
lib/catalog/inventory.rb

Instance Attribute Summary

Attributes inherited from Catalog

#catalog_targets, #entries

Instance Method Summary collapse

Methods inherited from Catalog

all_dates, chronological_item_sort, #citations, #entries_sorted, #entry_sort_valid?, #initialize, #items, #items_chronologically, #objects_for_source, #reference_object_global_id, #reference_object_valid_taxon_name_global_id, #sources, #sources_to_json, topic_year_metadata, #topics, #topics_to_json, year_hash, year_metadata

Constructor Details

This class inherits a constructor from Catalog

Instance Method Details

#buildObject



3
4
5
6
7
8
# File 'lib/catalog/inventory.rb', line 3

def build
  catalog_targets.each do |t|
    @entries.push(Catalog::Otu::InventoryEntry.new(t))
  end
  true
end

#citations_summaryHash{ Integer => Hash }

Returns Keyed by coordinate OTU id (the base_object of each item). Each value is a hash containing the OTU and its citations, one per unique (type, source) pair for that OTU, with topics unioned across all items of that pair. { otu_id => { otu: Otu,

citations: [ { id: Integer, citation_object_type: String, source: Source,
               pages: String, is_original: Boolean,
               topics: [Topic] }, ... ] } }.

Returns:

  • (Hash{ Integer => Hash })

    Keyed by coordinate OTU id (the base_object of each item). Each value is a hash containing the OTU and its citations, one per unique (type, source) pair for that OTU, with topics unioned across all items of that pair. { otu_id => { otu: Otu,

    citations: [ { id: Integer, citation_object_type: String, source: Source,
                   pages: String, is_original: Boolean,
                   topics: [Topic] }, ... ] } }
    


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/catalog/inventory.rb', line 19

def citations_summary
  items.group_by { |item| item.base_object.id }
    .transform_values do |otu_items|
      otu = otu_items.first.base_object

      {
        otu: otu,
        citations: otu_items
          .group_by { |item| [item.object.class.name, item.citation&.source_id] }
          .map do |(type, _source_id), grouped_items|
            {
              id: grouped_items.first.citation&.id,
              type: type,
              source: grouped_items.first.citation&.source,
              pages: grouped_items.first.citation&.pages,
              is_original: grouped_items.first.citation&.is_original,
              topics: grouped_items.flat_map(&:topics).uniq
            }
          end
      }
    end
end