Class: AssetBarcode

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

Overview

This class only a concurrency safe counter to generate asset barcode Used for tubes

Class 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

Class Method Details

.new_barcode(prefix = Tube.default_prefix) ⇒ String

Note:

The returned string does NOT include the prefix.

Generate a new Sanger barcode, namespaced with the given prefix

Examples:

Generating a new barcode

AssetBarcode.new_barcode #=> '12345'

Parameters:

  • prefix (String) (defaults to: Tube.default_prefix)

    The two letter prefix at the beginning of the barcode (default Tube.default_prefix, NT)

Returns:

  • (String)

    The number component of the new barcode in string format.


14
15
16
17
18
19
20
# File 'app/models/asset_barcode.rb', line 14

def self.new_barcode(prefix = Tube.default_prefix)
  barcode = (AssetBarcode.create!).id

  barcode = (AssetBarcode.create!).id while Barcode.find_by(barcode: SBCF::SangerBarcode.from_prefix_and_number(prefix, barcode).human_barcode)

  barcode.to_s
end