Class: Coder::Cleaner::Iconv
- Inherits:
-
Object
- Object
- Coder::Cleaner::Iconv
- Defined in:
- lib/coder/cleaner/iconv.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clean(str) ⇒ Object
-
#initialize(encoding) ⇒ Iconv
constructor
A new instance of Iconv.
Constructor Details
#initialize(encoding) ⇒ Iconv
Returns a new instance of Iconv.
33 34 35 36 37 38 39 |
# File 'lib/coder/cleaner/iconv.rb', line 33 def initialize(encoding) @nullbyte = "\0" @iconv = ::Iconv.new("#{encoding}//ignore", encoding.to_s) @nullbyte.encode! encoding if @nullbyte.respond_to? :encode! rescue ::Iconv::InvalidEncoding => e raise Coder::InvalidEncoding, e. end |
Class Method Details
.available? ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/coder/cleaner/iconv.rb', line 26 def self.available? load_iconv !!::Iconv.conv("iso-8859-1//ignore", "utf-8", "\305\253" + "a"*8160) rescue Exception false end |
.load_iconv ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/coder/cleaner/iconv.rb', line 7 def self.load_iconv return if defined? ::Iconv stderr_was, $stderr = $stderr, StringIO.new require 'iconv' ensure $stderr = stderr_was if stderr_was end |
.new ⇒ Object
15 16 17 18 |
# File 'lib/coder/cleaner/iconv.rb', line 15 def self.new(*) load_iconv super end |
.supports?(encoding) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/coder/cleaner/iconv.rb', line 20 def self.supports?(encoding) encoding.to_s !~ /^ucs/i and ::Iconv.new("#{encoding}//ignore", encoding.to_s) rescue Exception false end |