Module: Coder

Extended by:
Coder
Included in:
Coder
Defined in:
lib/coder.rb,
lib/coder/error.rb,
lib/coder/cleaner.rb,
lib/coder/version.rb,
lib/coder/cleaner/java.rb,
lib/coder/cleaner/iconv.rb,
lib/coder/cleaner/simple.rb,
lib/coder/cleaner/builtin.rb,
lib/coder/cleaner/simple/encodings.rb,
lib/coder/cleaner/simple/byte_buffer.rb

Defined Under Namespace

Modules: Cleaner Classes: Error, InvalidEncoding

Constant Summary collapse

DEFAULT_ENCODING =
'UTF-8'
VERSION =
"0.3.0"

Instance Method Summary collapse

Instance Method Details

#clean(str, encoding = DEFAULT_ENCODING) ⇒ Object



11
12
13
# File 'lib/coder.rb', line 11

def clean(str, encoding = DEFAULT_ENCODING)
  Cleaner.new(encoding).clean(str)
end

#clean!(str, encoding = DEFAULT_ENCODING) ⇒ Object



15
16
17
# File 'lib/coder.rb', line 15

def clean!(str, encoding = DEFAULT_ENCODING)
  str.replace clean(str, encoding)
end

#force_encoding(str, encoding = DEFAULT_ENCODING) ⇒ Object



24
25
26
# File 'lib/coder.rb', line 24

def force_encoding(str, encoding = DEFAULT_ENCODING)
  force_encoding! str.dup, encoding
end

#force_encoding!(str, encoding = DEFAULT_ENCODING) ⇒ Object



19
20
21
22
# File 'lib/coder.rb', line 19

def force_encoding!(str, encoding = DEFAULT_ENCODING)
  return str unless str.respond_to? :force_encoding
  str.force_encoding(encoding.to_s)
end