Class | Barby::Code25 |
In: |
lib/barby/barcode/code_25.rb
|
Parent: | Barcode1D |
Standard/Industrial 2 of 5, non-interleaved
Checksum not included by default, to include it, set include_checksum = true
WIDE | = | W = true |
NARROW | = | N = false |
START_ENCODING | = | [W,W,N] |
STOP_ENCODING | = | [W,N,W] |
ENCODINGS | = | { 0 => [N,N,W,W,N], 1 => [W,N,N,N,W], 2 => [N,W,N,N,W], 3 => [W,W,N,N,N], 4 => [N,N,W,N,W], 5 => [W,N,W,N,N], 6 => [N,W,W,N,N], 7 => [N,N,N,W,W], 8 => [W,N,N,W,N], 9 => [N,W,N,W,N] |
data | [RW] | |
include_checksum | [RW] | |
narrow_width | [RW] | |
space_width | [RW] | |
wide_width | [RW] |
# File lib/barby/barcode/code_25.rb, line 56 56: def characters_with_checksum 57: characters.push(checksum.to_s) 58: end
Mod10
# File lib/barby/barcode/code_25.rb, line 106 106: def checksum 107: evens, odds = even_and_odd_digits 108: sum = odds.inject(0){|sum,d| sum + d } + evens.inject(0){|sum,d| sum + (d*3) } 109: sum %= 10 110: sum.zero? ? 0 : 10-sum 111: end
# File lib/barby/barcode/code_25.rb, line 113 113: def checksum_encoding 114: encoding_for(checksum) 115: end
# File lib/barby/barcode/code_25.rb, line 43 43: def data_encoding_with_checksum 44: digit_encodings_with_checksum.join 45: end
# File lib/barby/barcode/code_25.rb, line 74 74: def digit_encodings 75: raise_invalid unless valid? 76: digits.map{|d| encoding_for(d) } 77: end
# File lib/barby/barcode/code_25.rb, line 80 80: def digit_encodings_with_checksum 81: raise_invalid unless valid? 82: digits_with_checksum.map{|d| encoding_for(d) } 83: end
# File lib/barby/barcode/code_25.rb, line 64 64: def digits_with_checksum 65: digits.push(checksum) 66: end
# File lib/barby/barcode/code_25.rb, line 47 47: def encoding 48: start_encoding+(include_checksum? ? data_encoding_with_checksum : data_encoding)+stop_encoding 49: end
Generate encoding for an array of W,N
# File lib/barby/barcode/code_25.rb, line 93 93: def encoding_for_bars(*bars) 94: wide, narrow, space = wide_encoding, narrow_encoding, space_encoding 95: bars.flatten.inject '' do |enc,bar| 96: enc + (bar == WIDE ? wide : narrow) + space 97: end 98: end
# File lib/barby/barcode/code_25.rb, line 100 100: def encoding_for_bars_without_end_space(*a) 101: encoding_for_bars(*a).gsub(/0+$/, '') 102: end
# File lib/barby/barcode/code_25.rb, line 68 68: def even_and_odd_digits 69: alternater = false 70: digits.reverse.partition{ alternater = !alternater } 71: end
# File lib/barby/barcode/code_25.rb, line 160 160: def narrow_encoding 161: '1' * narrow_width 162: end
The width of a narrow bar in xdims
# File lib/barby/barcode/code_25.rb, line 119 119: def narrow_width 120: @narrow_width || 1 121: end
# File lib/barby/barcode/code_25.rb, line 168 168: def space_encoding 169: '0' * space_width 170: end
The width of the space between the bars in xdims By default the same width as a narrow bar
A space serves only as a separator for the bars, there is no encoded meaning in them
# File lib/barby/barcode/code_25.rb, line 134 134: def space_width 135: @space_width || narrow_width 136: end
# File lib/barby/barcode/code_25.rb, line 151 151: def start_encoding 152: encoding_for_bars(START_ENCODING) 153: end
# File lib/barby/barcode/code_25.rb, line 155 155: def stop_encoding 156: encoding_for_bars_without_end_space(STOP_ENCODING) 157: end
# File lib/barby/barcode/code_25.rb, line 178 178: def to_s 179: (include_checksum? ? characters_with_checksum : characters).join 180: end
The width of a wide bar in xdims By default three times as wide as a narrow bar
# File lib/barby/barcode/code_25.rb, line 125 125: def wide_width 126: @wide_width || narrow_width*3 127: end