Class: Groonga::Command::Format::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/command/format/uri.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_prefix, name, arguments) ⇒ URI

Returns a new instance of URI.



25
26
27
28
29
# File 'lib/groonga/command/format/uri.rb', line 25

def initialize(path_prefix, name, arguments)
  @path_prefix = path_prefix
  @name = name
  @arguments = arguments
end

Instance Method Details

#pathObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/groonga/command/format/uri.rb', line 31

def path
  path = [@path_prefix.chomp("/"), @name].join("/")
  arguments = @arguments.dup
  output_type = arguments.delete(:output_type)
  path << ".#{output_type}" if output_type
  unless arguments.empty?
    sorted_arguments = arguments.sort_by do |name, _|
      name.to_s
    end
    uri_arguments = sorted_arguments.collect do |name, value|
      "#{CGI.escape(name.to_s)}=#{CGI.escape(value)}"
    end
    path << "?"
    path << uri_arguments.join("&")
  end
  path
end