Class: LabwareMetadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/labware_metadata.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ LabwareMetadata

Returns a new instance of LabwareMetadata.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/labware_metadata.rb', line 6

def initialize(params = {})
  @api = params.fetch(:api, nil)
  @user = params.fetch(:user, nil)
  @barcode = params.fetch(:barcode, nil)
  if barcode.present?
    @labware = find_labware(barcode, api)
  else
    @labware = params.fetch(:labware, nil)
    raise ArgumentError, 'Parameters labware or barcode missing' if labware.nil?
  end
  raise ArgumentError, 'Parameter api missing' if api.nil?
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



4
5
6
# File 'app/models/labware_metadata.rb', line 4

def api
  @api
end

#barcodeObject

Returns the value of attribute barcode.



4
5
6
# File 'app/models/labware_metadata.rb', line 4

def barcode
  @barcode
end

#labwareObject

Returns the value of attribute labware.



4
5
6
# File 'app/models/labware_metadata.rb', line 4

def labware
  @labware
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'app/models/labware_metadata.rb', line 4

def user
  @user
end

Instance Method Details

#metadataObject



28
29
30
31
32
# File 'app/models/labware_metadata.rb', line 28

def 
  @labware.custom_metadatum_collection.
rescue URI::InvalidURIError
  nil
end

#update!(metadata) ⇒ Object

rubocop:todo Metrics/AbcSize



19
20
21
22
23
24
25
26
# File 'app/models/labware_metadata.rb', line 19

def update!() # rubocop:todo Metrics/AbcSize
  if labware.custom_metadatum_collection.uuid.present?
     = labware.custom_metadatum_collection..symbolize_keys
    labware.custom_metadatum_collection.update!(metadata: .merge(.symbolize_keys))
  else
    api.custom_metadatum_collection.create!(user: user, asset: labware.uuid, metadata: .symbolize_keys)
  end
end