Class: Pan

Inherits:
Object
  • Object
show all
Defined in:
lib/pan.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'1.0.0'
DEFAULT_TEMPLATE =
[6, '*', 4]

Class Method Summary collapse

Class Method Details

.mask(pan, template: self.template) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pan.rb', line 13

def self.mask(pan, template: self.template)
  fail Pan::Error, 'invalid template' unless template.first >= 0 and template.last >= 0 and template[1].is_a?(String)
  fail Pan::Error, 'invalid pan' unless pan.is_a?(String)

  mask_length = pan.length - template.first - template.last

  return pan if mask_length <= 0

  pan.slice(0, template.first) \
    + (template[1] * mask_length) \
    + pan.slice(-template.last, template.last)
end

.truncate(pan, template: self.template) ⇒ Object



26
27
28
# File 'lib/pan.rb', line 26

def self.truncate(pan, template: self.template)
  pan.replace(self.mask(pan, template: template))
end