barby 0.6.8 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64d74091ea1f3aa79457c34878fc3b0d6f4c805dbb985d12eb372f29a7837e36
4
- data.tar.gz: a8a61c1af0a401a1b36bc675653d2063e569443d434a57b5a2d95c7abfc1d193
3
+ metadata.gz: f5aba9010322760b9c4416d397c0566cf91df3c2e980c9f5b0d4af162e9823ee
4
+ data.tar.gz: d69476e6a231e61eff9406e752cc59527a0ffae9c3d9ca8155a62f9719487cbc
5
5
  SHA512:
6
- metadata.gz: 99143c0bf41695fa1416956073bcb6c9d7257c677fa36337638f890681665bacd51c4b04cd3412008592c8f23e4130fec74363eb425c776f8c827bf360d07c5b
7
- data.tar.gz: d1b1f6aa2a63484b00f79bd184bef605b75850152dd54600b7eb25434f114c45c6994ce725af7535edefb8a536fc93f3e42c7d4bd2547c6f88d8da90d0947f8f
6
+ metadata.gz: 94249381a5c5a2a4625bb6d64ccfe5ebb0d8b63ee326cbc0313cc07006a1a7c9654d8e3a2e9b006d93d040abbba594f4f137aea9346447909bb1834fb8b90edf
7
+ data.tar.gz: 1af6b8bcc689f7014d2d06a4e7fcaa9c2004909d0f5c609f6b32dc70f39bfd1e37b765337f8b126798ddac3158736e40adfa05909fae579c3fd66de36a0ef7cc
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ * 0.7.0
2
+
3
+ * Swap semaocde for dmtx [ksylvest]
4
+
5
+ * 0.6.9
6
+
7
+ * Remove use of instance_eval in RMagick outputter [stlewis]
8
+ * Codabar in README [nashirox]
9
+
1
10
  * 0.6.7
2
11
 
3
12
  * RMagick outputter should use line command for lines [joshuaflanagan]
data/README.md CHANGED
@@ -62,13 +62,14 @@ require 'barby/barcode/<filename>'
62
62
  | Code 93 | `code_93` | ─ |
63
63
  | Code 128 (A, B, and C) | `code_128` | ─ |
64
64
  | └─ GS1 128 | `gs1_128` | ─ |
65
+ | Codabar | `codabar` | ─ |
65
66
  | EAN-13 | `ean_13` | ─ |
66
67
  | ├─ Bookland | `bookland` | ─ |
67
68
  | └─ UPC-A | `ean_13` | ─ |
68
69
  | EAN-8 | `ean_8` | ─ |
69
70
  | UPC/EAN supplemental, 2 & 5 digits | `upc_supplemental` | ─ |
70
71
  | QR Code | `qr_code` | `rqrcode` |
71
- | DataMatrix (Semacode) | `data_matrix` | `semacode` or `semacode-ruby19` |
72
+ | DataMatrix (dmtx) | `data_matrix` | `dmtx` |
72
73
  | PDF417 | `pdf_417` | JRuby |
73
74
 
74
75
 
data/barby.gemspec CHANGED
@@ -2,16 +2,16 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
  require "barby/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "barby"
6
- s.version = Barby::VERSION::STRING
7
- s.platform = Gem::Platform::RUBY
8
- s.summary = "The Ruby barcode generator"
9
- s.email = "toredarell@gmail.com"
10
- s.homepage = "http://toretore.github.com/barby"
11
- s.description = "Barby creates barcodes."
12
- s.authors = ['Tore Darell']
13
-
14
- s.rubyforge_project = "barby"
5
+ s.name = "barby"
6
+ s.version = Barby::VERSION::STRING
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = "The Ruby barcode generator"
9
+ s.email = "toredarell@gmail.com"
10
+ s.homepage = "http://toretore.github.com/barby"
11
+ s.description = "Barby creates barcodes."
12
+ s.authors = ['Tore Darell']
13
+ s.required_ruby_version = '>= 3.1'
14
+ s.licenses = []
15
15
 
