barby 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +2 -1
- data/barby.gemspec +17 -17
- data/lib/barby/barcode/data_matrix.rb +42 -7
- data/lib/barby/version.rb +2 -2
- data/test/bookland_test.rb +10 -8
- data/test/codabar_test.rb +7 -4
- data/test/code_128_test.rb +134 -128
- data/test/code_25_iata_test.rb +2 -2
- data/test/code_25_interleaved_test.rb +24 -18
- data/test/code_25_test.rb +36 -26
- data/test/code_39_test.rb +35 -32
- data/test/code_93_test.rb +31 -28
- data/test/data_matrix_test.rb +19 -8
- data/test/ean13_test.rb +31 -28
- data/test/ean8_test.rb +10 -10
- data/test/outputter/cairo_outputter_test.rb +31 -29
- data/test/outputter/html_outputter_test.rb +1 -2
- data/test/outputter/pdfwriter_outputter_test.rb +7 -7
- data/test/outputter/png_outputter_test.rb +9 -9
- data/test/outputter/prawn_outputter_test.rb +22 -22
- data/test/outputter/rmagick_outputter_test.rb +22 -22
- data/test/outputter/svg_outputter_test.rb +32 -31
- data/test/outputter_test.rb +30 -32
- data/test/pdf_417_test.rb +23 -23
- data/test/qr_code_test.rb +42 -37
- data/test/test_helper.rb +1 -1
- data/test/upc_supplemental_test.rb +39 -39
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5aba9010322760b9c4416d397c0566cf91df3c2e980c9f5b0d4af162e9823ee
|
4
|
+
data.tar.gz: d69476e6a231e61eff9406e752cc59527a0ffae9c3d9ca8155a62f9719487cbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94249381a5c5a2a4625bb6d64ccfe5ebb0d8b63ee326cbc0313cc07006a1a7c9654d8e3a2e9b006d93d040abbba594f4f137aea9346447909bb1834fb8b90edf
|
7
|
+
data.tar.gz: 1af6b8bcc689f7014d2d06a4e7fcaa9c2004909d0f5c609f6b32dc70f39bfd1e37b765337f8b126798ddac3158736e40adfa05909fae579c3fd66de36a0ef7cc
|
data/CHANGELOG
CHANGED
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 (
|
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
|
6
|
-
s.version
|
7
|
-
s.platform
|
8
|
-
s.summary
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.description
|
12
|
-
s.authors
|
13
|
-
|
14
|
-
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
|
+
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.
|
25
|
-
s.add_development_dependency "bundler", "~>
|
26
|
-
s.add_development_dependency "rake", "~>
|
27
|
-
s.add_development_dependency "
|
28
|
-
s.add_development_dependency "
|
29
|
-
s.add_development_dependency "
|
30
|
-
s.add_development_dependency "
|
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 '
|
1
|
+
require 'dmtx' # gem install dmtx
|
2
2
|
require 'barby/barcode'
|
3
3
|
|
4
4
|
module Barby
|
5
5
|
|
6
6
|
|
7
|
-
#Uses the
|
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
|
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
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
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
|
data/lib/barby/version.rb
CHANGED
data/test/bookland_test.rb
CHANGED
@@ -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
|
13
|
+
assert_equal '978968261240', @code.data
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should have the expected numbers" do
|
17
|
-
|
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
|
21
|
+
assert_equal 4, @code.checksum
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should raise an error when data not valid" do
|
25
|
-
|
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
|
-
|
35
|
+
assert_equal '978829252614', code.data
|
34
36
|
code = Bookland.new('979-82-92526-14-9')
|
35
37
|
assert code.valid?
|
36
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
@
|
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
|
-
|
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
|