Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/charlock_holmes/string.rb
Instance Method Summary collapse
-
#detect_encoding(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string.
-
#detect_encoding!(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string then set the encoding to what was detected ala ‘force_encoding`.
-
#detect_encodings(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string, and return a list with all the possible encodings that match it.
Instance Method Details
#detect_encoding(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string
Returns: a Hash with :encoding, :language, :type and :confidence
7 8 9 10 |
# File 'lib/charlock_holmes/string.rb', line 7 def detect_encoding(hint_enc=nil) detector = CharlockHolmes::EncodingDetector.new detector.detect(self, hint_enc) end |
#detect_encoding!(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string then set the encoding to what was detected ala ‘force_encoding`
Returns: self
27 28 29 30 31 32 |
# File 'lib/charlock_holmes/string.rb', line 27 def detect_encoding!(hint_enc=nil) if detected = self.detect_encoding(hint_enc) self.force_encoding(detected[:encoding]) if detected[:encoding] end self end |
#detect_encodings(hint_enc = nil) ⇒ Object
Attempt to detect the encoding of this string, and return a list with all the possible encodings that match it.
Returns: an Array with zero or more Hashes,
each one of them with with :encoding, :language, :type and :confidence
17 18 19 20 |
# File 'lib/charlock_holmes/string.rb', line 17 def detect_encodings(hint_enc=nil) detector = CharlockHolmes::EncodingDetector.new detector.detect_all(self, hint_enc) end |