usps_intelligent_barcode 1.0.0 → 1.1.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.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +6 -0
  3. data/.ruby-version +1 -0
  4. data/{CHANGELOG.markdown → CHANGELOG.md} +27 -12
  5. data/Gemfile +2 -16
  6. data/Gemfile.lock +74 -85
  7. data/LICENSE.md +7 -0
  8. data/{README.markdown → README.md} +56 -36
  9. data/VERSION +1 -1
  10. data/doc/font_installation.md +55 -0
  11. data/doc/migration.md +47 -0
  12. data/doc/publishing.md +75 -0
  13. data/examples/example.rb +4 -4
  14. data/examples/generate_pdf.rb +70 -0
  15. data/fonts/LICENSE +47 -0
  16. data/fonts/USPSIMBCompact.ttf +0 -0
  17. data/fonts/USPSIMBStandard.ttf +0 -0
  18. data/lib/usps_intelligent_barcode/barcode.rb +33 -30
  19. data/lib/usps_intelligent_barcode/barcode_id.rb +5 -0
  20. data/lib/usps_intelligent_barcode/mailer_id.rb +6 -1
  21. data/lib/usps_intelligent_barcode/project_dirs.rb +19 -0
  22. data/lib/usps_intelligent_barcode/routing_code.rb +20 -10
  23. data/lib/usps_intelligent_barcode/serial_number.rb +6 -1
  24. data/lib/usps_intelligent_barcode/service_type.rb +6 -1
  25. data/lib/usps_intelligent_barcode/usps_fonts.rb +48 -0
  26. data/lib/usps_intelligent_barcode.rb +2 -0
  27. data/rake/bundler.rb +1 -0
  28. data/rake/version.rb +33 -0
  29. data/rake/yard.rb +1 -0
  30. data/usps_intelligent_barcode.gemspec +24 -97
  31. metadata +67 -46
  32. data/USPS-intelligent-barcode.gemspec +0 -95
  33. data/rake/jeweler.rb +0 -23
  34. data/spec/bar_map_spec.rb +0 -30
  35. data/spec/bar_position_spec.rb +0 -40
  36. data/spec/bar_symbol_spec.rb +0 -39
  37. data/spec/barcode_id_spec.rb +0 -106
  38. data/spec/barcode_spec.rb +0 -213
  39. data/spec/character_position_spec.rb +0 -25
  40. data/spec/codeword_map_spec.rb +0 -22
  41. data/spec/crc_spec.rb +0 -21
  42. data/spec/mailer_id_spec.rb +0 -124
  43. data/spec/numeric_conversions_spec.rb +0 -23
  44. data/spec/routing_code_spec.rb +0 -180
  45. data/spec/serial_number_spec.rb +0 -117
  46. data/spec/service_type_spec.rb +0 -93
  47. data/spec/spec_helper.rb +0 -9
