Class: Pseudonymize::Telephone

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telephone, **options) ⇒ Telephone

Returns a new instance of Telephone.



5
6
7
8
# File 'lib/pseudonymize/telephone.rb', line 5

def initialize(telephone, **options)
  @telephone = telephone
  @options   = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/pseudonymize/telephone.rb', line 3

def options
  @options
end

Instance Method Details

#resultObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pseudonymize/telephone.rb', line 10

def result
  characters = @telephone.chars
  unhidden   = (characters.length / 2)
  last       = (unhidden.to_f / 2).ceil
  first      = unhidden - last
  
  [
    characters[0..first],
    (options[:censor] * (characters.length - first - last - 1)),
    characters[-last, last]
  ].flatten.join
end