Class: Barcodes::Symbology::MsiMod11
- Defined in:
- lib/barcodes/symbology/msimod11.rb
Overview
This class represents the MSI Mod 11 symbology MSI Mod 11 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 |
# File 'lib/barcodes/symbology/msimod11.rb', line 27 def checksum if self.valid? sum = 0 weight = 2 data.reverse.each_char do |char| if ('0'..'9').include? char sum += weight * char.to_i end if weight < 7 weight += 1 else weight = 2 end end value = sum % 11 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/msimod11.rb', line 19 def formatted_data checksum = self.checksum unless checksum.nil? @start_character + @data + checksum + @stop_character end end |