Class: UnicodePlugin::UnicodeFilter
Instance Method Summary collapse
- #in(data) ⇒ Object
-
#initialize(oenc, *iencs) ⇒ UnicodeFilter
constructor
A new instance of UnicodeFilter.
- #out(data) ⇒ Object
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 |