Class: UnicodePlugin::UnicodeFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/rbot/core/unicode.rb

Instance Method Summary collapse

Constructor Details

#initialize(oenc, *iencs) ⇒ UnicodeFilter

Returns a new instance of UnicodeFilter.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rbot/core/unicode.rb', line 31

def initialize(oenc, *iencs)
    o = oenc.dup
    o += '//ignore' if !o.include?('/')
    i = iencs[0].dup
    # i += '//ignore' if !i.include?('/')
    @iencs = iencs.dup
    @iconvs = @iencs.map { |_| Iconv.new('utf-8', _) }
    debug "*** o = #{o}, i = #{i}, iencs = #{iencs.inspect}"
    @default_in = Iconv.new('utf-8//ignore', i)
    @default_out = Iconv.new(o, 'utf-8//ignore')
end

Instance Method Details

#in(data) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rbot/core/unicode.rb', line 43

def in(data)
    rv = nil
    @iconvs.each_with_index { |ic, idx|
        begin
            debug "trying #{@iencs[idx]}"
            rv = ic.iconv(data)
            break
        rescue
        end
    }

    rv = @default_in.iconv(data) if !rv
    debug ">> #{rv.inspect}"
    return rv
end

#out(data) ⇒ Object



59
60
61
62
63
# File 'lib/rbot/core/unicode.rb', line 59

def out(data)
    rv = @default_out.iconv(data) rescue data # XXX: yeah, i know :/
    debug "<< #{rv}"
    rv
end