USPS-intelligent-barcode 0.2.0 → 0.2.1

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.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "USPS-intelligent-barcode"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wayne Conrad"]
12
- s.date = "2012-12-27"
12
+ s.date = "2012-12-28"
13
13
  s.description = "A pure Ruby gem to generate a USPS Intelligent Mail barcode. It generates the string of characters to print with one of the USPS Intelligent Mail barcode fonts."
14
14
  s.email = "wayne@databill.com"
15
15
  s.extra_rdoc_files = [
@@ -38,7 +38,6 @@ Gem::Specification.new do |s|
38
38
  "lib/USPS-intelligent-barcode/RoutingCode.rb",
39
39
  "lib/USPS-intelligent-barcode/SerialNumber.rb",
40
40
  "lib/USPS-intelligent-barcode/ServiceType.rb",
41
- "lib/USPS-intelligent-barcode/autoload.rb",
42
41
  "lib/USPS-intelligent-barcode/bar_to_character_mapping.yml",
43
42
  "lib/USPS-intelligent-barcode/codeword_to_character_mapping.yml",
44
43
  "spec/BarMap_spec.rb",
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -2,4 +2,15 @@ require 'andand'
2
2
  require 'memoizer'
3
3
  require 'yaml'
4
4
 
5
- require 'USPS-intelligent-barcode/autoload.rb'
5
+ require 'USPS-intelligent-barcode/BarMap'
6
+ require 'USPS-intelligent-barcode/BarPosition'
7
+ require 'USPS-intelligent-barcode/Barcode'
8
+ require 'USPS-intelligent-barcode/BarcodeId'
9
+ require 'USPS-intelligent-barcode/CharacterPosition'
10
+ require 'USPS-intelligent-barcode/CodewordMap'
11
+ require 'USPS-intelligent-barcode/Crc'
12
+ require 'USPS-intelligent-barcode/MailerId'
13
+ require 'USPS-intelligent-barcode/NumericConversions'
14
+ require 'USPS-intelligent-barcode/RoutingCode'
15
+ require 'USPS-intelligent-barcode/SerialNumber'
16
+ require 'USPS-intelligent-barcode/ServiceType'
@@ -1,11 +1,26 @@
1
+ require 'USPS-intelligent-barcode/CharacterPosition'
2
+
1
3
  module Imb
2
4
 
5
+ # Maps intelligent barcode "characters" to codes that indicate what
6
+ # type of bar to print at each given position. This class is
7
+ # internal and may change.
8
+
3
9
  class BarMap
4
10
 
11
+ # Create.
12
+
5
13
  def initialize
6
14
  @mapping = load_mapping
7
15
  end
8
16
 
17
+ # Given an array of intelligent barcode "characters", return an
18
+ # array of codes for each barcode position. The codes are:
19
+ # * 0 - tracking mark (neither ascending nor descending)
20
+ # * 1 - descending mark
21
+ # * 2 - ascending mark
22
+ # * 3 - full mark (both ascending and descending)
23
+
9
24
  def barcode(characters)
10
25
  @mapping.map do |bar_position|
11
26
  bar_position.map(characters)
@@ -1,12 +1,26 @@
1
1
  module Imb
2
2
 
3
+ # Represents a position (one line) in the barcode. This class is
4
+ # internal and may change.
5
+
3
6
  class BarPosition
4
7
 
8
+ # Create.
9
+ # * +descender_character_position+ - the CharacterPosition for the descender
10
+ # * +ascender_character_position* - the CharacterPosition for the ascender
11
+
5
12
  def initialize(descender_character_position, ascender_character_position)
6
13
  @descender_character_position = descender_character_position
7
14
  @ascender_character_position = ascender_character_position
8
15
  end
9
16
 
17
+ # Given an array of characters, return a code for this barcode
18
+ # position. The codes are:
19
+ # * 0 - tracking mark (neither ascending nor descending)
20
+ # * 1 - descending mark
21
+ # * 2 - ascending mark
22
+ # * 3 - full mark (both ascending and descending)
23
+
10
24
  def map(characters)
11
25
  2 * ascender_bit(characters) + descender_bit(characters)
12
26
  end
@@ -1,8 +1,11 @@
1
+ require 'USPS-intelligent-barcode/CodewordMap'
2
+
1
3
  # The namespace for everything in this gem.
2
4
 
3
5
  module Imb
4
6
 
5
- # This class represents a barcode
7
+ # This class represents a barcode. It is the main class: you will
8
+ # probably seldom need to touch any of the others.
6
9
 
7
10
  class Barcode
8
11
 
@@ -1,12 +1,19 @@
1
1
  module Imb
2
2
 
3
+ # Represents the position of one bit in the array of intelligent
4
+ # barcode "characters". This class is internal and may change.
5
+
3
6
  class CharacterPosition
4
7
 
8
+ # Create.
9
+
5
10
  def initialize(character_index, bit_number)
6
11
  @character_index = character_index
7
12
  @bit_number = bit_number
8
13
  end
9
14
 
15
+ # Given an array of characters, return the bit for this position.
16
+
10
17
  def extract_bit_from_characters(characters)
11
18
  characters[@character_index][@bit_number]
12
19
  end
@@ -1,11 +1,18 @@
1
1
  module Imb
2
2
 
3
+ # Maps codewords to characters. This class is internal and may
4
+ # change.
5
+
3
6
  class CodewordMap
4
7
 
8
+ # Constructor
9
+
5
10
  def initialize
6
11
  @characters = load_characters
7
12
  end
8
13
 
14
+ # Given an array of codewords, ruturn their characters.
15
+
9
16
  def characters(codewords)
10
17
  codewords.map do |codeword|
11
18
  @characters[codeword]
@@ -1,9 +1,16 @@
1
+ require 'USPS-intelligent-barcode/NumericConversions'
2
+
1
3
  module Imb
2
4
 
5
+ # Calculates the Intelligent Mail Barcode CRC. This class is
6
+ # internal and may change.
7
+
3
8
  class Crc
4
9
 
5
10
  extend NumericConversions
6
-
11
+
12
+ # Calculate a CRC. +binary_data+ on an Integer.
13
+
7
14
  def self.crc(binary_data)
8
15
  crc = MASK
9
16
  bytes = numeric_to_bytes(binary_data, NUM_INPUT_BYTES)
@@ -16,6 +23,8 @@ module Imb
16
23
 
17
24
  private
18
25
 
26
+ # :stopdoc:
27
+
19
28
  LEADING_BITS_TO_IGNORE = 2
20
29
  CRC_BITS = 11
21
30
  CRC_MSB_MASK = 1 << (CRC_BITS - 1)
@@ -24,6 +33,8 @@ module Imb
24
33
  MASK = (1 << CRC_BITS) - 1
25
34
  NUM_INPUT_BYTES = 13
26
35
 
36
+ # :startdoc:
37
+
27
38
  def self.crc_byte(crc, byte, leading_bits_to_ignore)
28
39
  num_bits = BITS_PER_BYTE - leading_bits_to_ignore
29
40
  data = byte << CRC_BITS - BITS_PER_BYTE + leading_bits_to_ignore
@@ -1,7 +1,11 @@
1
1
  module Imb
2
2
 
3
+ # Numeric conversions This class is internal and may change.
4
+
3
5
  module NumericConversions
4
6
 
7
+ # Convert a numberic to an array of at least +min_bytes+ bytes.
8
+
5
9
  def numeric_to_bytes(n, min_bytes=0)
6
10
  n.to_s(16).rjust(2 * min_bytes, '0').scan(/../).map do |s|
7
11
  s.to_i(16)
@@ -1,5 +1,7 @@
1
1
  module Imb
2
2
 
3
+ # Represents a routing code
4
+
3
5
  class RoutingCode
4
6
 
5
7
  # Turn the argument into a RoutingCode if possible. Accepts:
@@ -1,5 +1,7 @@
1
1
  module Imb
2
2
 
3
+ # This class represents a service type.
4
+
3
5
  class ServiceType
4
6
 
5
7
  # The valid range of a service type
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: USPS-intelligent-barcode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Wayne Conrad
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-27 00:00:00 Z
18
+ date: 2012-12-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: andand
@@ -108,7 +108,6 @@ files:
108
108
  - lib/USPS-intelligent-barcode/RoutingCode.rb
109
109
  - lib/USPS-intelligent-barcode/SerialNumber.rb
110
110
  - lib/USPS-intelligent-barcode/ServiceType.rb
111
- - lib/USPS-intelligent-barcode/autoload.rb
112
111
  - lib/USPS-intelligent-barcode/bar_to_character_mapping.yml
113
112
  - lib/USPS-intelligent-barcode/codeword_to_character_mapping.yml
114
113
  - spec/BarMap_spec.rb
@@ -1,61 +0,0 @@
1
- # class Autoload courtesy of www.databill.com
2
-
3
- class Autoload
4
-
5
- def self.setup(*args)
6
- new(*args).setup
7
- end
8
-
9
- def initialize(namespace, path)
10
- @namespace = namespace
11
- @path = path
12
- end
13
-
14
- def setup
15
- autoload_classes_and_modules
16
- require_utilities
17
- end
18
-
19
- private
20
-
21
- def require_utilities
22
- utility_paths.each do |path|
23
- require File.expand_path(path)
24
- end
25
- end
26
-
27
- def autoload_classes_and_modules
28
- class_and_module_paths.each do |path|
29
- module_name = File.basename(path).chomp('.rb')
30
- @namespace.instance_eval do
31
- autoload(module_name, File.expand_path(path))
32
- end
33
- end
34
- end
35
-
36
- def utility_paths
37
- ruby_paths - class_and_module_paths - [@path]
38
- end
39
-
40
- def ruby_paths
41
- dirname = File.directory?(@path) ? @path : File.dirname(@path)
42
- paths = Dir[File.join(dirname, '*.rb')]
43
- paths.reject do |path|
44
- File.basename(path) == File.basename(@path)
45
- end
46
- # Force require statements to happen in a random order to discover
47
- # missing direct dependencies
48
- paths.sort_by {rand}
49
- end
50
-
51
- def class_and_module_paths
52
- ruby_paths.find_all do |path|
53
- File.basename(path) =~ /[A-Z]/
54
- end
55
- end
56
-
57
- end
58
-
59
- module Imb ; end
60
-
61
- Autoload.setup(Imb, __FILE__)