Method: UniformResourceIdentifier::Query#initialize

Defined in:
lib/uniform_resource_identifier/query.rb

#initialize(query = nil) ⇒ Query

Returns a new instance of Query.



10
11
12
13
14
15
16
17
18
19
# File 'lib/uniform_resource_identifier/query.rb', line 10

def initialize(query=nil)
  if query.respond_to?(:to_str)
    query = "#{query =~ /^\?/ ? nil : '?'}#{query.to_str}" # Prepend a question mark if needed
    @query = Addressable::URI.parse(query).query_values
  elsif query.respond_to?(:to_hash)
    @query = query.to_hash
  else
    raise(TypeError, "query must either be a String or a Hash") unless query.nil?
  end
end