Module: Enco
- Defined in:
- lib/enco.rb,
lib/enco/version.rb
Overview
Enco will convert any string to utf-8 Just call Enco.to_utf8 any_string It will return non string objects back: Enco.to_utf8(not_a_string) === not_a_string
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
Class Method Details
.to_utf8(string, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/enco.rb', line 9 def self.to_utf8(string, = {}) return string unless string.is_a? String string = string.dup cd = ::CharDet.detect(string, :silent => true) if cd.confidence > 0.5 then string.encode('utf-8', cd.encoding, :invalid => :replace) else force_to_utf8 string end end |