Class: Barcodes::Symbology::Code39Mod43
- Defined in:
- lib/barcodes/symbology/code39mod43.rb
Overview
Modulo 43 checksum version of Code 39
More info: en.wikipedia.org/wiki/Code_39
Instance Attribute Summary
Attributes inherited from Base
#alpha, #bar_height, #bar_width, #caption_height, #caption_size, #captioned, #color, #data
Instance Method Summary collapse
-
#caption_data ⇒ Object
Returns caption data without checksum.
-
#checksum ⇒ Object
Calculates the checksum using the provided data.
-
#formatted_data ⇒ Object
Start character + data + checksum + stop character.
Methods inherited from Code39
charset, #initialize, valueset
Methods inherited from Base
charset, #encoded_data, #height, #initialize, #quiet_zone_width, #valid?, valueset, #width
Constructor Details
This class inherits a constructor from Barcodes::Symbology::Code39
Instance Method Details
#caption_data ⇒ Object
Returns caption data without checksum
18 19 20 |
# File 'lib/barcodes/symbology/code39mod43.rb', line 18 def caption_data @start_character + @data + @stop_character end |
#checksum ⇒ Object
Calculates the checksum using the provided data
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/barcodes/symbology/code39mod43.rb', line 31 def checksum if self.valid? sum = 0 self.data.each_char do |char| if ('0'..'9').include? char sum += char.to_i elsif ('A'..'Z').include? char sum += ('A'..'Z').to_a.index(char) + 10 else case char when '-' sum += 36 when '.' sum += 37 when ' ' sum += 38 when '$' sum += 39 when '/' sum += 40 when '+' sum += 41 when '%' sum += 42 end end end value = sum % 43 if (0..9).include? value return value.to_s elsif value >= 10 && value < 36 return ('A'..'Z').to_a.fetch(value - 10) else case value when 36 return '-' when 37 return '.' when 38 return ' ' when 39 return '$' when 40 return '/' when 41 return '+' when 42 return '%' end end end end |
#formatted_data ⇒ Object
Start character + data + checksum + stop character
23 24 25 26 27 28 |
# File 'lib/barcodes/symbology/code39mod43.rb', line 23 def formatted_data checksum = self.checksum unless checksum.nil? @start_character + @data + checksum + @stop_character end end |