Module: Castle::Utils::CleanInvalidChars

Defined in:
lib/castle/utils/clean_invalid_chars.rb

Class Method Summary collapse

Class Method Details

.call(arg) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/castle/utils/clean_invalid_chars.rb', line 7

def call(arg)
  case arg
  when ::String
    arg.encode('UTF-8', invalid: :replace, undef: :replace)
  when ::Hash
    arg.transform_values { |v| Castle::Utils::CleanInvalidChars.call(v) }
  when ::Array
    arg.map { |el| Castle::Utils::CleanInvalidChars.call(el) }
  else
    arg
  end
end