class UriEncoding::Encoder

Public Class Methods

new(excepted_chars=nil) click to toggle source
# File lib/uri_encoding/encoder.rb, line 3
def initialize(excepted_chars=nil)
  @excepted_chars = excepted_chars || DefaultExceptions
end

Public Instance Methods

encode(str) click to toggle source
# File lib/uri_encoding/encoder.rb, line 7
def encode(str)
  str.to_s.each_char.map{|c| @excepted_chars.include?(c) ? c : escape_char(c) }.join("")
end

Private Instance Methods

escape_char(char) click to toggle source
# File lib/uri_encoding/encoder.rb, line 13
def escape_char(char)
  char.each_byte.map{|byte| "%#{byte.to_s(16).upcase}" }.join("")
end