Sha256: 5c5ff03eeaf2bb3823235fa541395af6e1bea644778ee8060e49f52c26c9aa04

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Imb

  # @!group Internal

  # Represents a position (one line) in the barcode.  This class is
  # internal and may change.

  class BarPosition

    # @param [CharacterPosition] descender_character_position
    # @param [CharacterPosition] ascender_character_position

    def initialize(descender_character_position, ascender_character_position)
      @descender_character_position = descender_character_position
      @ascender_character_position = ascender_character_position
    end

    # Given an array of characters, return a symbol code for this
    # barcode position.  The symbol codes are:
    # * 0 - tracking mark (neither ascending nor descending)
    # * 1 - descending mark
    # * 2 - ascending mark
    # * 3 - full mark (both ascending and descending)
    # @param [[Integer]] characters character codes
    # @return [Integer] symbol code

    def map(characters)
      2 * ascender_bit(characters) + descender_bit(characters)
    end

    private

    def descender_bit(characters)
      @descender_character_position.extract_bit_from_characters(characters)
    end

    def ascender_bit(characters)
      @ascender_character_position.extract_bit_from_characters(characters)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
USPS-intelligent-barcode-0.2.3 lib/USPS-intelligent-barcode/BarPosition.rb