Class: Barcode1DTools::Barcode1D
- Inherits:
-
Object
- Object
- Barcode1DTools::Barcode1D
- Defined in:
- lib/barcode1dtools.rb
Direct Known Subclasses
Codabar, Code11, Code128, Code3of9, 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
Returns the value of attribute check_digit.
-
#encoded_string ⇒ Object
readonly
Returns the value of attribute encoded_string.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
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)
Returns the value of attribute check_digit.
73 74 75 |
# File 'lib/barcode1dtools.rb', line 73 def check_digit @check_digit end |
#encoded_string ⇒ Object (readonly)
Returns the value of attribute encoded_string.
75 76 77 |
# File 'lib/barcode1dtools.rb', line 75 def encoded_string @encoded_string end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
76 77 78 |
# File 'lib/barcode1dtools.rb', line 76 def @options end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
74 75 76 |
# File 'lib/barcode1dtools.rb', line 74 def value @value end |
Class Method Details
.bar_pair(options = {}) ⇒ Object
Get a bar pair from the options
107 108 109 |
# File 'lib/barcode1dtools.rb', line 107 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
87 88 89 |
# File 'lib/barcode1dtools.rb', line 87 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
81 82 83 84 |
# File 'lib/barcode1dtools.rb', line 81 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
97 98 99 |
# File 'lib/barcode1dtools.rb', line 97 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
102 103 104 |
# File 'lib/barcode1dtools.rb', line 102 def wn_pair( = {}) ([:w_character] || 'w') + ([:n_character] || 'n') end |
.wn_to_rle(wn_str, options = {}) ⇒ Object
Generate rle pattern from wn string
92 93 94 |
# File 'lib/barcode1dtools.rb', line 92 def wn_to_rle(wn_str, = {}) wn_str.tr(wn_pair(), ([:wn_ratio] || 2).to_s + '1') end |