Class: Coder::Cleaner::Simple
- Inherits:
-
Object
- Object
- Coder::Cleaner::Simple
show all
- Defined in:
- lib/coder/cleaner/simple.rb,
lib/coder/cleaner/simple/encodings.rb,
lib/coder/cleaner/simple/byte_buffer.rb
Defined Under Namespace
Modules: Encodings
Classes: ByteBuffer
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(encoding) ⇒ Simple
Returns a new instance of Simple.
19
20
21
22
23
|
# File 'lib/coder/cleaner/simple.rb', line 19
def initialize(encoding)
const_name = encoding.to_s.upcase.gsub('-', '_')
raise Coder::InvalidEncoding, "unknown encoding name - #{encoding}" unless self.class.supports? const_name
@encoding, @name = Encodings.const_get(const_name), encoding
end
|
Class Method Details
.available? ⇒ Boolean
8
9
10
|
# File 'lib/coder/cleaner/simple.rb', line 8
def self.available?
true
end
|
.supports?(encoding) ⇒ Boolean
12
13
14
15
16
17
|
# File 'lib/coder/cleaner/simple.rb', line 12
def self.supports?(encoding)
const_name = encoding.to_s.upcase.gsub('-', '_')
Encodings.const_defined? const_name
rescue NameError
false
end
|
Instance Method Details
#clean(str) ⇒ Object
25
26
27
28
29
|
# File 'lib/coder/cleaner/simple.rb', line 25
def clean(str)
bytes = ByteBuffer.new(@encoding)
str.each_byte { |b| bytes << b }
Coder.force_encoding!(bytes.to_s, @name)
end
|