Class: Barcode1DTools::Barcode1D
- Inherits:
-
Object
- Object
- Barcode1DTools::Barcode1D
- Defined in:
- lib/barcode1dtools.rb
Overview
Base class for all barcode classes.
Direct Known Subclasses
Codabar, Code11, Code128, Code3of9, Code93, Coop2of5, EAN13, EAN8, IATA2of5, Industrial2of5, Interleaved2of5, MSI, Matrix2of5, Plessey, PostNet, UPC_E, UPC_Supplemental_2, UPC_Supplemental_5
Instance Attribute Summary collapse
-
#check_digit ⇒ Object
readonly
The check digit(s), if any - may be nil.
-
#encoded_string ⇒ Object
readonly
The actual string that is encoded, including check digits.
-
#options ⇒ Object
readonly
Options, including defaults and those explicitly set.
-
#value ⇒ Object
readonly
The value that is encoded.
Class Method Summary collapse
-
.bar_pair(options = {}) ⇒ Object
Get a bar pair from the options.
-
.bars_to_rle(bar_str, options = {}) ⇒ Object
Generate rle pattern from bar string.
-
.rle_to_bars(rle_str, options = {}) ⇒ Object
Generate bar pattern string from rle string.
-
.rle_to_wn(rle_str, options = {}) ⇒ Object
Generate wn pattern from rle string.
-
.wn_pair(options = {}) ⇒ Object
Get an “wn” pair from the options.
-
.wn_to_rle(wn_str, options = {}) ⇒ Object
Generate rle pattern from wn string.
Instance Attribute Details
#check_digit ⇒ Object (readonly)
The check digit(s), if any - may be nil
185 186 187 |
# File 'lib/barcode1dtools.rb', line 185 def check_digit @check_digit end |
#encoded_string ⇒ Object (readonly)
The actual string that is encoded, including check digits
187 188 189 |
# File 'lib/barcode1dtools.rb', line 187 def encoded_string @encoded_string end |
#options ⇒ Object (readonly)
Options, including defaults and those explicitly set
189 190 191 |
# File 'lib/barcode1dtools.rb', line 189 def @options end |
#value ⇒ Object (readonly)
The value that is encoded
183 184 185 |
# File 'lib/barcode1dtools.rb', line 183 def value @value end |
Class Method Details
.bar_pair(options = {}) ⇒ Object
Get a bar pair from the options
220 221 222 |
# File 'lib/barcode1dtools.rb', line 220 def ( = {}) ([:space_character] || '0').to_s + ([:line_character] || '1').to_s end |
.bars_to_rle(bar_str, options = {}) ⇒ Object
Generate rle pattern from bar string
200 201 202 |
# File 'lib/barcode1dtools.rb', line 200 def (, = {}) .scan(/(.)(\1*)/).collect { |char,rest| 1+rest.length }.join end |
.rle_to_bars(rle_str, options = {}) ⇒ Object
Generate bar pattern string from rle string
194 195 196 197 |
# File 'lib/barcode1dtools.rb', line 194 def (rle_str, = {}) str=0 rle_str.split('').inject('') { |a,c| str = 1 - str; a + (str.to_s * c.to_i) }.tr('01', ()) end |
.rle_to_wn(rle_str, options = {}) ⇒ Object
Generate wn pattern from rle string
210 211 212 |
# File 'lib/barcode1dtools.rb', line 210 def rle_to_wn(rle_str, = {}) rle_str.tr('123456789', 'nwwwwwwww').tr('wn', wn_pair()) end |
.wn_pair(options = {}) ⇒ Object
Get an “wn” pair from the options
215 216 217 |
# File 'lib/barcode1dtools.rb', line 215 def wn_pair( = {}) ([:w_character] || 'w') + ([:n_character] || 'n') end |
.wn_to_rle(wn_str, options = {}) ⇒ Object
Generate rle pattern from wn string
205 206 207 |
# File 'lib/barcode1dtools.rb', line 205 def wn_to_rle(wn_str, = {}) wn_str.tr(wn_pair(), ([:wn_ratio] || 2).to_s + '1') end |