Class: Barcodes::Symbology::Interleaved2Of5Mod10
- Inherits:
-
Interleaved2Of5
- Object
- Base
- Interleaved2Of5
- Barcodes::Symbology::Interleaved2Of5Mod10
- Defined in:
- lib/barcodes/symbology/interleaved2of5mod10.rb
Overview
This class represents the Interleaved 2 of 5 Mod 10 symbology Interleaved 2 of 5 Mod 10 can encode only numbers 0-9
More info: en.wikipedia.org/wiki/Interleaved_2_of_5
Instance Attribute Summary
Attributes inherited from Base
#alpha, #bar_height, #bar_width, #caption_height, #caption_size, #captioned, #color, #data
Instance Method Summary collapse
-
#checksum ⇒ Object
Calculates the checksum using provided data.
-
#formatted_data ⇒ Object
Returns start character + data + checksum + stop character.
Methods inherited from Interleaved2Of5
charset, #initialize, valueset
Methods inherited from Base
#caption_data, charset, #encoded_data, #height, #initialize, #quiet_zone_width, #valid?, valueset, #width
Constructor Details
This class inherits a constructor from Barcodes::Symbology::Interleaved2Of5
Instance Method Details
#checksum ⇒ Object
Calculates the checksum using provided data
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/barcodes/symbology/interleaved2of5mod10.rb', line 27 def checksum even_sum = 0 odd_sum = 0 index = 0 @data.reverse.each_char do |char| if ('0'..'9').include? char if index.even? even_sum += char.to_i * 3 else odd_sum += char.to_i end end index += 1 end sum = even_sum + odd_sum value = 10 - (sum % 10) if value == 10 value = 0 end if (0..9).include? value return value.to_s end end |
#formatted_data ⇒ Object
Returns start character + data + checksum + stop character
19 20 21 22 23 24 |
# File 'lib/barcodes/symbology/interleaved2of5mod10.rb', line 19 def formatted_data checksum = self.checksum unless checksum.nil? @start_character + @data + checksum + @stop_character end end |