Module: PrettyDiff::Encoding
Instance Method Summary collapse
Instance Method Details
#convert(str, from, to) ⇒ Object
25 26 27 |
# File 'lib/pretty_diff/encoding.rb', line 25 def convert(str, from, to) CharlockHolmes::Converter.convert(str, from, to) end |
#detect(str) ⇒ Object
19 20 21 22 23 |
# File 'lib/pretty_diff/encoding.rb', line 19 def detect(str) if detected = CharlockHolmes::EncodingDetector.detect(str) detected[:encoding] end end |
#enforce(encoding, text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pretty_diff/encoding.rb', line 7 def enforce(encoding, text) result = text if (detected = detect(result)) && detected.downcase != encoding.downcase result = convert(result, detected, encoding) end if RUBY_VERSION >= "2.0.0" result.force_encoding(encoding) else result end end |