Class: Embulk::GuessCharset
Instance Method Summary
collapse
Methods inherited from GuessPlugin
from_java_object, java_object
Instance Method Details
#guess(config, sample_buffer) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/embulk/guess_charset.rb', line 6
def guess(config, sample_buffer)
detector = com.ibm.icu.text.CharsetDetector.new
detector.setText(sample_buffer.to_java_bytes)
best_match = detector.detect
if best_match.getConfidence < 50
name = "UTF-8"
else
name = best_match.getName
if name == "ISO-8859-1"
name = "UTF-8"
end
end
return {"parser" => {"charset" => name}}
end
|