usps_intelligent_barcode 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +2 -1
- data/Gemfile +8 -4
- data/Gemfile.lock +44 -40
- data/README.markdown +6 -3
- data/Rakefile +4 -28
- data/lib/usps_intelligent_barcode/bar_map.rb +10 -8
- data/lib/usps_intelligent_barcode/bar_position.rb +14 -10
- data/lib/usps_intelligent_barcode/bar_symbol.rb +42 -12
- data/lib/usps_intelligent_barcode/bar_to_character_mapping.yml +24 -0
- data/lib/usps_intelligent_barcode/barcode.rb +50 -9
- data/lib/usps_intelligent_barcode/barcode_id.rb +14 -12
- data/lib/usps_intelligent_barcode/character_position.rb +10 -8
- data/lib/usps_intelligent_barcode/codeword_map.rb +0 -1
- data/lib/usps_intelligent_barcode/codeword_to_character_mapping.yml +7 -0
- data/lib/usps_intelligent_barcode/crc.rb +3 -3
- data/lib/usps_intelligent_barcode/mailer_id.rb +12 -13
- data/lib/usps_intelligent_barcode/numeric_conversions.rb +7 -6
- data/lib/usps_intelligent_barcode/routing_code.rb +18 -17
- data/lib/usps_intelligent_barcode/serial_number.rb +10 -10
- data/lib/usps_intelligent_barcode/service_type.rb +8 -11
- data/rake/default.rb +1 -0
- data/rake/jeweler.rb +23 -0
- data/rake/rspec.rb +2 -0
- data/rake/yard.rb +8 -0
- data/spec/spec_helper.rb +2 -1
- data/usps_intelligent_barcode.gemspec +14 -16
- metadata +27 -51
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YTUzZDMyYWQ4NjQ3ZGZlMzEyNDVlZmEzNzdkN2Q2ZDcwNmE0YTk2OA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdeac04e1071c96dc596d2bec3e84ece73cf2291
|
4
|
+
data.tar.gz: 451155bce2c3da38ce4477268f27edcf74c252d8
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NzA5NDJhYWY1YWZlNWEyM2Y1OTUyZDA2NWYwYTQ3MDE4NGQ5ZTYyYTYwMTE5
|
11
|
-
MDZjNDkzNjkyNjVjM2ViMGYzZjVlZTNlZWI1NDVjZTI3NDJmNDU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Zjk3Mzk1OWFiODczMWI1MDE0Njg0N2Q1MjY3YWI5NjJhNDU2NzBhNTQxNWE1
|
14
|
-
ZDAyMmY0YTM1ZDU2NmE0MGE1NzUzZDZkYzYzODhhNDUzMGU1Yjk3Y2IyMjA0
|
15
|
-
OTI3MmVmYTM1YTA1ZDQ3ZjUwMzJmZGFlNzZlZTlmZDUyOThjNjg=
|
6
|
+
metadata.gz: 330b9a3c194405b63ac36a84cfadff64a3656fe769d0cda0f5edfeaa0478d72611812baae70b1f0e10404f9f421520f0c09f14ae41f0ce172cf1f1e10d538d8d
|
7
|
+
data.tar.gz: 7d067d53ea00a44f1334f1791c877b4a57f0e36282419b74addb8499c9d77f7548698a3fab0c4d83782decf0a068995de31775f6fdd6532db75251e82ec8433c
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,11 +3,15 @@ source 'http://rubygems.org'
|
|
3
3
|
gem 'andand', '~> 1.3'
|
4
4
|
gem 'memoizer', '~> 1.0'
|
5
5
|
|
6
|
-
group :
|
7
|
-
gem '
|
6
|
+
group :test do
|
7
|
+
gem 'rake', '~> 11.2'
|
8
8
|
gem 'rspec', '~> 3.3'
|
9
9
|
gem 'rspec-its', '~> 1.0'
|
10
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem 'jeweler', '~> 2.0'
|
14
|
+
gem 'rake', '~> 11.2'
|
15
|
+
gem 'simplecov'
|
11
16
|
gem 'yard', '~> 0.8.5'
|
12
|
-
gem 'rake', '~> 10.0'
|
13
17
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,74 +1,78 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.
|
4
|
+
addressable (2.5.0)
|
5
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
5
6
|
andand (1.3.3)
|
6
7
|
builder (3.2.2)
|
7
8
|
descendants_tracker (0.0.4)
|
8
9
|
thread_safe (~> 0.3, >= 0.3.1)
|
9
10
|
diff-lcs (1.2.5)
|
10
11
|
docile (1.1.5)
|
11
|
-
faraday (0.9.
|
12
|
+
faraday (0.9.2)
|
12
13
|
multipart-post (>= 1.2, < 3)
|
13
|
-
git (1.
|
14
|
-
github_api (0.
|
14
|
+
git (1.3.0)
|
15
|
+
github_api (0.11.3)
|
15
16
|
addressable (~> 2.3)
|
16
|
-
descendants_tracker (~> 0.0.
|
17
|
+
descendants_tracker (~> 0.0.1)
|
17
18
|
faraday (~> 0.8, < 0.10)
|
18
|
-
hashie (>=
|
19
|
+
hashie (>= 1.2)
|
19
20
|
multi_json (>= 1.7.5, < 2.0)
|
20
|
-
nokogiri (~> 1.6.
|
21
|
+
nokogiri (~> 1.6.0)
|
21
22
|
oauth2
|
22
|
-
hashie (3.4.
|
23
|
-
highline (1.7.
|
24
|
-
jeweler (2.
|
23
|
+
hashie (3.4.6)
|
24
|
+
highline (1.7.8)
|
25
|
+
jeweler (2.1.2)
|
25
26
|
builder
|
26
27
|
bundler (>= 1.0)
|
27
28
|
git (>= 1.2.5)
|
28
|
-
github_api
|
29
|
+
github_api (~> 0.11.0)
|
29
30
|
highline (>= 1.6.15)
|
30
31
|
nokogiri (>= 1.5.10)
|
31
32
|
rake
|
32
33
|
rdoc
|
33
|
-
|
34
|
-
|
34
|
+
semver
|
35
|
+
json (2.0.2)
|
36
|
+
json (2.0.2-java)
|
37
|
+
jwt (1.5.6)
|
35
38
|
memoizer (1.0.1)
|
36
|
-
|
37
|
-
multi_json (1.
|
39
|
+
mini_portile2 (2.1.0)
|
40
|
+
multi_json (1.12.1)
|
38
41
|
multi_xml (0.5.5)
|
39
42
|
multipart-post (2.0.0)
|
40
|
-
nokogiri (1.6.
|
41
|
-
|
42
|
-
nokogiri (1.6.
|
43
|
-
oauth2 (1.
|
43
|
+
nokogiri (1.6.8.1)
|
44
|
+
mini_portile2 (~> 2.1.0)
|
45
|
+
nokogiri (1.6.8.1-java)
|
46
|
+
oauth2 (1.2.0)
|
44
47
|
faraday (>= 0.8, < 0.10)
|
45
48
|
jwt (~> 1.0)
|
46
49
|
multi_json (~> 1.3)
|
47
50
|
multi_xml (~> 0.5)
|
48
|
-
rack (
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
rspec (3.
|
54
|
-
rspec-core (~> 3.
|
55
|
-
rspec-expectations (~> 3.
|
56
|
-
rspec-mocks (~> 3.
|
57
|
-
rspec-core (3.
|
58
|
-
rspec-support (~> 3.
|
59
|
-
rspec-expectations (3.
|
51
|
+
rack (>= 1.2, < 3)
|
52
|
+
public_suffix (2.0.4)
|
53
|
+
rack (2.0.1)
|
54
|
+
rake (11.3.0)
|
55
|
+
rdoc (5.0.0)
|
56
|
+
rspec (3.5.0)
|
57
|
+
rspec-core (~> 3.5.0)
|
58
|
+
rspec-expectations (~> 3.5.0)
|
59
|
+
rspec-mocks (~> 3.5.0)
|
60
|
+
rspec-core (3.5.4)
|
61
|
+
rspec-support (~> 3.5.0)
|
62
|
+
rspec-expectations (3.5.0)
|
60
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
-
rspec-support (~> 3.
|
64
|
+
rspec-support (~> 3.5.0)
|
62
65
|
rspec-its (1.2.0)
|
63
66
|
rspec-core (>= 3.0.0)
|
64
67
|
rspec-expectations (>= 3.0.0)
|
65
|
-
rspec-mocks (3.
|
68
|
+
rspec-mocks (3.5.0)
|
66
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-support (3.
|
69
|
-
|
70
|
+
rspec-support (~> 3.5.0)
|
71
|
+
rspec-support (3.5.0)
|
72
|
+
semver (1.0.1)
|
73
|
+
simplecov (0.12.0)
|
70
74
|
docile (~> 1.1.0)
|
71
|
-
json (
|
75
|
+
json (>= 1.8, < 3)
|
72
76
|
simplecov-html (~> 0.10.0)
|
73
77
|
simplecov-html (0.10.0)
|
74
78
|
thread_safe (0.3.5)
|
@@ -83,11 +87,11 @@ DEPENDENCIES
|
|
83
87
|
andand (~> 1.3)
|
84
88
|
jeweler (~> 2.0)
|
85
89
|
memoizer (~> 1.0)
|
86
|
-
rake (~>
|
90
|
+
rake (~> 11.2)
|
87
91
|
rspec (~> 3.3)
|
88
92
|
rspec-its (~> 1.0)
|
89
|
-
simplecov
|
93
|
+
simplecov
|
90
94
|
yard (~> 0.8.5)
|
91
95
|
|
92
96
|
BUNDLED WITH
|
93
|
-
1.
|
97
|
+
1.13.6
|
data/README.markdown
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/wconrad/usps_intelligent_barcode.png)](https://travis-ci.org/wconrad/usps_intelligent_barcode)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/wconrad/usps_intelligent_barcode.png)](https://codeclimate.com/github/wconrad/usps_intelligent_barcode)
|
5
5
|
|
6
|
-
|
6
|
+
usps_intelligent_barcode is a pure ruby gem to generate a USPS IMB
|
7
7
|
(Intelligent Mail Barcode). More specifically, it generates the
|
8
8
|
string of characters you should print using one of the [USPS
|
9
9
|
Intelligent Barcode
|
@@ -25,7 +25,7 @@ most methods and classes, and eliminated the #draw method.
|
|
25
25
|
#!/usr/bin/env ruby
|
26
26
|
|
27
27
|
require 'rubygems'
|
28
|
-
require '
|
28
|
+
require 'usps_intelligent_barcode'
|
29
29
|
|
30
30
|
barcode_id = '01'
|
31
31
|
service_type = '234'
|
@@ -43,7 +43,9 @@ most methods and classes, and eliminated the #draw method.
|
|
43
43
|
# STANDARD
|
44
44
|
|
45
45
|
This gem is based upon standard
|
46
|
-
[USPS-B-
|
46
|
+
[USPS-B-3200H](https://ribbs.usps.gov/intelligentmail_mailpieces/documents/tech_guides/USPSB3200IntelligentMailBarcode4State.pdf),
|
47
|
+
which is linked to from [Intelligent Mail Barcode for
|
48
|
+
Mailpieces](https://ribbs.usps.gov/index.cfm?page=intellmailmailpieces)
|
47
49
|
|
48
50
|
# RUBY VERSIONS
|
49
51
|
|
@@ -54,6 +56,7 @@ These Ruby versions are supported (these are the rvm platform names):
|
|
54
56
|
* ruby-2.0
|
55
57
|
* ruby-2.1
|
56
58
|
* ruby-2.2
|
59
|
+
* ruby-2.3
|
57
60
|
|
58
61
|
For ruby-1.8.7 please see the deprecated
|
59
62
|
[USPS-intelligent-barcode](https://rubygems.org/gems/USPS-intelligent-barcode)
|
data/Rakefile
CHANGED
@@ -1,40 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
|
5
4
|
require 'bundler'
|
6
5
|
begin
|
7
|
-
Bundler.setup
|
6
|
+
Bundler.setup
|
8
7
|
rescue Bundler::BundlerError => e
|
9
8
|
$stderr.puts e.message
|
10
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
11
10
|
exit e.status_code
|
12
11
|
end
|
13
|
-
require 'rake'
|
14
|
-
|
15
|
-
require 'jeweler'
|
16
|
-
Jeweler::Tasks.new do |gem|
|
17
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
-
gem.name = "usps_intelligent_barcode"
|
19
|
-
gem.homepage = "http://github.com/wconrad/usps_intelligent_barcode"
|
20
|
-
gem.license = "MIT"
|
21
|
-
gem.summary = %Q{Generates a USPS Intelligent Mail Barcode.}
|
22
|
-
gem.description =
|
23
|
-
("A pure Ruby library to generate a USPS Intelligent "\
|
24
|
-
"Mail barcode. It generates the string of characters "\
|
25
|
-
"to print with one of the USPS Intelligent Mail barcode "\
|
26
|
-
"fonts.")
|
27
|
-
gem.email = "wconrad@yagni.com"
|
28
|
-
gem.authors = ["Wayne Conrad"]
|
29
|
-
# dependencies defined in Gemfile
|
30
|
-
end
|
31
|
-
Jeweler::RubygemsDotOrgTasks.new
|
32
|
-
|
33
|
-
require 'rspec/core/rake_task'
|
34
|
-
RSpec::Core::RakeTask.new(:spec)
|
35
|
-
|
36
|
-
task :default => :spec
|
37
12
|
|
38
|
-
|
39
|
-
|
13
|
+
glob = File.join(File.dirname(__FILE__), "rake/*.rb")
|
14
|
+
Dir[glob].sort.each do |path|
|
15
|
+
require path
|
40
16
|
end
|
@@ -4,9 +4,7 @@ require 'usps_intelligent_barcode/character_position'
|
|
4
4
|
|
5
5
|
module Imb
|
6
6
|
|
7
|
-
# Maps intelligent barcode "characters" to
|
8
|
-
# type of bar to print at each given position.
|
9
|
-
|
7
|
+
# Maps intelligent barcode "characters" to the actual barcode.
|
10
8
|
class BarMap
|
11
9
|
|
12
10
|
def initialize
|
@@ -15,9 +13,11 @@ module Imb
|
|
15
13
|
|
16
14
|
# Given an array of intelligent barcode "characters", return an
|
17
15
|
# the symbols for each position.
|
18
|
-
#
|
19
|
-
# @
|
20
|
-
|
16
|
+
#
|
17
|
+
# @param characters [Array<Integer>] array of 13-bit "characters"
|
18
|
+
# between 0 and 1364
|
19
|
+
# @return [Array<BarSymbol>] array of symbols,
|
20
|
+
# e.g. [BarSymbol::TRACKER, BarSymbol::ASCENDER, ...]
|
21
21
|
def symbols(characters)
|
22
22
|
@mapping.map do |bar_position|
|
23
23
|
bar_position.map(characters)
|
@@ -34,8 +34,10 @@ module Imb
|
|
34
34
|
mapping_data.map do |descender, ascender|
|
35
35
|
descender_character_position = CharacterPosition.new(*descender)
|
36
36
|
ascender_character_position = CharacterPosition.new(*ascender)
|
37
|
-
BarPosition.new(
|
38
|
-
|
37
|
+
BarPosition.new(
|
38
|
+
descender_character_position,
|
39
|
+
ascender_character_position,
|
40
|
+
)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -2,14 +2,17 @@ module Imb
|
|
2
2
|
|
3
3
|
# @!group Internal
|
4
4
|
|
5
|
-
# Represents a position (
|
6
|
-
# internal and may change.
|
7
|
-
|
5
|
+
# Represents a position (a vertical bar) in the barcode. This class
|
6
|
+
# is internal and may change.
|
7
|
+
#
|
8
|
+
# Each bar represents two bits, but which two bits it represents is
|
9
|
+
# determined by the "Bar to Character Mapping" table in the
|
10
|
+
# specification (see Table 22, "Bar to Character Mapping", appendix
|
11
|
+
# E) in the specification linked to in the README.
|
8
12
|
class BarPosition
|
9
13
|
|
10
|
-
# @param [CharacterPosition]
|
11
|
-
# @param [CharacterPosition]
|
12
|
-
|
14
|
+
# @param descender_character_position [CharacterPosition]
|
15
|
+
# @param ascender_character_position [CharacterPosition]
|
13
16
|
def initialize(descender_character_position, ascender_character_position)
|
14
17
|
@descender_character_position = descender_character_position
|
15
18
|
@ascender_character_position = ascender_character_position
|
@@ -17,12 +20,13 @@ module Imb
|
|
17
20
|
|
18
21
|
# Given an array of characters, return a symbol for this
|
19
22
|
# barcode position.
|
20
|
-
# @param [
|
23
|
+
# @param characters [Array<Integer>] character codes
|
21
24
|
# @return [BarSymbol] symbol code
|
22
|
-
|
23
25
|
def map(characters)
|
24
|
-
BarSymbol.make(
|
25
|
-
|
26
|
+
BarSymbol.make(
|
27
|
+
ascender_bit(characters),
|
28
|
+
descender_bit(characters),
|
29
|
+
)
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
@@ -2,14 +2,34 @@ module Imb
|
|
2
2
|
|
3
3
|
# @!group Internal
|
4
4
|
|
5
|
-
# Represents a symbol in the barcode.
|
6
|
-
|
5
|
+
# Represents a symbol in the barcode. A symbol encodes two bits,
|
6
|
+
# and is represented as one of four characters to be printed using
|
7
|
+
# one of the USPS Intelligent Barcode fonts. Each character, when
|
8
|
+
# printed using that font, results in a vertical bar having three
|
9
|
+
# part: An ascender, which may be present or missing; a descender,
|
10
|
+
# which may be present or missing; and between the ascender and the
|
11
|
+
# descender, a tracker which is always present.
|
12
|
+
#
|
13
|
+
# This chart shows the bits being encoded (ascender bit, then
|
14
|
+
# descender bit), the code (ASCII character) used for the barcode
|
15
|
+
# font, and an ASCII art repsentation of the bar that is printed by
|
16
|
+
# that code:
|
17
|
+
#
|
18
|
+
# bits: 00 01 10 11
|
19
|
+
#
|
20
|
+
# ascender: | |
|
21
|
+
# tracker: | | | |
|
22
|
+
# descender: | |
|
23
|
+
#
|
24
|
+
# code: T D A F
|
25
|
+
# mnemonic: tracker descender ascender full
|
7
26
|
class BarSymbol
|
8
27
|
|
9
|
-
#
|
10
|
-
#
|
28
|
+
# Return the symbol for a given ascender bit and descender bit.
|
29
|
+
#
|
30
|
+
# @param ascender_bit [Integer] 0 or 1
|
31
|
+
# @param descender_bit [Integer] 0 or 1
|
11
32
|
# @return [BarSymbol]
|
12
|
-
|
13
33
|
def self.make(ascender_bit, descender_bit)
|
14
34
|
case [ascender_bit, descender_bit]
|
15
35
|
when [0, 0]
|
@@ -29,9 +49,12 @@ module Imb
|
|
29
49
|
# @return [String] the letter for this symbol
|
30
50
|
attr_reader :letter
|
31
51
|
|
32
|
-
#
|
33
|
-
#
|
34
|
-
|
52
|
+
# Make an instance.
|
53
|
+
#
|
54
|
+
# @param code [Integer] Binary number from 0b00 to 0b11. Bit 1
|
55
|
+
# controls the ascender; bit 0 controls the descender.
|
56
|
+
# @param letter [String] The character to print in the barcode
|
57
|
+
# font.
|
35
58
|
def initialize(code, letter)
|
36
59
|
@code = code
|
37
60
|
@letter = letter
|
@@ -39,10 +62,17 @@ module Imb
|
|
39
62
|
|
40
63
|
private
|
41
64
|
|
42
|
-
TRACKER = BarSymbol.new(
|
43
|
-
|
44
|
-
|
45
|
-
|
65
|
+
TRACKER = BarSymbol.new(0b00, 'T')
|
66
|
+
private_constant :TRACKER
|
67
|
+
|
68
|
+
DESCENDER = BarSymbol.new(0b01, 'D')
|
69
|
+
private_constant :DESCENDER
|
70
|
+
|
71
|
+
ASCENDER = BarSymbol.new(0b10, 'A')
|
72
|
+
private_constant :ASCENDER
|
73
|
+
|
74
|
+
FULL = BarSymbol.new(0b11, 'F')
|
75
|
+
private_constant :FULL
|
46
76
|
|
47
77
|
end
|
48
78
|
|
@@ -1,3 +1,27 @@
|
|
1
|
+
# Represents the table from the spec. that controls how the bits of
|
2
|
+
# the "characters" are mapped to barcode positions. Each line of this
|
3
|
+
# file represents a single barcode position (or vertical line), with
|
4
|
+
# the leftmost position first.
|
5
|
+
#
|
6
|
+
# Let's decode the first line:
|
7
|
+
#
|
8
|
+
# [
|
9
|
+
# [
|
10
|
+
# 7, # descender character index (0..)
|
11
|
+
# 2, # descender bit number (0..)
|
12
|
+
# ],
|
13
|
+
# [
|
14
|
+
# 4, # ascender character index (0..)
|
15
|
+
# 3, #ascender bit number (0..)
|
16
|
+
# ]
|
17
|
+
# ]
|
18
|
+
#
|
19
|
+
# This means that the first barcode position's ascender is controlled
|
20
|
+
# by bit 2 of character 7; the descender is controlled by bit 3 of
|
21
|
+
# character 4.
|
22
|
+
#
|
23
|
+
# See spec. section 10.0 ("Appendix E -- Tables for Converting
|
24
|
+
# Characters"), Table 22 ("Bar to Character Mapping")
|
1
25
|
---
|
2
26
|
- [[7, 2], [4, 3]]
|
3
27
|
- [[1, 10], [0, 0]]
|