Module: Kameleoon::Utils::Strval

Defined in:
lib/kameleoon/utils.rb

Class Method Summary collapse

Class Method Details

.secret(secret) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kameleoon/utils.rb', line 56

def self.secret(secret)
  hid_ch = '*'
  vis_count = 4

  return 'nil' if secret.nil?

  length = secret.length

  return hid_ch * length if length <= vis_count

  hidden_length = [length - vis_count, vis_count].max

  secret[0, length - hidden_length] + hid_ch * hidden_length
end