barcodes 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/Gemfile +6 -0
  2. data/README.md +24 -24
  3. data/Rakefile +6 -0
  4. data/barcodes.gemspec +6 -0
  5. data/lib/barcodes.rb +52 -0
  6. data/lib/barcodes/exec.rb +52 -31
  7. data/lib/barcodes/renderer.rb +6 -0
  8. data/lib/barcodes/renderer/ascii.rb +7 -0
  9. data/lib/barcodes/renderer/pdf.rb +6 -0
  10. data/lib/barcodes/symbology.rb +6 -0
  11. data/lib/barcodes/symbology/base.rb +55 -15
  12. data/lib/barcodes/symbology/codabar.rb +23 -0
  13. data/lib/barcodes/symbology/code11.rb +18 -0
  14. data/lib/barcodes/symbology/code128.rb +44 -5
  15. data/lib/barcodes/symbology/code39.rb +21 -0
  16. data/lib/barcodes/symbology/code39extended.rb +12 -0
  17. data/lib/barcodes/symbology/code39extendedmod43.rb +14 -0
  18. data/lib/barcodes/symbology/code39mod43.rb +14 -0
  19. data/lib/barcodes/symbology/code93.rb +23 -0
  20. data/lib/barcodes/symbology/code93extended.rb +17 -1
  21. data/lib/barcodes/symbology/ean.rb +28 -1
  22. data/lib/barcodes/symbology/ean13.rb +17 -0
  23. data/lib/barcodes/symbology/ean8.rb +18 -0
  24. data/lib/barcodes/symbology/interleaved2of5.rb +18 -0
  25. data/lib/barcodes/symbology/interleaved2of5mod10.rb +14 -0
  26. data/lib/barcodes/symbology/msi.rb +16 -0
  27. data/lib/barcodes/symbology/msimod10.rb +14 -0
  28. data/lib/barcodes/symbology/msimod11.rb +14 -0
  29. data/lib/barcodes/symbology/planet.rb +24 -1
  30. data/lib/barcodes/symbology/postnet.rb +24 -1
  31. data/lib/barcodes/symbology/standard2of5.rb +16 -0
  32. data/lib/barcodes/symbology/standard2of5mod10.rb +14 -0
  33. data/lib/barcodes/symbology/upca.rb +16 -0
  34. data/lib/barcodes/version.rb +9 -1
  35. data/spec/barcodes/exec_spec.rb +7 -1
  36. data/spec/barcodes/renderer/ascii_spec.rb +6 -0
  37. data/spec/barcodes/renderer/pdf_spec.rb +6 -0
  38. data/spec/barcodes/symbology/base_spec.rb +6 -0
  39. data/spec/barcodes/symbology/codabar_spec.rb +6 -0
  40. data/spec/barcodes/symbology/code11_spec.rb +6 -0
  41. data/spec/barcodes/symbology/code128_spec.rb +6 -0
  42. data/spec/barcodes/symbology/code39_spec.rb +6 -0
  43. data/spec/barcodes/symbology/code39extended_spec.rb +6 -0
  44. data/spec/barcodes/symbology/code39extendedmod43_spec.rb +6 -0
  45. data/spec/barcodes/symbology/code39mod43_spec.rb +6 -0
  46. data/spec/barcodes/symbology/code93_spec.rb +6 -0
  47. data/spec/barcodes/symbology/code93extended_spec.rb +6 -0
  48. data/spec/barcodes/symbology/ean13_spec.rb +6 -0
  49. data/spec/barcodes/symbology/ean8_spec.rb +6 -0
  50. data/spec/barcodes/symbology/ean_spec.rb +6 -0
  51. data/spec/barcodes/symbology/interleaved2of5_spec.rb +6 -0
  52. data/spec/barcodes/symbology/interleaved2of5mod10_spec.rb +6 -0
  53. data/spec/barcodes/symbology/msi_spec.rb +6 -0
  54. data/spec/barcodes/symbology/msimod10_spec.rb +6 -0
  55. data/spec/barcodes/symbology/msimod11_spec.rb +6 -0
  56. data/spec/barcodes/symbology/planet_spec.rb +6 -0
  57. data/spec/barcodes/symbology/postnet_spec.rb +6 -0
  58. data/spec/barcodes/symbology/standard2of5_spec.rb +6 -0
  59. data/spec/barcodes/symbology/standard2of5mod10_spec.rb +6 -0
  60. data/spec/barcodes/symbology/upca_spec.rb +6 -0
  61. data/spec/barcodes_spec.rb +6 -0
  62. data/spec/spec_helper.rb +6 -0
  63. metadata +8 -8
@@ -1,12 +1,26 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the POSTNET symbology
13
+ # POSTNET can encode only numbers 0-9
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/POSTNET
5
16
  class Postnet < Base
17
+
18
+ # POSTNET character set
6
19
  def self.charset
7
20
  ['0','1','2','3','4','5','6','7','8','9'].collect {|c| c.bytes.to_a[0] }
8
21
  end
9
22
 
23
+ # POSTNET values set
10
24
  def self.valueset
11
25
  [
12
26
  '11000','00011','00101','00110',
@@ -15,6 +29,7 @@ module Barcodes
15
29
  ]
16
30
  end
17
31
 
32
+ # Creates a new Postnet instance
18
33
  def initialize(args={})
