class Imb::BarPosition

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.

Public Class Methods

new(descender_character_position, ascender_character_position) click to toggle source

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

# File lib/usps_intelligent_barcode/bar_position.rb, line 16
def initialize(descender_character_position, ascender_character_position)
  @descender_character_position = descender_character_position
  @ascender_character_position = ascender_character_position
end

Public Instance Methods

map(characters) click to toggle source

Given an array of characters, return a symbol for this barcode position. @param characters [Array<Integer>] character codes @return [BarSymbol] symbol code

# File lib/usps_intelligent_barcode/bar_position.rb, line 25
def map(characters)
  BarSymbol.make(
    ascender_bit(characters),
    descender_bit(characters),
  )
end

Private Instance Methods

ascender_bit(characters) click to toggle source
# File lib/usps_intelligent_barcode/bar_position.rb, line 38
def ascender_bit(characters)
  @ascender_character_position.extract_bit_from_characters(characters)
end
descender_bit(characters) click to toggle source
# File lib/usps_intelligent_barcode/bar_position.rb, line 34
def descender_bit(characters)
  @descender_character_position.extract_bit_from_characters(characters)
end