Class: Barcode::FormatHandlers::BaseRegExBarcode
- Inherits:
-
Object
- Object
- Barcode::FormatHandlers::BaseRegExBarcode
show all
- Includes:
- Ean13Incompatible
- Defined in:
- app/models/barcode/format_handlers.rb
Overview
A basic class for barodes that can be validated and decomposed by simple regular expressions Classes that inherit from this should define a regular expression with optional names matchers for prefix, number and suffix. This regex should be assigned to self.format
Direct Known Subclasses
AkerBarcode, AlderleyParkEagle, AlderlyParkV1, AlderlyParkV2, BrantsBridge, BrantsBridgeV2, BrantsBridgeV3, CambridgeAZ, CambridgeAZEagle, CambridgeAZV2, Cgap, CgapPlate, CgapRack, Eagle, EastLondonGenesAndHealth, EastLondonGenesAndHealthV2, External, Fluidigm, FluidxBarcode, Glasgow, GlasgowEagle, GlasgowV2, GlasgowV3, HealthServicesLaboratoriesV1, HeronTailed, IbdResponse, Infinium, LeamingtonSpa, LeamingtonSpaV2, LeamingtonSpaV3, Newcastle, PlymouthV1, PlymouthV2, Randox, RandoxEagle, RandoxV2, Rvi, Sequencescape22, UkBiocentreEagle, UkBiocentreUnid, UkBiocentreV1, UkBiocentreV2, UkBiocentreV3, UkBiocentreV4, UkBiocentreV5, UkBiocentreV6, UkBiocentreV7
Instance Attribute Summary collapse
-
#human_barcode ⇒ Object
(also: #machine_barcode, #serialize_barcode)
readonly
Returns the value of attribute human_barcode.
Instance Method Summary
collapse
#ean13_barcode, #ean13_barcode?
Constructor Details
Returns a new instance of BaseRegExBarcode.
109
110
111
112
|
# File 'app/models/barcode/format_handlers.rb', line 109
def initialize(barcode)
@human_barcode = barcode
@matches = format.match(@human_barcode)
end
|
Instance Attribute Details
#human_barcode ⇒ Object
Also known as:
machine_barcode, serialize_barcode
Returns the value of attribute human_barcode.
105
106
107
|
# File 'app/models/barcode/format_handlers.rb', line 105
def human_barcode
@human_barcode
end
|
Instance Method Details
#=~(other) ⇒ Object
150
151
152
|
# File 'app/models/barcode/format_handlers.rb', line 150
def =~(other)
human_barcode == other
end
|
#barcode_prefix ⇒ Object
114
115
116
|
# File 'app/models/barcode/format_handlers.rb', line 114
def barcode_prefix
@matches[:prefix] if @matches&.names&.include?('prefix')
end
|
#child ⇒ Object
126
127
128
|
# File 'app/models/barcode/format_handlers.rb', line 126
def child
@matches[:child].to_i if @matches&.names&.include?('child') && !@matches[:child].nil?
end
|
#code128_barcode ⇒ Object
142
143
144
|
# File 'app/models/barcode/format_handlers.rb', line 142
def code128_barcode
human_barcode if code128_barcode?
end
|
#code128_barcode? ⇒ Boolean
130
131
132
|
# File 'app/models/barcode/format_handlers.rb', line 130
def code128_barcode?
/\A[[:ascii:]]+\z/.match?(@human_barcode)
end
|
#code39_barcode ⇒ Object
146
147
148
|
# File 'app/models/barcode/format_handlers.rb', line 146
def code39_barcode
human_barcode if code39_barcode?
end
|
#code39_barcode? ⇒ Boolean
134
135
136
|
# File 'app/models/barcode/format_handlers.rb', line 134
def code39_barcode?
%r{\A[A-Z0-9 \-.$/+%]+\z}.match?(@human_barcode)
end
|
#number ⇒ Object
118
119
120
|
# File 'app/models/barcode/format_handlers.rb', line 118
def number
@matches[:number].to_i if @matches&.names&.include?('number')
end
|
#suffix ⇒ Object
122
123
124
|
# File 'app/models/barcode/format_handlers.rb', line 122
def suffix
@matches[:suffix] if @matches&.names&.include?('suffix')
end
|
#valid? ⇒ Boolean
138
139
140
|
# File 'app/models/barcode/format_handlers.rb', line 138
def valid?
format.match? @human_barcode
end
|