Module: Export::Helpers::MaterialExamined

Defined in:
lib/export/helpers/material_examined.rb

Class Method Summary collapse

Class Method Details

.build_augmentations(scope) ⇒ Object (private)



48
49
50
51
52
53
54
55
56
57
# File 'lib/export/helpers/material_examined.rb', line 48

private_class_method def self.build_augmentations(scope)
  scope.each_with_object({}) do |dwc, hash|
    occ_id = dwc.occurrenceID
    next if occ_id.blank?
    hash[occ_id] = {
      label:     dwc.catalogNumber.presence,
      edit_link: edit_link_for(dwc)
    }
  end
end


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/export/helpers/material_examined.rb', line 59

private_class_method def self.edit_link_for(dwc)
  id = dwc.dwc_occurrence_object_id
  case dwc.dwc_occurrence_object_type
  when 'CollectionObject'
    "/tasks/accessions/comprehensive?collection_object_id=#{id}"
  when 'FieldOccurrence'
    "/tasks/field_occurrences/browse?field_occurrence_id=#{id}"
  when 'AssertedDistribution'
    "/tasks/asserted_distributions/new_asserted_distribution?asserted_distribution_id=#{id}"
  end
end

.render_for_otu(otu, dwc_scope: nil, order: ::Utilities::MaterialExamined::DEFAULT_ORDER, augmentations: {}) ⇒ Object

Convenience wrapper that returns rendered Markdown directly.



44
45
46
# File 'lib/export/helpers/material_examined.rb', line 44

def self.render_for_otu(otu, dwc_scope: nil, order: ::Utilities::MaterialExamined::DEFAULT_ORDER, augmentations: {})
  renderer_for_otu(otu, dwc_scope:, order:, augmentations:, todo: false).render
end

.renderer_for_otu(otu, dwc_scope: nil, order: ::Utilities::MaterialExamined::DEFAULT_ORDER, augmentations: {}, todo: false) ⇒ Utilities::MaterialExamined

Parameters:

  • otu (Otu)
  • dwc_scope (ActiveRecord::Relation, nil) (defaults to: nil)

    Optional pre-filtered DwcOccurrence scope. When nil, defaults to all occurrences for the OTU including synonymy.

  • order (Array<Symbol>) (defaults to: ::Utilities::MaterialExamined::DEFAULT_ORDER)

    Nesting order forwarded to Utilities::MaterialExamined.

  • augmentations (Hash) (defaults to: {})

    Occurrence-level additions keyed by occurrenceID. When todo: true the wrapper merges edit_link values built from each DwcOccurrence record; callers may pass additional augmentation data (e.g. :label) which is preserved.

  • todo (Boolean) (defaults to: false)

    When true, blank active-field values render as "[TODO]" and todo_occurrence_ids is populated on the returned renderer.

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/export/helpers/material_examined.rb', line 28

def self.renderer_for_otu(otu, dwc_scope: nil, order: ::Utilities::MaterialExamined::DEFAULT_ORDER, augmentations: {}, todo: false)
  scope       = dwc_scope || ::DwcOccurrence.scoped_by_otu(otu)
  occurrences = scope.map(&:dwc_json)
  return ::Utilities::MaterialExamined.new([], order:, augmentations:, todo:) if occurrences.empty?

  merged_augmentations = build_augmentations(scope).merge(augmentations)

  ::Utilities::MaterialExamined.new(
    occurrences,
    order:,
    augmentations: merged_augmentations,
    todo:
  )
end