Class: Barby::Code25Interleaved
- Defined in:
- lib/barby/barcode/code_25_interleaved.rb
Overview
Code 2 of 5 interleaved. Same as standard 2 of 5, but spaces are used for encoding as well as the bars. Each pair of numbers get interleaved, that is, the first is encoded in the bars and the second is encoded in the spaced. This means an interleaved 2/5 barcode must have an even number of digits.
Constant Summary collapse
- START_ENCODING =
[N,N,N,N]
- STOP_ENCODING =
[W,N,N]
Constants inherited from Code25
Barby::Code25::ENCODINGS, Barby::Code25::NARROW, Barby::Code25::WIDE
Instance Attribute Summary
Attributes inherited from Code25
#data, #include_checksum, #narrow_width, #space_width, #wide_width
Instance Method Summary collapse
- #digit_encodings ⇒ Object
- #digit_encodings_with_checksum ⇒ Object
- #digit_pairs(d = nil) ⇒ Object
- #digit_pairs_with_checksum ⇒ Object
-
#encoding_for_interleaved(*bars_and_spaces) ⇒ Object
Encodes an array of interleaved W or N bars and spaces ex: [W,N,W,W,N,N] => “111011100010”.
- #encoding_for_pair(pair) ⇒ Object
- #start_encoding ⇒ Object
- #stop_encoding ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Code25
#characters, #characters_with_checksum, #checksum, #checksum_encoding, #data_encoding, #data_encoding_with_checksum, #digits, #digits_with_checksum, #encoding, #encoding_for, #encoding_for_bars, #encoding_for_bars_without_end_space, #even_and_odd_digits, #include_checksum?, #initialize, #narrow_encoding, #space_encoding, #to_s, #wide_encoding
Methods inherited from Barcode
#encoding, #method_missing, #outputter_class_for, #outputter_for, outputters, register_outputter, #to_s, #two_dimensional?
Constructor Details
This class inherits a constructor from Barby::Code25
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Barby::Barcode
Instance Method Details
#digit_encodings ⇒ Object
29 30 31 32 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 29 def digit_encodings raise_invalid unless valid? digit_pairs.map{|p| encoding_for_pair(p) } end |
#digit_encodings_with_checksum ⇒ Object
34 35 36 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 34 def digit_encodings_with_checksum digit_pairs_with_checksum.map{|p| encoding_for_pair(p) } end |
#digit_pairs(d = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 16 def digit_pairs(d=nil) (d || digits).inject [] do |ary,i| ary << [] if !ary.last || ary.last.size == 2 ary.last << i ary end end |
#digit_pairs_with_checksum ⇒ Object
24 25 26 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 24 def digit_pairs_with_checksum digit_pairs(digits_with_checksum) end |
#encoding_for_interleaved(*bars_and_spaces) ⇒ Object
Encodes an array of interleaved W or N bars and spaces ex: [W,N,W,W,N,N] => “111011100010”
47 48 49 50 51 52 53 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 47 def encoding_for_interleaved(*) = false#starts with bar .flatten.inject '' do |enc,| = ! enc << ( ? '1' : '0') * ( == WIDE ? wide_width : narrow_width) end end |
#encoding_for_pair(pair) ⇒ Object
39 40 41 42 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 39 def encoding_for_pair(pair) , spaces = ENCODINGS[pair.first], ENCODINGS[pair.last] encoding_for_interleaved(.zip(spaces)) end |
#start_encoding ⇒ Object
56 57 58 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 56 def start_encoding encoding_for_interleaved(START_ENCODING) end |
#stop_encoding ⇒ Object
60 61 62 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 60 def stop_encoding encoding_for_interleaved(STOP_ENCODING) end |
#valid? ⇒ Boolean
65 66 67 68 |
# File 'lib/barby/barcode/code_25_interleaved.rb', line 65 def valid? # When checksum is included, it's included when determining "evenness" super && digits.size % 2 == (include_checksum? ? 1 : 0) end |