Module: Barcode::Barcodeable

Included in:
Plate, Tube, TubeRack
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


87
88
89
# File 'app/models/barcode/barcodeable.rb', line 87

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

#aker_barcode=(barcode) ⇒ Object


91
92
93
# File 'app/models/barcode/barcodeable.rb', line 91

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


71
72
73
# File 'app/models/barcode/barcodeable.rb', line 71

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

#cgap_barcode=(barcode) ⇒ Object


75
76
77
# File 'app/models/barcode/barcodeable.rb', line 75

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

#external_barcodeObject


79
80
81
# File 'app/models/barcode/barcodeable.rb', line 79

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

#external_barcode=(barcode) ⇒ Object


83
84
85
# File 'app/models/barcode/barcodeable.rb', line 83

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


63
64
65
# File 'app/models/barcode/barcodeable.rb', line 63

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

#fluidigm_barcode=(barcode) ⇒ Object


67
68
69
# File 'app/models/barcode/barcodeable.rb', line 67

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


55
56
57
# File 'app/models/barcode/barcodeable.rb', line 55

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

#infinium_barcode=(barcode) ⇒ Object


59
60
61
# File 'app/models/barcode/barcodeable.rb', line 59

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
48
49
50
51
52
53
# File 'app/models/barcode/barcodeable.rb', line 45

def primary_barcode
  # If we've already loaded the barcodes, then their order is indeterminate
  # rather than re-fetching them, we sort in Ruby.
  if barcodes.loaded?
    barcodes.max_by(&:id)
  else
    barcodes.last
  end
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