Class: FormKeeper::Filter::ToUTF8
Instance Method Summary collapse
-
#initialize(encoding) ⇒ ToUTF8
constructor
A new instance of ToUTF8.
- #process(value) ⇒ Object
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 |