Class: FormKeeper::Filter::ToUTF8

Inherits:
Base
  • Object
show all
Defined in:
lib/formkeeper.rb

Instance Method Summary collapse

Constructor Details

#initialize(encoding) ⇒ ToUTF8

Returns a new instance of ToUTF8.



48
49
50
# File 'lib/formkeeper.rb', line 48

def initialize(encoding)
  @encoding = encoding
end

Instance Method Details

#process(value) ⇒ Object



51
52
53
54
55
56
# File 'lib/formkeeper.rb', line 51

def process(value)
  v = value.dup
  v.force_encoding(@encoding)
  return v.encode('UTF-8') if v.valid_encoding?
  value.encode('UTF-16', :invalid => :replace, :undef => :replace, :replace => '').encode('UTF-8')
end