Class: Imb::Barcode

Inherits:
Object
  • Object
show all
Includes:
Memoizer
Defined in:
lib/USPS-intelligent-barcode/barcode.rb

Overview

This class represents a barcode.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode_id, service_type, mailer_id, serial_number, routing_code) ⇒ Barcode

Create a new barcode

Parameters:

  • barcode_id (String)

    Nominally a String, but can be anything that Imb::BarcodeId.coerce will accept.

  • service_type (String)

    Nominally a String, but can be anything that ServiceType.coerce will accept.

  • mailer_id (String)

    Nominally a String, but can be anything that MailerId.coerce will accept.

  • serial_number (String)

    Nominally a String, but can be anything that SerialNumber.coerce will accept.

  • routing_code (String)

    Nominally a String, but can be anything that RoutingCode.coerce will accept.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 44

def initialize(barcode_id,
               service_type,
               mailer_id,
               serial_number,
               routing_code)
  @barcode_id = BarcodeId.coerce(barcode_id)
  @service_type = ServiceType.coerce(service_type)
  @mailer_id = MailerId.coerce(mailer_id)
  @serial_number = SerialNumber.coerce(serial_number)
  @routing_code = RoutingCode.coerce(routing_code)
  validate_components
end

Instance Attribute Details

#barcode_idBarcodeId (readonly)

Returns:



15
16
17
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 15

def barcode_id
  @barcode_id
end

#mailer_idMailerId (readonly)

Returns:



21
22
23
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 21

def mailer_id
  @mailer_id
end

#routing_codeRoutingCode (readonly)

Returns:



27
28
29
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 27

def routing_code
  @routing_code
end

#serial_numberSerialNumber (readonly)

Returns:



24
25
26
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 24

def serial_number
  @serial_number
end

#service_typeServiceType (readonly)

Returns:



18
19
20
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 18

def service_type
  @service_type
end

Instance Method Details

#barcode_lettersString

Return a string to print using one of the USPS Intelligent Mail Barcode fonts. Each character of the string will be one of:

  • ‘T’ for a tracking mark (neither ascender nor descender)

  • ‘A’ for an ascender mark

  • ‘D’ for a descender mark

  • ‘F’ for a full mark (both ascender and descender)

Returns:

  • (String)

    A string that represents the barcode.



65
66
67
# File 'lib/USPS-intelligent-barcode/barcode.rb', line 65

def barcode_letters
  symbols.map(&:letter).join
end