Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/lumix/charset.rb,
lib/lumix/concordancer.rb
Constant Summary collapse
- NoMatchFound =
Class.new(Exception)
Instance Method Summary collapse
Instance Method Details
#digest ⇒ Object
25 26 27 28 29 30 |
# File 'lib/lumix/concordancer.rb', line 25 def digest return @digest if @digest digest = Digest::MD5.new digest.update self @digest = digest.hexdigest end |
#find_icu ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/lumix/charset.rb', line 18 def find_icu matches = @icu.detect_all(self) matches.each do |match| if d = icu_return(match.name) return d end end return nil end |
#icu_return(cs) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/lumix/charset.rb', line 28 def icu_return(cs) begin return Iconv.conv('UTF-8', cs, self) rescue end end |
#to_utf(default = 'utf-8') ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/lumix/charset.rb', line 9 def to_utf(default = 'utf-8') @icu ||= ICU::CharDet::Detector.new result = icu_return(default) || find_icu raise NoMatchFound unless result @entities ||= HTMLEntities.new @entities.decode(result) end |