Module: Material
- Defined in:
- lib/material.rb
Overview
Methods for handling the “bulk” accession of collection objects
Defined Under Namespace
Classes: QuickVerbatimObject, QuickVerbatimResponse
Class Method Summary collapse
-
.create_quick_verbatim(options = {}) ⇒ QuickVerbatimResponse instance
rubocop:disable Style/StringHashKeys rubocop:disable Metrics/MethodLength.
Class Method Details
.create_quick_verbatim(options = {}) ⇒ QuickVerbatimResponse instance
rubocop:disable Style/StringHashKeys rubocop:disable Metrics/MethodLength
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/material.rb', line 9 def self.create_quick_verbatim( = {}) # We could refactor this to use nested attributes, but it's not that much cleaner opts = { 'collection_objects' => {}, 'note' => nil, 'biocuration_classes' => [], 'repository' => {'id' => nil}, 'preparation_type' => {'id' => nil}, 'collection_object' => {} }.merge() response = QuickVerbatimResponse.new(opts) objects = {} opts['collection_objects'].each_key do |k| objects.merge!(k => opts['collection_objects'][k]) if !opts['collection_objects'][k]['total'].blank? end stub_object_attributes = CollectionObject::BiologicalCollectionObject.new(opts['collection_object'].merge( 'repository_id' => opts['repository']['id'], 'preparation_type_id' => opts['preparation_type']['id'] )) if opts['identifier'] && !opts['identifier']['namespace_id'].blank? && !opts['identifier']['identifier'].blank? identifier = Identifier::Local::CatalogNumber.new( namespace_id: opts['identifier']['namespace_id'], identifier: opts['identifier']['identifier']) end container = Container::Virtual.new if objects.keys.count > 1 container.identifiers << identifier if container && identifier note = Note.new(opts['note']) if opts['note'] && !opts['note']['text'].blank? repository = Repository.find(opts['repository']['id']) if opts['repository'] && !opts['repository']['id'].blank? preparation_type = PreparationType.find(opts['preparation_type']['id']) if opts['preparation_type'] && !opts['preparation_type']['id'].blank? objects.each_key do |o| object = stub_object_attributes.dup object.total = objects[o]['total'] if objects[o]['biocuration_classes'] objects[o]['biocuration_classes'].each_key do |k| object.biocuration_classifications.build(biocuration_class: BiocurationClass.find(k)) end end object.notes << note.dup if note object.contained_in = container if container # = container if container object.identifiers << identifier if identifier && !container response.collection_objects.push(object) object = nil end # Cache the values for next use !! test response.note = note if note response.identifier = identifier if identifier response.repository = repository if repository response.preparation_type = preparation_type if preparation_type response end |