Module: Material

Defined in:
lib/material.rb

Overview

Methods for handling the “bulk” accession of collection objects

Defined Under Namespace

Classes: QuickVerbatimResponse

Class Method Summary collapse

Class Method Details

.create_quick_verbatim(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/material.rb', line 4

def self.create_quick_verbatim(options  = {}) 
  # We could refactor this to use nested attributes, but it's not that much cleaner 
  opts = {
    collection_objects: {},
    note: nil,
    biocuration_classes: [],
  }.merge!(options) 

  response = QuickVerbatimResponse.new

  stub_object = CollectionObject::BiologicalCollectionObject.new(opts[:collection_object])
  container = Container::Virtual.new if stub_object.container.blank?
  note = Note.new(opts[:note]) if opts[:note]

  i = 1
  opts[:collection_objects].keys.each do |o|

    object = stub_object.dup
    object.total = opts[:collection_objects][o][:total]

    if opts[:collection_objects][o][:biocuration_classes] 
      object.biocuration_classes << BiocurationClass.find(opts[:collection_objects][o][:biocuration_classes]) 
    end

    object.notes << note.dup if note
    object.container = container if container
    response.collection_objects.push object
    object = nil
  end

  response 
end