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.
108
109
110
111
|
# File 'app/models/barcode/format_handlers.rb', line 108
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.
104
105
106
|
# File 'app/models/barcode/format_handlers.rb', line 104
def human_barcode
@human_barcode
end
|
Instance Method Details
#=~(other) ⇒ Object
149
150
151
|
# File 'app/models/barcode/format_handlers.rb', line 149
def =~(other)
human_barcode == other
end
|
#barcode_prefix ⇒ Object
113
114
115
|
# File 'app/models/barcode/format_handlers.rb', line 113
def barcode_prefix
@matches[:prefix] if @matches&.names&.include?('prefix')
end
|
#child ⇒ Object
125
126
127
|
# File 'app/models/barcode/format_handlers.rb', line 125
def child
@matches[:child].to_i if @matches&.names&.include?('child') && !@matches[:child].nil?
end
|
#code128_barcode ⇒ Object
141
142
143
|
# File 'app/models/barcode/format_handlers.rb', line 141
def code128_barcode
human_barcode if code128_barcode?
end
|
#code128_barcode? ⇒ Boolean
129
130
131
|
# File 'app/models/barcode/format_handlers.rb', line 129
def code128_barcode?
/\A[[:ascii:]]+\z/.match?(@human_barcode)
end
|
#code39_barcode ⇒ Object
145
146
147
|
# File 'app/models/barcode/format_handlers.rb', line 145
def code39_barcode
human_barcode if code39_barcode?
end
|
#code39_barcode? ⇒ Boolean
133
134
135
|
# File 'app/models/barcode/format_handlers.rb', line 133
def code39_barcode?
%r{\A[A-Z0-9 \-.$/+%]+\z}.match?(@human_barcode)
end
|
#number ⇒ Object
117
118
119
|
# File 'app/models/barcode/format_handlers.rb', line 117
def number
@matches[:number].to_i if @matches&.names&.include?('number')
end
|
#suffix ⇒ Object
121
122
123
|
# File 'app/models/barcode/format_handlers.rb', line 121
def suffix
@matches[:suffix] if @matches&.names&.include?('suffix')
end
|
#valid? ⇒ Boolean
137
138
139
|
# File 'app/models/barcode/format_handlers.rb', line 137
def valid?
format.match? @human_barcode
end
|