Class: AttrMasker::Maskers::Replacing
- Inherits:
-
Object
- Object
- AttrMasker::Maskers::Replacing
- Defined in:
- lib/attr_masker/maskers/replacing.rb
Overview
This default masker simply replaces any value with a fixed string.
opts
is a Hash with the key :value that gives you the current attribute value.
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.
13 14 15 16 17 |
# File 'lib/attr_masker/maskers/replacing.rb', line 13 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.
11 12 13 |
# File 'lib/attr_masker/maskers/replacing.rb', line 11 def alphanum_only @alphanum_only end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
11 12 13 |
# File 'lib/attr_masker/maskers/replacing.rb', line 11 def replacement @replacement end |
Instance Method Details
#call(value:, **_opts) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/attr_masker/maskers/replacing.rb', line 19 def call(value:, **_opts) return value unless value.is_a? String if alphanum_only value.gsub(/[[:alnum:]]/, replacement) else replacement * value.size end end |