16
16
  s.extra_rdoc_files = ["README.md"]
17
17
 
@@ -21,11 +21,11 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_development_dependency "minitest", "~> 5.11"
25
- s.add_development_dependency "bundler", "~> 1.16"
26
- s.add_development_dependency "rake", "~> 10.0"
27
- s.add_development_dependency "semacode-ruby19", "~> 0.7"
28
- s.add_development_dependency "rqrcode", "~> 0.10"
29
- s.add_development_dependency "prawn", "~> 2.2"
30
- s.add_development_dependency "cairo", "~> 1.15"
24
+ s.add_development_dependency "minitest", "~> 5.25"
25
+ s.add_development_dependency "bundler", "~> 2.5"
26
+ s.add_development_dependency "rake", "~> 13.2"
27
+ s.add_development_dependency "rqrcode", "~> 2.2"
28
+ s.add_development_dependency "prawn", "~> 2.5"
29
+ s.add_development_dependency "cairo", "~> 1.17"
30
+ s.add_development_dependency "dmtx", "~> 0.2"
31
31
  end
@@ -1,10 +1,10 @@
1
- require 'semacode' #Ruby 1.8: gem install semacode - Ruby 1.9: gem install semacode-ruby19
1
+ require 'dmtx' # gem install dmtx
2
2
  require 'barby/barcode'
3
3
 
4
4
  module Barby
5
5
 
6
6
 
7
- #Uses the semacode library (gem install semacode) to encode DataMatrix barcodes
7
+ #Uses the dmtx library (gem install dmtx) to encode DataMatrix barcodes
8
8
  class DataMatrix < Barcode2D
9
9
 
10
10
  attr_reader :data
@@ -21,21 +21,56 @@ module Barby
21
21
  end
22
22
 
23
23
  def encoder
24
- @encoder ||= ::DataMatrix::Encoder.new(data)
24
+ @encoder ||= ::Dmtx::DataMatrix.new(data)
25
25
  end
26
26
 
27
27
 
28
+ # Converts the barcode to an array of lines where 0 is white and 1 is black.
29
+ #
30
+ # @example
31
+ # code = Barby::DataMatrix.new('humbaba')
32
+ # code.encoding
33
+ # # => [
34
+ # # "10101010101010",
35
+ # # "10111010000001",
36
+ # # "11100101101100",
37
+ # # "11101001110001",
38
+ # # "11010101111110",
39
+ # # "11100101100001",
40
+ # # "11011001011110",
41
+ # # "10011011010011",
42
+ # # "11011010000100",
43
+ # # "10101100101001",
44
+ # # "11011100001100",
45
+ # # "10101110110111",
46
+ # # "11000001010100",
47
+ # # "11111111111111",
48
+ # # ]
49
+ #
50
+ # @return [String]
28
51
  def encoding
29
- encoder.data.map{|a| a.map{|b| b ? '1' : '0' }.join }
52
+ width = encoder.width
53
+ height = encoder.height
54
+
55
+ height.times.map { |y| width.times.map { |x| bit?(x, y) ? '1' : '0' }.join }
30
56
  end
31
57
 
32
58
 
33
- def semacode?
34
- #TODO: Not sure if this is right
35
- data =~ /^http:\/\//
59
+ # NOTE: this method is not exposed via the gem so using send ahead of opening a PR to hopefully support:
60
+ #
61
+ # https://github.com/mtgrosser/dmtx/blob/master/lib/dmtx/data_matrix.rb#L133-L135
62
+ #
63
+ # @param x [Integer] x-coordinate
64
+ # @param y [Integer] y-coordinate
65
+ # @return [Boolean]
66
+ def bit?(x, y)
67
+ encoder.send(:bit?, x, y)
36
68
  end
37
69
 
38
70
 
71
+ # The data being encoded.
72
+ #
73
+ # @return [String]
39
74
  def to_s
40
75
  data
41
76
  end
@@ -53,7 +53,7 @@ module Barby
53
53
  def to_image(opts={})
