Class: Imb::ServiceType
- Inherits:
-
Object
- Object
- Imb::ServiceType
- Defined in:
- lib/USPS-intelligent-barcode/service_type.rb
Overview
This class represents a service type.
Constant Summary collapse
- RANGE =
The valid range of a service type
0..999
Internal collapse
-
#shift_and_add_to(target, long_mailer_id) ⇒ Integer
Add this object’s value to target, shifting it left as many digts as are needed to make room.
-
#validate(long_mailer_id) ⇒ Object
Validate the value.
Class Method Summary collapse
-
.coerce(o) ⇒ Object
Turn the argument into a ServiceType if possible.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Return true if this object is equal to o.
-
#initialize(value) ⇒ ServiceType
constructor
A new instance of ServiceType.
-
#to_i ⇒ Integer
The value of the service type.
Constructor Details
#initialize(value) ⇒ ServiceType
Returns a new instance of ServiceType.
30 31 32 |
# File 'lib/USPS-intelligent-barcode/service_type.rb', line 30 def initialize(value) @value = value end |
Class Method Details
.coerce(o) ⇒ Object
Turn the argument into a ServiceType if possible. Accepts:
-
String
-
Integer
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/USPS-intelligent-barcode/service_type.rb', line 15 def self.coerce(o) case o when ServiceType o when String new(o.to_i) when Integer new(o) else raise ArgumentError, 'Cannot coerce to ServiceType' end end |
Instance Method Details
#==(o) ⇒ Object
Return true if this object is equal to o
37 38 39 40 41 |
# File 'lib/USPS-intelligent-barcode/service_type.rb', line 37 def ==(o) ServiceType.coerce(o).to_i == to_i rescue ArgumentError false end |
#shift_and_add_to(target, long_mailer_id) ⇒ Integer
Add this object’s value to target, shifting it left as many digts as are needed to make room.
67 68 69 |
# File 'lib/USPS-intelligent-barcode/service_type.rb', line 67 def shift_and_add_to(target, long_mailer_id) target * 10 ** NUM_DIGITS + to_i end |
#to_i ⇒ Integer
Returns The value of the service type.
45 46 47 |
# File 'lib/USPS-intelligent-barcode/service_type.rb', line 45 def to_i @value end |