Class: Implement

Inherits:
ApplicationRecord show all
Defined in:
app/models/implement.rb

Constant Summary collapse

@@barcode_prefix =
'LE'

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Instance Method Details

#barcode_prefixObject


13
14
15
# File 'app/models/implement.rb', line 13

def barcode_prefix
  @@barcode_prefix
end

#generate_barcodeObject

Raises:

  • (Exception.new)

6
7
8
9
10
11
# File 'app/models/implement.rb', line 6

def generate_barcode
  raise Exception.new, "Can't generate barcode with a null ID" if id == 0

  b = Barcode.calculate_barcode(barcode_prefix, id)
  Barcode.barcode_to_human b
end

#human_barcodeObject


17
18
19
# File 'app/models/implement.rb', line 17

def human_barcode
  Barcode.barcode_to_human barcode
end

#save_and_generate_barcodeObject


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

def save_and_generate_barcode
  ActiveRecord::Base.transaction do
    save and self.barcode = generate_barcode
    save
  end
end