54
54
  with_options opts do
55
55
  b = background #Capture locally because Magick::Image.new block uses instance_eval
56
- canvas = Magick::Image.new(full_width, full_height){ self.background_color = b }
56
+ canvas = Magick::Image.new(full_width, full_height){ |i| i.background_color = b }
57
57
  bars = Magick::Draw.new
58
58
  bars.fill = foreground
59
59
 
data/lib/barby/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Barby #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 6
5
- TINY = 8
4
+ MINOR = 7
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.').freeze
8
8
  end
@@ -10,19 +10,21 @@ class BooklandTest < Barby::TestCase
10
10
  end
11
11
 
12
12
  it "should have the expected data" do
13
- @code.data.must_equal '978968261240'
13
+ assert_equal '978968261240', @code.data
14
14
  end
15
15
 
16
16
  it "should have the expected numbers" do
17
- @code.numbers.must_equal [9,7,8,9,6,8,2,6,1,2,4,0]
17
+ assert_equal [9,7,8,9,6,8,2,6,1,2,4,0], @code.numbers
18
18
  end
19
19
 
20
20
  it "should have the expected checksum" do
21
- @code.checksum.must_equal 4
21
+ assert_equal 4, @code.checksum
22
22
  end
23
23
 
24
24
  it "should raise an error when data not valid" do
25
- lambda{ Bookland.new('1234') }.must_raise ArgumentError
25
+ assert_raises ArgumentError do
26
+ Bookland.new('1234')
27
+ end
26
28
  end
27
29
 
28
30
  describe 'ISBN conversion' do
@@ -30,22 +32,22 @@ class BooklandTest < Barby::TestCase
30
32
  it "should accept ISBN with number system and check digit" do
31
33
  code = Bookland.new('978-82-92526-14-9')
32
34
  assert code.valid?
33
- code.data.must_equal '978829252614'
35
+ assert_equal '978829252614', code.data
34
36
  code = Bookland.new('979-82-92526-14-9')
35
37
  assert code.valid?
36
- code.data.must_equal '979829252614'
38
+ assert_equal '979829252614', code.data
37
39
  end
38
40
 
39
41
  it "should accept ISBN without number system but with check digit" do
40
42
  code = Bookland.new('82-92526-14-9')
41
43
  assert code.valid?
42
- code.data.must_equal '978829252614' #978 is the default prefix
44
+ assert_equal '978829252614', code.data #978 is the default prefix
43
45
  end
44
46
 
45
47
  it "should accept ISBN without number system or check digit" do
46
48
  code = Bookland.new('82-92526-14')
47
49
  assert code.valid?
48
- code.data.must_equal '978829252614'
50
+ assert_equal '978829252614', code.data
49
51
  end
50
52
 
51
53
  end
data/test/codabar_test.rb CHANGED
@@ -19,7 +19,9 @@ class CodabarTest < Barby::TestCase
19
19
  end
20
20
 
21
21
  it "should raise an exception when data is invalid" do
22
- lambda{ Codabar.new('A12345E') }.must_raise(ArgumentError)
22
+ assert_raises ArgumentError do
23
+ Codabar.new('A12345E')
24
+ end
23
25
  end
24
26
  end
25
27
 
@@ -31,7 +33,7 @@ class CodabarTest < Barby::TestCase
31
33
  end
32
34
 
33
35
  it "should have the same data as was passed to it" do
34
- @code.data.must_equal @data
36
+ assert_equal @data, @code.data
35
37
  end
36
38
  end
37
39
 
@@ -46,12 +48,13 @@ class CodabarTest < Barby::TestCase
46
48
  end
47
49
 
48
50
  it "should have the expected encoding" do
49
- @code.encoding.must_equal [
51
+ assert_equal [
50
52
  "1011001001", # A
51
53
  "101010011", # 0
52
54
  "101011001", # 1
53
55
  "1010011001", # D
54
- ].join("00")
56
+ ].join("00"),
57
+ @code.encoding
55
58
  end
56
59
  end
57
60
  end