Module: Barcode::Barcodeable

Included in:
Plate, Tube
Defined in:
app/models/barcode/barcodeable.rb

Overview

Anything that has a barcode is considered barcodeable.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


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

def self.included(base)
  base.class_eval do
    # Default prefix is the fallback prefix if no purpose is available.
    class_attribute :default_prefix
    delegate :ean13_barcode, :machine_barcode, :human_barcode, to: :primary_barcode, allow_nil: true
  end
end

Instance Method Details

#aker_barcodeObject


81
82
83
# File 'app/models/barcode/barcodeable.rb', line 81

def aker_barcode
  barcodes.detect(&:aker_barcode?)&.machine_barcode
end

#aker_barcode=(barcode) ⇒ Object


85
86
87
# File 'app/models/barcode/barcodeable.rb', line 85

def aker_barcode=(barcode)
  barcodes.aker_barcode.first_or_initialize.barcode = barcode
end

#any_barcode_matching?(other_barcode) ⇒ Boolean

Returns:

  • (Boolean)

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

def any_barcode_matching?(other_barcode)
  barcodes.any? { |barcode| barcode =~ other_barcode }
end

#barcode_formatObject


25
26
27
# File 'app/models/barcode/barcodeable.rb', line 25

def barcode_format
  primary_barcode.format
end

#barcode_numberObject


21
22
23
# File 'app/models/barcode/barcodeable.rb', line 21

def barcode_number
  primary_barcode&.number&.to_s
end

#cgap_barcodeObject


65
66
67
# File 'app/models/barcode/barcodeable.rb', line 65

def cgap_barcode
  barcodes.detect(&:cgap?)&.machine_barcode
end

#cgap_barcode=(barcode) ⇒ Object


69
70
71
# File 'app/models/barcode/barcodeable.rb', line 69

def cgap_barcode=(barcode)
  barcodes.cgap.first_or_initialize.barcode = barcode
end

#external_barcodeObject


73
74
75
# File 'app/models/barcode/barcodeable.rb', line 73

def external_barcode
  barcodes.detect(&:external?)&.machine_barcode
end

#external_barcode=(barcode) ⇒ Object


77
78
79
# File 'app/models/barcode/barcodeable.rb', line 77

def external_barcode=(barcode)
  barcodes.external.first_or_initialize.barcode = barcode
end

#external_identifierObject


33
34
35
# File 'app/models/barcode/barcodeable.rb', line 33

def external_identifier
  human_barcode
end

#fluidigm_barcodeObject


57
58
59
# File 'app/models/barcode/barcodeable.rb', line 57

def fluidigm_barcode
  barcodes.detect(&:fluidigm?)&.machine_barcode
end

#fluidigm_barcode=(barcode) ⇒ Object


61
62
63
# File 'app/models/barcode/barcodeable.rb', line 61

def fluidigm_barcode=(barcode)
  barcodes.fluidigm.first_or_initialize.barcode = barcode
end

#generate_barcodeObject


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

def generate_barcode
  self.sanger_barcode = { prefix: default_prefix, number: AssetBarcode.new_barcode } unless primary_barcode
end

#infinium_barcodeObject


49
50
51
# File 'app/models/barcode/barcodeable.rb', line 49

def infinium_barcode
  barcodes.detect(&:infinium?)&.machine_barcode
end

#infinium_barcode=(barcode) ⇒ Object


53
54
55
# File 'app/models/barcode/barcodeable.rb', line 53

def infinium_barcode=(barcode)
  barcodes.infinium.first_or_initialize.barcode = barcode
end

#prefixObject


29
30
31
# File 'app/models/barcode/barcodeable.rb', line 29

def prefix
  primary_barcode&.barcode_prefix
end

#primary_barcodeObject


45
46
47
# File 'app/models/barcode/barcodeable.rb', line 45

def primary_barcode
  barcodes.last
end

#printable_targetObject


37
38
39
# File 'app/models/barcode/barcodeable.rb', line 37

def printable_target
  self
end

#sanger_barcodeObject


41
42
43
# File 'app/models/barcode/barcodeable.rb', line 41

def sanger_barcode
  barcodes.detect(&:sanger_barcode?)
end