class Addressable::URI
def self.unencode(uri, returning=String)
-
(String, Addressable::URI)
-
Parameters:
-
returning
(Class
) -- -
uri
(String, Addressable::URI, #to_str
) --
def self.unencode(uri, returning=String) return nil if uri.nil? begin uri = uri.to_str rescue NoMethodError, TypeError raise TypeError, "Can't convert #{uri.class} into String." end if !uri.is_a? String if ![String, ::Addressable::URI].include?(returning) raise TypeError, "Expected Class (String or Addressable::URI), " + "got #{returning.inspect}" end result = uri.gsub(/%[0-9a-f]{2}/i) do |sequence| sequence[1..3].to_i(16).chr end result.force_encoding("utf-8") if result.respond_to?(:force_encoding) if returning == String return result elsif returning == ::Addressable::URI return ::Addressable::URI.parse(result) end end