Sha256: 9c481b6bf4400c38e4878c9f0a96bdda5a41032e5b1f65400074054b4f80aa16

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Imb

  # @!group Internal

  # Represents a position (a vertical bar) in the barcode.  This class
  # is internal and may change.
  #
  # Each bar represents two bits, but which two bits it represents is
  # determined by the "Bar to Character Mapping" table in the
  # specification (see Table 22, "Bar to Character Mapping", appendix
  # E) in the specification linked to in the README.
  class BarPosition

    # @param descender_character_position [CharacterPosition]
    # @param ascender_character_position [CharacterPosition]
    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 for this
    # barcode position.
    # @param characters [Array<Integer>] character codes
    # @return [BarSymbol] symbol code
    def map(characters)
      BarSymbol.make(
        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-1.0.0 lib/usps_intelligent_barcode/bar_position.rb