Method: CoreHelper#mask_value

Defined in:
app/helpers/core_helper.rb

#mask_value(value, default: '************') ⇒ Object

Mask a value, i.e. password field

  1. If blank or nil, return the default

  2. Length of 1-4 only show the first character

  3. Length 5-10 only show the first and last character

  4. Otherwise show the first and last three characters



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/core_helper.rb', line 62

def mask_value(value, default: '************')
  return default if value.blank? || !value.respond_to?(:to_s)

  string_value = value.to_s
  case string_value.length
  when 1..4
    "#{string_value.first}***********"
  when 5..10
    "#{string_value.first}**********#{string_value.last}"
  else
    "#{string_value[0..2]}**********#{string_value[-3..-1]}"
  end
end