barby 0.6.5 → 0.6.6
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 +21 -20
- data/lib/barby/barcode/codabar.rb +82 -0
- data/lib/barby/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 785be5fa4a1302abd27db4793aa66e35342a80d1
|
4
|
+
data.tar.gz: 70c044812cef3591c072b891ab1a827e524a9819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bcad78fd0a01fa2184a95ccb909ec214b06bdcafa353fa5cbb70416772b8c4bf7cd94866c969e985e273f311551d6de2211bf9cd503580bda32b32b8a2b544b
|
7
|
+
data.tar.gz: 66e130f3faf4eec7044e88455b2e3ab6dd3b5da8921190568bf235d843719fb4ebac547d387bb4bee66500bfb0c76a8a65f4de89874742125d88a7b137b1d269
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,8 @@ lines or squares, outputters will do that for you.
|
|
12
12
|
Likewise, you can easily add an outputter for a format that doesn't have one
|
13
13
|
yet, and it will work with all existing symbologies.
|
14
14
|
|
15
|
-
For more information, check out [the Barby wiki]
|
15
|
+
For more information, check out [the Barby wiki][wiki].
|
16
|
+
|
16
17
|
|
17
18
|
### New require policy
|
18
19
|
|
@@ -51,24 +52,24 @@ puts barcode.to_ascii #Implicitly uses the AsciiOutputter
|
|
51
52
|
require 'barby/barcode/<filename>'
|
52
53
|
```
|
53
54
|
|
54
|
-
| Name | Filename | Dependencies
|
55
|
-
| ----------------------------------- | --------------------- |
|
56
|
-
| Code 25 | `code_25` | ─
|
57
|
-
| ├─ Interleaved | `code_25_interleaved` | ─
|
58
|
-
| └─ IATA | `code_25_iata` | ─
|
59
|
-
| Code 39 | `code_39` | ─
|
60
|
-
| └─ Extended | `code_39` | ─
|
61
|
-
| Code 93 | `code_93` | ─
|
62
|
-
| Code 128 (A, B, and C) | `code_128` | ─
|
63
|
-
| └─ GS1 128 | `gs1_128` | ─
|
64
|
-
| EAN-13 | `ean_13` | ─
|
65
|
-
| ├─ Bookland | `bookland` | ─
|
66
|
-
| └─ UPC-A | `ean_13` | ─
|
67
|
-
| EAN-8 | `ean_8` | ─
|
68
|
-
| UPC/EAN supplemental, 2 & 5 digits | `upc_supplemental` | ─
|
69
|
-
| QR Code | `qr_code` | `rqrcode`
|
70
|
-
| DataMatrix (Semacode) | `data_matrix` | `semacode` |
|
71
|
-
| PDF417 | `pdf_417` | JRuby
|
55
|
+
| Name | Filename | Dependencies |
|
56
|
+
| ----------------------------------- | --------------------- | ---------------------------------- |
|
57
|
+
| Code 25 | `code_25` | ─ |
|
58
|
+
| ├─ Interleaved | `code_25_interleaved` | ─ |
|
59
|
+
| └─ IATA | `code_25_iata` | ─ |
|
60
|
+
| Code 39 | `code_39` | ─ |
|
61
|
+
| └─ Extended | `code_39` | ─ |
|
62
|
+
| Code 93 | `code_93` | ─ |
|
63
|
+
| Code 128 (A, B, and C) | `code_128` | ─ |
|
64
|
+
| └─ GS1 128 | `gs1_128` | ─ |
|
65
|
+
| EAN-13 | `ean_13` | ─ |
|
66
|
+
| ├─ Bookland | `bookland` | ─ |
|
67
|
+
| └─ UPC-A | `ean_13` | ─ |
|
68
|
+
| EAN-8 | `ean_8` | ─ |
|
69
|
+
| UPC/EAN supplemental, 2 & 5 digits | `upc_supplemental` | ─ |
|
70
|
+
| QR Code | `qr_code` | `rqrcode` |
|
71
|
+
| DataMatrix (Semacode) | `data_matrix` | `semacode` or `semacode-ruby19` |
|
72
|
+
| PDF417 | `pdf_417` | JRuby |
|
72
73
|
|
73
74
|
|
74
75
|
## Outputters
|
@@ -99,7 +100,7 @@ require 'barby/outputter/<filename>_outputter'
|
|
99
100
|
|
100
101
|
---
|
101
102
|
|
102
|
-
For more information, check out [the Barby wiki]
|
103
|
+
For more information, check out [the Barby wiki][wiki].
|
103
104
|
|
104
105
|
|
105
106
|
[wiki]: https://github.com/toretore/barby/wiki
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "barby/barcode"
|
2
|
+
|
3
|
+
module Barby
|
4
|
+
# https://en.wikipedia.org/wiki/Codabar
|
5
|
+
class Codabar < Barcode1D
|
6
|
+
BLACK_NARROW_WIDTH = 1
|
7
|
+
WHITE_NARROW_WIDTH = 2
|
8
|
+
WIDE_WIDTH_RATE = 3
|
9
|
+
SPACING = 5 # must be equal to or wider than white narrow width
|
10
|
+
CHARACTERS = "0123456789-$:/.+ABCD".freeze
|
11
|
+
# even: black, odd: white
|
12
|
+
# 0: narrow, 1: wide
|
13
|
+
BINARY_EXPRESSION = [
|
14
|
+
"0000011", # 0
|
15
|
+
"0000110", # 1
|
16
|
+
"0001001", # 2
|
17
|
+
"1100000", # 3
|
18
|
+
"0010010", # 4
|
19
|
+
"1000010", # 5
|
20
|
+
"0100001", # 6
|
21
|
+
"0100100", # 7
|
22
|
+
"0110000", # 8
|
23
|
+
"1001000", # 9
|
24
|
+
"0001100", # -
|
25
|
+
"0011000", # $
|
26
|
+
"1000101", # :
|
27
|
+
"1010001", # /
|
28
|
+
"1010100", # .
|
29
|
+
"0010101", # +
|
30
|
+
"0011010", # A
|
31
|
+
"0101001", # B
|
32
|
+
"0001011", # C
|
33
|
+
"0001110", # D
|
34
|
+
].each(&:freeze)
|
35
|
+
CHARACTER_TO_BINARY = Hash[CHARACTERS.chars.zip(BINARY_EXPRESSION)].freeze
|
36
|
+
FORMAT = /\A[ABCD][0123456789\-\$:\/\.\+]+[ABCD]\z/.freeze
|
37
|
+
ONE = "1".freeze
|
38
|
+
ZERO = "0".freeze
|
39
|
+
|
40
|
+
attr_accessor :data, :black_narrow_width, :white_narrow_width, :wide_width_rate, :spacing
|
41
|
+
|
42
|
+
def initialize(data)
|
43
|
+
self.data = data
|
44
|
+
raise ArgumentError, 'data not valid' unless valid?
|
45
|
+
|
46
|
+
self.black_narrow_width = BLACK_NARROW_WIDTH
|
47
|
+
self.white_narrow_width = WHITE_NARROW_WIDTH
|
48
|
+
self.wide_width_rate = WIDE_WIDTH_RATE
|
49
|
+
self.spacing = SPACING
|
50
|
+
end
|
51
|
+
|
52
|
+
def encoding
|
53
|
+
data.chars.map{|c| binary_to_bars(CHARACTER_TO_BINARY[c]) }.join(ZERO * spacing)
|
54
|
+
end
|
55
|
+
|
56
|
+
def valid?
|
57
|
+
data =~ FORMAT
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def binary_to_bars(bin)
|
62
|
+
bin.chars.each_with_index.map{|c, i|
|
63
|
+
black = i % 2 == 0
|
64
|
+
narrow = c == ZERO
|
65
|
+
|
66
|
+
if black
|
67
|
+
if narrow
|
68
|
+
ONE * black_narrow_width
|
69
|
+
else
|
70
|
+
ONE * (black_narrow_width * wide_width_rate).to_i
|
71
|
+
end
|
72
|
+
else
|
73
|
+
if narrow
|
74
|
+
ZERO * white_narrow_width
|
75
|
+
else
|
76
|
+
ZERO * (white_narrow_width * wide_width_rate).to_i
|
77
|
+
end
|
78
|
+
end
|
79
|
+
}.join
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/barby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tore Darell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Barby creates barcodes.
|
14
14
|
email: toredarell@gmail.com
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- lib/barby.rb
|
25
25
|
- lib/barby/barcode.rb
|
26
26
|
- lib/barby/barcode/bookland.rb
|
27
|
+
- lib/barby/barcode/codabar.rb
|
27
28
|
- lib/barby/barcode/code_128.rb
|
28
29
|
- lib/barby/barcode/code_25.rb
|
29
30
|
- lib/barby/barcode/code_25_iata.rb
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
72
|
rubyforge_project: barby
|
72
|
-
rubygems_version: 2.5.
|
73
|
+
rubygems_version: 2.5.2
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
76
|
summary: The Ruby barcode generator
|