Module: Barcode::Barcodeable
Overview
Anything that has a barcode is considered barcodeable.
Class Method Summary collapse
Instance Method Summary collapse
-
#any_barcode_matching?(other_barcode) ⇒ Boolean
***** Read-only utility methods *****.
- #barcode_format ⇒ Object
- #barcode_number ⇒ Object
- #cgap_barcode ⇒ Object
- #cgap_barcode=(barcode) ⇒ Object
- #external_barcode ⇒ Object
- #external_barcode=(barcode) ⇒ Object
- #external_identifier ⇒ Object
- #fluidigm_barcode ⇒ Object
- #fluidigm_barcode=(barcode) ⇒ Object
-
#foreign_barcode=(barcode) ⇒ Object
Detects the format of the foreign barcode string passed in Adds it to the list of barcodes, making it the primary (most recent) barcode Throws exceptions if there are validation issues.
-
#generate_barcode ⇒ Object
Assumes presence of a method called
sanger_barcode=
on the class this is included within. -
#infinium_barcode ⇒ Object
***** Getter and setter methods for foreign barcodes *****.
- #infinium_barcode=(barcode) ⇒ Object
- #prefix ⇒ Object
- #primary_barcode ⇒ Object
- #printable_target ⇒ Object
- #sanger_barcode ⇒ Object
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
#any_barcode_matching?(other_barcode) ⇒ Boolean
***** Read-only utility methods *****
20 21 22 |
# File 'app/models/barcode/barcodeable.rb', line 20 def () .any? { || =~ } end |
#barcode_format ⇒ Object
28 29 30 |
# File 'app/models/barcode/barcodeable.rb', line 28 def .format end |
#barcode_number ⇒ Object
24 25 26 |
# File 'app/models/barcode/barcodeable.rb', line 24 def &.number&.to_s end |
#cgap_barcode ⇒ Object
73 74 75 |
# File 'app/models/barcode/barcodeable.rb', line 73 def .detect(&:cgap?)&. end |
#cgap_barcode=(barcode) ⇒ Object
77 78 79 |
# File 'app/models/barcode/barcodeable.rb', line 77 def () .cgap.first_or_initialize. = end |
#external_barcode ⇒ Object
81 82 83 |
# File 'app/models/barcode/barcodeable.rb', line 81 def .detect(&:external?)&. end |
#external_barcode=(barcode) ⇒ Object
85 86 87 |
# File 'app/models/barcode/barcodeable.rb', line 85 def () .external.first_or_initialize. = end |
#external_identifier ⇒ Object
36 37 38 |
# File 'app/models/barcode/barcodeable.rb', line 36 def external_identifier end |
#fluidigm_barcode ⇒ Object
65 66 67 |
# File 'app/models/barcode/barcodeable.rb', line 65 def .detect(&:fluidigm?)&. end |
#fluidigm_barcode=(barcode) ⇒ Object
69 70 71 |
# File 'app/models/barcode/barcodeable.rb', line 69 def () .fluidigm.first_or_initialize. = end |
#foreign_barcode=(barcode) ⇒ Object
Detects the format of the foreign barcode string passed in Adds it to the list of barcodes, making it the primary (most recent) barcode Throws exceptions if there are validation issues
92 93 94 95 96 97 98 99 100 |
# File 'app/models/barcode/barcodeable.rb', line 92 def () = Barcode.() raise "Cannot determine format for foreign barcode #{}" if .blank? raise "Foreign Barcode: #{} is already in use!" if Barcode.exists_for_format?(, ) << Barcode.new(format: , barcode: ) end |
#generate_barcode ⇒ Object
Assumes presence of a method called sanger_barcode=
on the class this is included within. It’s not implemented on TubeRack!
15 16 17 |
# File 'app/models/barcode/barcodeable.rb', line 15 def self. = { prefix: default_prefix, number: AssetBarcode. } unless end |
#infinium_barcode ⇒ Object
***** Getter and setter methods for foreign barcodes *****
57 58 59 |
# File 'app/models/barcode/barcodeable.rb', line 57 def .detect(&:infinium?)&. end |
#infinium_barcode=(barcode) ⇒ Object
61 62 63 |
# File 'app/models/barcode/barcodeable.rb', line 61 def () .infinium.first_or_initialize. = end |
#prefix ⇒ Object
32 33 34 |
# File 'app/models/barcode/barcodeable.rb', line 32 def prefix &. end |
#primary_barcode ⇒ Object
48 49 50 51 52 |
# File 'app/models/barcode/barcodeable.rb', line 48 def # If we've already loaded the barcodes, then their order is indeterminate # rather than re-fetching them, we sort in Ruby. .loaded? ? .max_by(&:id) : .last end |
#printable_target ⇒ Object
40 41 42 |
# File 'app/models/barcode/barcodeable.rb', line 40 def printable_target self end |
#sanger_barcode ⇒ Object
44 45 46 |
# File 'app/models/barcode/barcodeable.rb', line 44 def .detect(&:sanger_barcode?) end |