Class: Gitlab::Utils::Email::Masker

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/utils/email.rb

Direct Known Subclasses

Deform, Symmetrical

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original) ⇒ Masker

Returns a new instance of Masker.



20
21
22
23
24
25
26
27
# File 'lib/gitlab/utils/email.rb', line 20

def initialize(original)
  @original = original
  @local_part, @at, domain = original.rpartition('@')
  @sub_domain, @dot, @toplevel_domain = domain.rpartition('.')

  @at = nil if @at.empty?
  @dot = nil if @dot.empty?
end

Instance Attribute Details

#atObject (readonly)

Returns the value of attribute at.



18
19
20
# File 'lib/gitlab/utils/email.rb', line 18

def at
  @at
end

#dotObject (readonly)

Returns the value of attribute dot.



18
19
20
# File 'lib/gitlab/utils/email.rb', line 18

def dot
  @dot
end

#local_partObject (readonly)

Returns the value of attribute local_part.



18
19
20
# File 'lib/gitlab/utils/email.rb', line 18

def local_part
  @local_part
end

#sub_domainObject (readonly)

Returns the value of attribute sub_domain.



18
19
20
# File 'lib/gitlab/utils/email.rb', line 18

def sub_domain
  @sub_domain
end

#toplevel_domainObject (readonly)

Returns the value of attribute toplevel_domain.



18
19
20
# File 'lib/gitlab/utils/email.rb', line 18

def toplevel_domain
  @toplevel_domain
end

Instance Method Details

#maskedObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/utils/email.rb', line 29

def masked
  masked = [
    local_part,
    at,
    sub_domain,
    dot,
    toplevel_domain
  ].compact.join('')

  masked = mask(@original, visible_length: 1) if masked == @original

  masked
end