Class: Barcodes::Symbology::MsiMod10
- Defined in:
- lib/barcodes/symbology/msimod10.rb
Overview
This class represents the MSI Mod 10 symbology MSI Mod 10 can encode only numbers 0-9
More info: en.wikipedia.org/wiki/MSI_Barcode
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 the provided data.
-
#formatted_data ⇒ Object
Returns start character + data + checksum + stop character.
Methods inherited from Msi
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::Msi
Instance Method Details
#checksum ⇒ Object
Calculates the checksum using the 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 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/barcodes/symbology/msimod10.rb', line 27 def checksum if self.valid? used_nums = [] unused_nums = [] index = 0 data.reverse.each_char do |char| if index.even? used_nums << char.to_i else unused_nums << char.to_i end index += 1 end used_nums.reverse! unused_nums.reverse! sum = 0 (used_nums.join.to_i * 2).to_s.split(//).each do |n| sum += n.to_i end unused_nums.each do |n| sum += n end value = 10 - (sum % 10) if value == 10 value = 0 end if (0..9).include? value return value.to_s end end end |
#formatted_data ⇒ Object
Returns start character + data + checksum + stop character
19 20 21 22 23 24 |
# File 'lib/barcodes/symbology/msimod10.rb', line 19 def formatted_data checksum = self.checksum unless checksum.nil? @start_character + @data + checksum + @stop_character end end |