Class: EscapeUriString

Inherits:
Object
  • Object
show all
Defined in:
lib/escape_uri_string.rb

Constant Summary collapse

RESERVED_CHARACTERS =
/[^a-zA-Z0-9\-\.\_\~]/

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ EscapeUriString

Returns a new instance of EscapeUriString.



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

def initialize(string)
  @string = string
  validate
end

Instance Method Details

#escapeObject



16
17
18
19
20
21
22
23
24
# File 'lib/escape_uri_string.rb', line 16

def escape
  escaped = escape_uri(@string) || escape_uri(@string.force_encoding(Encoding::UTF_8))

  unless escaped
    fail ArgumentError, "Unable to escape string: #{@string}"
  end

  escaped
end