Module: CharlockHolmes::EncodingDetector

Extended by:
EncodingDetector
Included in:
EncodingDetector
Defined in:
lib/charlock_holmes/encoding_detector.rb

Instance Method Summary collapse

Instance Method Details

#all_detectable_charsetsObject



40
41
42
# File 'lib/charlock_holmes/encoding_detector.rb', line 40

def all_detectable_charsets
  CharsetDetector.getAllDetectableCharsets().to_a
end

#detect(string, hint = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/charlock_holmes/encoding_detector.rb', line 12

def detect(string, hint=nil)
  detector = create_detector(string, hint)

  begin
    if charset_match = detector.detect()
      charset_match.to_hash
    else
      nil
    end
  rescue
    nil
  end
end

#detect_all(string, hint = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/charlock_holmes/encoding_detector.rb', line 26

def detect_all(string, hint=nil)
  detector = create_detector(string, hint)

  begin
    if charset_matchs = detector.detectAll()
      charset_matchs.collect {|match| match.to_hash }
    else
      nil
    end
  rescue
    nil
  end
end