class Groonga::Client::Protocol::GQTP::RawResponse

Attributes

body[RW]
header[RW]

Public Class Methods

new(command) click to toggle source
# File lib/groonga/client/protocol/gqtp.rb, line 93
def initialize(command)
  @start_time = Time.now.to_f
  @command = command
  @header = nil
  @body = nil
end

Public Instance Methods

to_groonga_command_compatible_response() click to toggle source
# File lib/groonga/client/protocol/gqtp.rb, line 100
def to_groonga_command_compatible_response
  case @command.output_type
  when :json
    convert_for_json
  when :xml
    convert_for_xml
  when :none
    @body
  end
end

Private Instance Methods

convert_for_json() click to toggle source
# File lib/groonga/client/protocol/gqtp.rb, line 112
def convert_for_json
  elapsed_time = Time.now.to_f - @start_time
  header = [
    @header.status,
    @start_time,
    elapsed_time,
  ]
  header_in_json = JSON.generate(header)
  "[#{header_in_json},#{@body}]"
end
convert_for_xml() click to toggle source
# File lib/groonga/client/protocol/gqtp.rb, line 123
          def convert_for_xml
            code = @header.status
            up = @start_time.to_f
            elapsed = Time.now.to_f - @start_time.to_f
            <<-XML
<RESULT CODE="#{h(code)}" UP="#{h(up)}" ELAPSED="#{h(elapsed)}">
#{@body}
</RESULT>
            XML
          end