Sha256: 2c02f1145198ccc40b6bcd160bd8ece68c5fc423fa027a0d11594a5a276f891c

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Imb

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

  class BarPosition

    # Create.
    # * +descender_character_position+ - the CharacterPosition for the descender
    # * +ascender_character_position* - the CharacterPosition for the ascender

    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 code for this barcode
    # position.  The codes are:
    # * 0 - tracking mark (neither ascending nor descending)
    # * 1 - descending mark
    # * 2 - ascending mark
    # * 3 - full mark (both ascending and descending)

    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

2 entries across 2 versions & 1 rubygems

Version Path
USPS-intelligent-barcode-0.2.2 lib/USPS-intelligent-barcode/BarPosition.rb
USPS-intelligent-barcode-0.2.1 lib/USPS-intelligent-barcode/BarPosition.rb