data/spec/barcode_spec.rb DELETED
@@ -1,213 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe Barcode do
6
-
7
- let(:barcode) do
8
- Barcode.new(barcode_id,
9
- service_type,
10
- mailer_id,
11
- serial_number,
12
- routing_code)
13
- end
14
- subject {barcode}
15
-
16
- describe 'Examples from USPS-B-3200 rev. G, Appendix B' do
17
-
18
- describe '#1' do
19
-
20
- let(:barcode_id) {'01'}
21
- let(:service_type) {'234'}
22
- let(:mailer_id) {'567094'}
23
- let(:serial_number) {'987654321'}
24
- let(:routing_code) {nil}
25
-
26
- its(:binary_data) {should == 0x00000000001122103B5C2004B1}
27
- its(:frame_check_sequence) {should == 0x051}
28
- its(:codewords) do
29
- should == [0, 0, 0, 0, 559, 202, 508, 451, 124, 17]
30
- end
31
- its(:codewords_with_orientation_in_character_j) do
32
- should == [0, 0, 0, 0, 559, 202, 508, 451, 124, 34]
33
- end
34
- its(:codewords_with_fcs_bit_in_character_a) do
35
- should == [0, 0, 0, 0, 559, 202, 508, 451, 124, 34]
36
- end
37
- its(:characters) do
38
- should == [
39
- 0x001F, 0x001F, 0x001F, 0x001F, 0x1524,
40
- 0x01A3, 0x043C, 0x1838, 0x012B, 0x0076,
41
- ]
42
- end
43
- its(:characters_with_fcs_bits_0_through_9) do
44
- should == [
45
- 0x1FE0, 0x001F, 0x001F, 0x001F, 0x0ADB,
46
- 0x01A3, 0x1BC3, 0x1838, 0x012B, 0x0076,
47
- ]
48
- end
49
- its(:barcode_letters) do
50
- should == ('ATTFATTDTTADTAATTDTDTATTDAFDDFADF'\
51
- 'DFTFFFFFTATFAAAATDFFTDAADFTFDTDT')
52
- end
53
-
54
- end
55
-
56
- describe '#2' do
57
-
58
- let(:barcode_id) {'01'}
59
- let(:service_type) {'234'}
60
- let(:mailer_id) {'567094'}
61
- let(:serial_number) {'987654321'}
62
- let(:routing_code) {'01234'}
63
-
64
- its(:binary_data) {should == 0x0000000D138A87BAB5CF3804B1}
65
- its(:frame_check_sequence) {should == 0x065}
66
- its(:codewords) do
67
- should == [0, 0, 15, 14, 290, 567, 385, 48, 388, 333]
68
- end
69
- its(:codewords_with_orientation_in_character_j) do
70
- should == [0, 0, 15, 14, 290, 567, 385, 48, 388, 666]
71
- end
72
- its(:codewords_with_fcs_bit_in_character_a) do
73
- should == [0, 0, 15, 14, 290, 567, 385, 48, 388, 666]
74
- end
75
- its(:characters) do
76
- should == [
77
- 0x001F, 0x001F, 0x1D40, 0x0057, 0x0255,
78
- 0x0724, 0x04E8, 0x009D, 0x030B, 0x0583,
79
- ]
80
- end
81
- its(:characters_with_fcs_bits_0_through_9) do
82
- should == [
83
- 0x1FE0, 0x001F, 0x02BF, 0x0057, 0x0255,
84
- 0x18DB, 0x1B17, 0x009D, 0x030B, 0x0583,
85
- ]
86
- end
87
- its(:barcode_letters) do
88
- should == ('DTTAFADDTTFTDTFTFDTDDADADAFADFATD'\
89
- 'DFTAAAFDTTADFAAATDFDTDFADDDTDFFT')
90
- end
91
-
92
- end
93
-
94
- describe '#3' do
95
-
96
- let(:barcode_id) {'01'}
97
- let(:service_type) {'234'}
98
- let(:mailer_id) {'567094'}
99
- let(:serial_number) {'987654321'}
100
- let(:routing_code) {'012345678'}
101
-
102
- its(:binary_data) {should == 0x000202BDC097711204D21804B1}
103
- its(:frame_check_sequence) {should == 0x606}
104
- its(:codewords) do
105
- should == [0, 110, 1113, 1363, 198, 413, 470, 468, 1333, 513]
106
- end
107
- its(:codewords_with_orientation_in_character_j) do
108
- should == [0, 110, 1113, 1363, 198, 413, 470, 468, 1333, 1026]
109
- end
110
- its(:codewords_with_fcs_bit_in_character_a) do
111
- should == [659, 110, 1113, 1363, 198, 413, 470, 468, 1333, 1026]
112
- end
113
- its(:characters) do
114
- should == [
115
- 0x1154, 0x00F8, 0x1E01, 0x0110, 0x019A,
116
- 0x1298, 0x03A2, 0x03A1, 0x0084, 0x0B11,
117
- ]
118
- end
119
- its(:characters_with_fcs_bits_0_through_9) do
120
- should == [
121
- 0x1154, 0x1F07, 0x01FE, 0x0110, 0x019A,
122
- 0x1298, 0x03A2, 0x03A1, 0x0084, 0x14EE,
123
- ]
124
- end
125
- its(:barcode_letters) do
126
- should == ('ADFTTAFDTTTTFATTADTAAATFTFTATDAAA'\
127
- 'FDDADATATDTDTTDFDTDATADADTDFFTFA')
128
- end
129
-
130
- end
131
-
132
- describe '#4' do
133
-
134
- let(:barcode_id) {'01'}
135
- let(:service_type) {'234'}
136
- let(:mailer_id) {'567094'}
137
- let(:serial_number) {'987654321'}
138
- let(:routing_code) {'01234567891'}
139
-
140
- its(:binary_data) {should == 0x016907B2A24ABC16A2E5C004B1}
141
- its(:frame_check_sequence) {should == 0x751}
142
- its(:codewords) do
143
- should == [14, 787, 607, 1022, 861, 19, 816, 1294, 35, 301]
144
- end
145
- its(:codewords_with_orientation_in_character_j) do
146
- should == [14, 787, 607, 1022, 861, 19, 816, 1294, 35, 602]
147
- end
148
- its(:codewords_with_fcs_bit_in_character_a) do
149
- should == [673, 787, 607, 1022, 861, 19, 816, 1294, 35, 602]
150
- end
151
- its(:characters) do
152
- should == [
153
- 0x1234, 0x085C, 0x08E4, 0x0B06, 0x1922,
154
- 0x1740, 0x0839, 0x1200, 0x0DC0, 0x04D4,
155
- ]
156
- end
157
- its(:characters_with_fcs_bits_0_through_9) do
158
- should == [
159
- 0x0DCB, 0x085C, 0x08E4, 0x0B06, 0x06DD,
160
- 0x1740, 0x17C6, 0x1200, 0x123F, 0x1B2B,
161
- ]
162
- end
163
- its(:barcode_letters) do
164
- should == ('AADTFFDFTDADTAADAATFDTDDAAADDTDTT'\
165
- 'DAFADADDDTFFFDDTTTADFAAADFTDAADA')
166
- end
167
-
168
- end
169
-
170
- end
171
-
172
- describe '#accessors' do
173
-
174
- let(:barcode) do
175
- Barcode.new(barcode_id,
176
- service_type,
177
- mailer_id,
178
- serial_number,
179
- routing_code)
180
- end
181
- subject {barcode}
182
-
183
- context 'when constructed with strings' do
184
- let(:barcode_id) {'01'}
185
- let(:service_type) {'234'}
186
- let(:mailer_id) {'567094'}
187
- let(:serial_number) {'987654321'}
188
- let(:routing_code) {'98765432109'}
189
- its(:barcode_id) {should == 1}
190
- its(:service_type) {should == 234}
191
- its(:mailer_id) {should == 567094}
192
- its(:serial_number) {should == 987654321}
193
- its(:routing_code) {should == RoutingCode.new(98765, 4321, 9)}
194
- end
195
-
196
- context 'when constructed with integers' do
197
- let(:barcode_id) {01}
198
- let(:service_type) {234}
199
- let(:mailer_id) {567094}
200
- let(:serial_number) {987654321}
201
- let(:routing_code) {[98765, 4321, 9]}
202
- its(:barcode_id) {should == 1}
203
- its(:service_type) {should == 234}
204
- its(:mailer_id) {should == 567094}
205
- its(:serial_number) {should == 987654321}
206
- its(:routing_code) {should == RoutingCode.new(98765, 4321, 9)}
207
- end
208
-
209
- end
210
-
211
- end
212
-
213
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe CharacterPosition do
6
-
7
- describe '#extract_bit_from_characters' do
8
-
9
- let(:characters) {[1, 2]}
10
-
11
- def extract(character_index, bit_number)
12
- CharacterPosition.new(character_index, bit_number)\
13
- .extract_bit_from_characters(characters)
14
- end
15
-
16
- specify {expect(extract(0, 0)).to eq(1)}
17
- specify {expect(extract(0, 1)).to eq(0)}
18
- specify {expect(extract(1, 0)).to eq(0)}
19
- specify {expect(extract(1, 1)).to eq(1)}
20
-
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,22 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe CodewordMap do
6
-
7
- let(:characters) do
8
- [
9
- 0x001F, 0x001F, 0x001F, 0x001F, 0x1524,
10
- 0x01A3, 0x043C, 0x1838, 0x012B, 0x0076,
11
- ]
12
- end
13
- let(:codewords) {[0, 0, 0, 0, 559, 202, 508, 451, 124, 34]}
14
- let(:codeword_map) {CodewordMap.new}
15
-
16
- specify do
17
- expect(codeword_map.characters(codewords)).to eq(characters)
18
- end
19
-
20
- end
21
-
22
- end
data/spec/crc_spec.rb DELETED
@@ -1,21 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe Crc do
6
-
7
- describe '#crc' do
8
-
9
- specify do
10
- expect(Crc.new.crc(0x016907B2A24ABC16A2E5C004B1)).to eq(0x751)
11
- end
12
-
13
- specify do
14
- expect(Crc.new.crc(0)).to eq(0x6e0)
15
- end
16
-
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,124 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe MailerId do
6
-
7
- describe '::coerce' do
8
-
9
- subject {MailerId.coerce(o)}
10
-
11
- context 'MailerId' do
12
- let(:o) {MailerId.new(12)}
13
- its(:to_i) {should == 12}
14
- end
15
-
16
- context 'String' do
17
- let(:o) {'12'}
18
- its(:to_i) {should == 12}
19
- end
20
-
21
- context 'Integer' do
22
- let(:o) {12}
23
- its(:to_i) {should == 12}
24
- end
25
-
26
- context 'unknown' do
27
- let(:o) {Object.new}
28
- specify do
29
- expect {
30
- MailerId.coerce(o)
31
- }.to raise_error ArgumentError, 'Cannot coerce to MailerId'
32
- end
33
- end
34
-
35
- end
36
-
37
- describe '#to_i' do
38
- let(:value) {23}
39
- subject {MailerId.new(value)}
40
- its(:to_i) {should == value}
41
- end
42
-
43
- describe '#=' do
44
- def o1 ; MailerId.new(1) ; end
45
- def o2 ; 1 ; end
46
- def o3 ; MailerId.new(2) ; end
47
- def o4 ; Object.new ; end
48
- specify {expect(o1).to eq(o1)}
49
- specify {expect(o1).to eq(o2)}
50
- specify {expect(o1).not_to eq(o3)}
51
- specify {expect(o1).not_to eq(o4)}
52
- end
53
-
54
- describe '#validate' do
55
-
56
- let(:long_mailer_id?) {double 'long_mailer_id?'}
57
-
58
- def validate(value)
59
- MailerId.new(value).validate(long_mailer_id?)
60
- end
61
-
62
- def self.is_valid(value)
63
- context "#{value}" do
64
- specify {validate(value)}
65
- end
66
- end
67
-
68
- def self.is_out_of_range(value)
69
- context "#{value}" do
70
- specify do
71
- expect {
72
- validate(value)
73
- }.to raise_error(ArgumentError,
74
- 'Must be 0..899999 or 900000000..999999999')
75
- end
76
- end
77
- end
78
-
79
- is_out_of_range -1
80
- is_valid 0
81
- is_valid 899_999
82
- is_out_of_range 1_000_000
83
- is_out_of_range 899_999_999
84
- is_valid 900_000_000
85
- is_valid 999_999_999
86
- is_out_of_range 1_000_000_000
87
-
88
- end
89
-
90
- describe '#long?' do
91
-
92
- subject {MailerId.new(value)}
93
-
94
- context 'short' do
95
- let(:value) {0}
96
- its(:long?) {should be_falsey}
97
- end
98
-
99
- context 'long' do
100
- let(:value) {900_000_000}
101
- its(:long?) {should be_truthy}
102
- end
103
-
104
- end
105
-
106
- describe '#shift_and_add_to' do
107
-
108
- context 'short' do
109
- let(:mailer_id) {MailerId.new(999999)}
110
- let(:long_mailer_id?) {false}
111
- specify {expect(mailer_id.shift_and_add_to(1, long_mailer_id?)).to eq(1999999)}
112
- end
113
-
114
- context 'long' do
115
- let(:mailer_id) {MailerId.new(999999999)}
116
- let(:long_mailer_id?) {true}
117
- specify {expect(mailer_id.shift_and_add_to(1, long_mailer_id?)).to eq(1999999999)}
118
- end
119
-
120
- end
121
-
122
- end
123
-
124
- end
@@ -1,23 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe NumericConversions do
6
-
7
- include NumericConversions
8
-
9
- describe '#numeric_to_bytes' do
10
-
11
- specify do
12
- expect(numeric_to_bytes(0x1234)).to eq([0x12, 0x34])
13
- end
14
-
15
- specify do
16
- expect(numeric_to_bytes(0x1234, 3)).to eq([0, 0x12, 0x34])
17
- end
18
-
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,180 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- module Imb
4
-
5
- describe RoutingCode do
6
-
7
- describe '::coerce' do
8
-
9
- let(:zip) {85308}
10
- let(:plus4) {1465}
11
- let(:delivery_point) {12}
12
-
13
- subject {RoutingCode.coerce(o)}
14
-
15
- shared_examples 'coerces' do
16
- its(:zip) {should == zip}
17
- its(:plus4) {should == plus4}
18
- its(:delivery_point) {should == delivery_point}
19
- end
20
-
21
- context 'RoutingCode' do
22
- let(:o) {RoutingCode.new(zip, plus4, delivery_point)}
23
- it_behaves_like 'coerces'
24
- end
25
-
26
- context 'nil' do
27
- let(:o) {nil}
28
- let(:zip) {nil}
29
- let(:plus4) {nil}
30
- let(:delivery_point) {nil}
31
- it_behaves_like 'coerces'
32
- end
33
-
34
- context 'string' do
35
-
36
- let(:o) {"#{zip}#{plus4}#{delivery_point}"}
37
-
38
- context 'empty' do
39
- let(:zip) {nil}
40
- let(:plus4) {nil}
41
- let(:delivery_point) {nil}
42
- it_behaves_like 'coerces'
43
- end
44
-
45
- context "zip, plu4, delivery_point" do
46
- it_behaves_like 'coerces'
47
- end
48
-
49
- end
50
-
51
- context 'array' do
52
- let(:o) {[zip, plus4, delivery_point]}
53
- it_behaves_like 'coerces'
54
- end
55
-
56
- context 'unrecognized' do
57
- let(:o) {Object.new}
58
- specify do
59
- expect {
60
- RoutingCode.coerce(o)
61
- }.to raise_error ArgumentError, 'Cannot coerce to RoutingCode'
62
- end
63
- end
64
-
65
- end
66
-
67
- describe '#string_to_array' do
68
-
69
- subject(:array) {RoutingCode.string_to_array(s)}
70
-
71
- context 'empty' do
72
- let(:s) {''}
73
- it {is_expected.to eq([nil, nil, nil])}
74
- end
75
-
76
- context 'zip' do
77
- let(:s) {'85308'}
78
- it {is_expected.to eq(['85308', nil, nil])}
79
- end
80
-
81
- context 'zip, plus4' do
82
- let(:s) {'853081465'}
83
- it {is_expected.to eq(['85308', '1465', nil])}
84
- end
85
-
86
- context 'zip, plu4, delivery_point' do
87
- let(:s) {'85308146502'}
88
- it {is_expected.to eq(['85308', '1465', '02'])}
89
- end
90
-
91
- context 'non-digits' do
92
- let(:s) {'(85308 1465 02)'}
93
- it {is_expected.to eq(['85308', '1465', '02'])}
94
- end
95
-
96
- context 'incorrect length' do
97
- let(:s) {'1'}
98
- specify do
99
- expect {
100
- array
101
- }.to raise_error ArgumentError, 'Bad routing code: "1"'
102
- end
103
- end
104
-
105
- end
106
-
107
- describe '#convert' do
108
-
109
- subject do
110
- RoutingCode.new(zip, plus4, delivery_point)
111
- end
112
-
113
- context 'empty' do
114
- let(:zip) {nil}
115
- let(:plus4) {nil}
116
- let(:delivery_point) {nil}
117
- its(:convert) {should == 0}
118
- end
119
-
120
- context 'zip' do
121
- let(:zip) {85308}
122
- let(:plus4) {nil}
123
- let(:delivery_point) {nil}
124
- its(:convert) {should == 85309}
125
- end
126
-
127
- context 'zip, plus4' do
128
- let(:zip) {85308}
129
- let(:plus4) {1465}
130
- let(:delivery_point) {nil}
131
- its(:convert) {should == 853181466}
132
- end
133
-
134
- context 'zip, plus4, delivery_point' do
135
- let(:zip) {85308}
136
- let(:plus4) {1465}
137
- let(:delivery_point) {2}
138
- its(:convert) {should == 86308246503}
139
- end
140
-
141
- end
142
-
143
- describe '#to_a' do
144
- let(:zip) {85308}
145
- let(:plus4) {1465}
146
- let(:delivery_point) {2}
147
- subject {RoutingCode.new(zip, plus4, delivery_point)}
148
- its(:to_a) {should == [zip, plus4, delivery_point]}
149
- end
150
-
151
- describe '#==' do
152
- def o1 ; RoutingCode.new(85308, 1465, 1) ; end
153
- def o2 ; [85308, 1465, 1] ; end
154
- def o3 ; RoutingCode.new(85308, 1465, 2) ; end
155
- def o4 ; RoutingCode.new(85308, 1466, 1) ; end
156
- def o5 ; RoutingCode.new(85309, 1465, 1) ; end
157
- def o6 ; Object.new ; end
158
- specify {expect(o1).to eq(o1)}
159
- specify {expect(o1).to eq(o2)}
160
- specify {expect(o1).not_to eq(o3)}
161
- specify {expect(o1).not_to eq(o4)}
162
- specify {expect(o1).not_to eq(o5)}
163
- specify {expect(o1).not_to eq(o6)}
164
- end
165
-
166
- describe '#validate' do
167
- let(:routing_code) {RoutingCode.new(nil, nil, nil)}
168
- let(:long_mailer_id?) {double 'long_mailer_id?'}
169
- specify {routing_code.validate(long_mailer_id?)}
170
- end
171
-
172
- describe '#shift_and_add_to' do
173
- let(:routing_code) {RoutingCode.new(85308, 1465, 2)}
174
- let(:long_mailer_id?) {double 'long mailer id'}
175
- specify {expect(routing_code.shift_and_add_to(1, long_mailer_id?)).to eq(186308246503)}
176
- end
177
-
178
- end
179
-
180
- end