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
12
13
14
# 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

    # has_one :barcodes, -> { order(id: :desc) }, foreign_key: :asset_id, inverse_of: :asset, dependent: :destroy, class_name: 'Barcode'

    delegate :ean13_barcode, :machine_barcode, :human_barcode, to: :primary_barcode, allow_nil: true
  end
end

Instance Method Details

#aker_barcodeObject


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

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

#aker_barcode=(barcode) ⇒ Object


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

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

#any_barcode_matching?(other_barcode) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#barcode_formatObject


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

def barcode_format
  primary_barcode.format
end

#barcode_numberObject


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

def barcode_number
  primary_barcode&.number&.to_s
end

#cgap_barcodeObject


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

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

#cgap_barcode=(barcode) ⇒ Object


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

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

#external_barcodeObject


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

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

#external_barcode=(barcode) ⇒ Object


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

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

#external_identifierObject


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

def external_identifier
  human_barcode
end

#fluidigm_barcodeObject


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

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

#fluidigm_barcode=(barcode) ⇒ Object


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

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

#generate_barcodeObject


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

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

#infinium_barcodeObject


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

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

#infinium_barcode=(barcode) ⇒ Object


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

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

#prefixObject


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

def prefix
  primary_barcode&.barcode_prefix
end

#primary_barcodeObject


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

def primary_barcode
  barcodes.last
end

#printable_targetObject


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

def printable_target
  self
end

#sanger_barcodeObject


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

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