Sha256: dcfdff79d4126ebd72e31cf5aa212f9db869e9cafa563eb1e95b3ad9cb105fe4

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'usps_intelligent_barcode/character_position'

# @!group Internal

module Imb

  # Maps intelligent barcode "characters" to the actual barcode.
  class BarMap

    def initialize
      @mapping = load_mapping
    end

    # Given an array of intelligent barcode "characters", return an
    # the symbols for each position.
    #
    # @param characters [Array<Integer>] array of 13-bit "characters"
    #   between 0 and 1364
    # @return [Array<BarSymbol>] array of symbols,
    #   e.g. [BarSymbol::TRACKER, BarSymbol::ASCENDER, ...]
    def symbols(characters)
      @mapping.map do |bar_position|
        bar_position.map(characters)
      end
    end

    private

    def load_mapping
      convert_mapping_data(load_mapping_data)
    end

    def convert_mapping_data(mapping_data)
      mapping_data.map do |descender, ascender|
        descender_character_position = CharacterPosition.new(*descender)
        ascender_character_position = CharacterPosition.new(*ascender)
        BarPosition.new(
          descender_character_position,
          ascender_character_position,
        )
      end
    end

    def load_mapping_data
      YAML.load_file(mapping_path)
    end

    def mapping_path
      File.expand_path('bar_to_character_mapping.yml', File.dirname(__FILE__))
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
usps_intelligent_barcode-1.0.0 lib/usps_intelligent_barcode/bar_map.rb