Class: Fetch::URLSearchParams

Inherits:
MultiMap
  • Object
show all
Defined in:
lib/fetch/url_search_params.rb

Instance Attribute Summary

Attributes inherited from MultiMap

#entries

Instance Method Summary collapse

Methods inherited from MultiMap

#append, #delete, #each, #get, #get_all, #has, #keys, #set, #values

Constructor Details

#initialize(options = []) ⇒ URLSearchParams

Returns a new instance of URLSearchParams.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fetch/url_search_params.rb', line 7

def initialize(options = [])
  super()

  case options
  when String
    initialize(URI.decode_www_form(options.delete_prefix('?')))
  when Enumerable
    options.each do |k, v|
      append k, v
    end
  else
    raise ArgumentError
  end
end

Instance Method Details

#sortObject



22
23
24
# File 'lib/fetch/url_search_params.rb', line 22

def sort
  entries.sort_by!(&:first)
end

#to_sObject



26
27
28
# File 'lib/fetch/url_search_params.rb', line 26

def to_s
  URI.encode_www_form(entries)
end