Class: AttrMasker::Maskers::Replacing
- Inherits:
-
Object
- Object
- AttrMasker::Maskers::Replacing
- Defined in:
- lib/attr_masker/maskers/replacing.rb
Overview
Replacing
masker replaces every character of string which is being masked with replacement
one, preserving the length of the masked string (provided that a replacement string contains a single character, which is a typical case). Optionally, non-alphanumeric characters like dashes or spaces may be left unchanged.
Instance Attribute Summary collapse
-
#alphanum_only ⇒ Object
readonly
Returns the value of attribute alphanum_only.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
- #call(value:, **_opts) ⇒ Object
-
#initialize(replacement: "*", alphanum_only: false) ⇒ Replacing
constructor
A new instance of Replacing.
Constructor Details
#initialize(replacement: "*", alphanum_only: false) ⇒ Replacing
Returns a new instance of Replacing.
30 31 32 33 34 |
# File 'lib/attr_masker/maskers/replacing.rb', line 30 def initialize(replacement: "*", alphanum_only: false) replacement = "" if replacement.nil? @replacement = replacement @alphanum_only = alphanum_only end |
Instance Attribute Details
#alphanum_only ⇒ Object (readonly)
Returns the value of attribute alphanum_only.
25 26 27 |
# File 'lib/attr_masker/maskers/replacing.rb', line 25 def alphanum_only @alphanum_only end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
25 26 27 |
# File 'lib/attr_masker/maskers/replacing.rb', line 25 def replacement @replacement end |
Instance Method Details
#call(value:, **_opts) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/attr_masker/maskers/replacing.rb', line 36 def call(value:, **_opts) return value unless value.is_a? String if alphanum_only value.gsub(/[[:alnum:]]/, replacement) else replacement * value.size end end |