Class: TextUtils::EnsureUtf
- Defined in:
- lib/text_utils/ensure_utf.rb
Instance Method Summary collapse
Methods inherited from Processor
Constructor Details
This class inherits a constructor from TextUtils::Processor
Instance Method Details
#call(data, env) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/text_utils/ensure_utf.rb', line 2 def call data, env data = call_next data, env # Escape all non-word unicode symbols, otherwise it will raise error when converting to BSON data = Iconv.conv('UTF-8//IGNORE//TRANSLIT', 'UTF-8', data) unless data.encoding == Encoding::UTF_8 raise "something wrong happens, invalid encoding (#{data.encoding} instead of utf-8)!" end data end |