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

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

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.



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

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

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

  barcode.to_s
end