19
34
  unless args.has_key? :data
20
35
  args[:data] = '01234'
@@ -23,6 +38,7 @@ module Barcodes
23
38
  super(args)
24
39
  end
25
40
 
41
+ # Returns data + checksum
26
42
  def formatted_data
27
43
  checksum = self.checksum
28
44
  unless checksum.nil?
@@ -30,6 +46,7 @@ module Barcodes
30
46
  end
31
47
  end
32
48
 
49
+ # Returns the barcode data encoded as 1's and 0's.
33
50
  def encoded_data
34
51
  if self.valid?
35
52
  encoded_data = ''
@@ -40,6 +57,7 @@ module Barcodes
40
57
  end
41
58
  end
42
59
 
60
+ # Calculates the checksum using the provided data
43
61
  def checksum
44
62
  if self.valid?
45
63
  sum = 0
@@ -58,17 +76,22 @@ module Barcodes
58
76
  end
59
77
  end
60
78
 
79
+ # Returns the overall width of the barcode in mils.
61
80
  def width
62
81
  if self.valid?
63
82
  return (((self.encoded_data.length * 2) - 1) * 20)
64
83
  end
65
84
  return 0
66
85
  end
67
-
86
+
87
+ # Returns the overall height of the barcode in mils.
68
88
  def height
69
89
  125
70
90
  end
71
91
 
92
+ # Determines whether or not the barcode data to be encoded
93
+ # is valid.
94
+ # Data length must be 5, 9 or 11 digits
72
95
  def valid?
73
96
  @data.each_byte do |char|
74
97
  if self._encode_character(char).nil?
@@ -1,12 +1,26 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Standard 2 of 5 symbology
13
+ # Standard 2 of 5 can encode only numbers 0-9
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Two-out-of-five_code
5
16
  class Standard2Of5 < Base
17
+
18
+ # Standard 2 of 5 character set
6
19
  def self.charset
7
20
  ['0','1','2','3','4','5','6','7','8','9','S','E'].collect {|c| c.bytes.to_a[0] }
8
21
  end
9
22
 
23
+ # Standard 2 of 5 values set
10
24
  def self.valueset
11
25
  [
12
26
  '10101110111010','11101010101110','10111010101110','11101110101010',
@@ -15,6 +29,7 @@ module Barcodes
15
29
  ]
16
30
  end
17
31
 
32
+ # Creates a new Standard2Of5 instance
18
33
  def initialize(args={})
19
34
  super(args)
20
35
 
@@ -22,6 +37,7 @@ module Barcodes
22
37
  @stop_character = 'E'
23
38
  end
24
39
 
40
+ # Returns start character + data + stop character
25
41
  def formatted_data
26
42
  @start_character + @data + @stop_character
27
43
  end
@@ -1,8 +1,21 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/standard2of5'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Standard 2 of 5 Mod 10 symbology
13
+ # Standard 2 of 5 Mod 10 can encode only numbers 0-9
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Two-out-of-five_code
5
16
  class Standard2Of5Mod10 < Standard2Of5
17
+
18
+ # Returns start character + data + checksum + stop character
6
19
  def formatted_data
7
20
  checksum = self.checksum
8
21
  unless checksum.nil?
@@ -10,6 +23,7 @@ module Barcodes
10
23
  end
11
24
  end
12
25
 
26
+ # Calculates the checksum using the provided data
13
27
  def checksum
14
28
  even_sum = 0
15
29
  odd_sum = 0
@@ -1,8 +1,21 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/ean'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the UPC-A symbology
13
+ # UPC-A can encode only numbers 0-9
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Universal_Product_Code
5
16
  class UpcA < Ean
17
+
18
+ # Creates a new UpcA instance
6
19
  def initialize(args={})
7
20
  unless args.has_key? :data
8
21
  args[:data] = '01234567899'
@@ -11,10 +24,13 @@ module Barcodes
11
24
  super(args)
12
25
  end
13
26
 
27
+ # Returns start character + 0 + data + center character + data + checksum + stop character
14
28
  def formatted_data
15
29
  @start_character + '0' + @data[0..5] + @center_character + @data[6..10] + self.checksum + @stop_character
16
30
  end
17
31
 
32
+ # Validates barcode using provided data
33
+ # Data length must be 11 digits
18
34
  def valid?
19
35
  unless super
20
36
  return false
@@ -1,3 +1,11 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
7
+ #
1
8
  module Barcodes
2
- VERSION = "0.0.1"
9
+ # Returns the current version
10
+ VERSION = "0.0.2"
3
11
  end
@@ -1,9 +1,15 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/exec'
3
9
 
4
10
  describe Barcodes::Exec do
5
11
  describe "#new" do
6
- it "should accept command line arguments and return a new Barcodes::Exec class" do
12
+ it "should accept an array of command line arguments and return a new Barcodes::Exec class" do
7
13
 
8
14
  end
9
15
  end
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/renderer/ascii'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/renderer/pdf'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/base'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/codabar'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code11'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code128'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code39'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code39extended'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code39extendedmod43'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code39mod43'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code93'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/code93extended'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/ean13'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/ean8'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/ean'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/interleaved2of5'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/interleaved2of5mod10'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/msi'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/msimod10'
3
9
 
@@ -1,3 +1,9 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'spec_helper'
2
8
  require 'barcodes/symbology/msimod11'
3
9