Class: EasyPin::Padder
- Inherits:
-
Object
- Object
- EasyPin::Padder
- Defined in:
- lib/easy_pin.rb
Instance Method Summary collapse
-
#initialize(amount) ⇒ Padder
constructor
A new instance of Padder.
- #pad(parts) ⇒ Object
- #unpad(parts) ⇒ Object
Constructor Details
#initialize(amount) ⇒ Padder
Returns a new instance of Padder.
115 116 117 |
# File 'lib/easy_pin.rb', line 115 def initialize(amount) @amount = amount end |
Instance Method Details
#pad(parts) ⇒ Object
119 120 121 122 123 |
# File 'lib/easy_pin.rb', line 119 def pad(parts) padding_parts = [0] * [@amount - parts.size, 0].max padding_parts + parts end |
#unpad(parts) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/easy_pin.rb', line 125 def unpad(parts) if parts[0].zero? unpad(parts[1..-1]) else parts end end |