Navigation Menu

Skip to content

Commit

Permalink
groonga: Extract method to convert main select result
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 28, 2014
1 parent fe42389 commit 250f4c2
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions lib/droonga/plugins/groonga/select.rb
Expand Up @@ -139,37 +139,43 @@ def convert_drilldown(select_request)

class ResponseConverter
def convert(search_response)
select_responses = search_response.collect do |key, value|
status_code = 0

start_time = value["startTime"]
start_time_in_unix_time = if start_time
Time.parse(start_time).to_f
else
Time.now.to_f
end
elapsed_time = value["elapsedTime"] || 0
count = value["count"]

attributes = value["attributes"] || []
converted_attributes = attributes.collect do |attribute|
name = attribute["name"]
type = attribute["type"]
[name, type]
end
search_response.each do |key, value|
convert_main_result(value)
end

header = [status_code, start_time_in_unix_time, elapsed_time]
records = value["records"]
if records.empty?
results = [[count], converted_attributes]
else
results = [[count], converted_attributes, records]
end
body = [results]
select_results = [@header, [@body]]

[header, body]
select_results
end

private
def convert_main_result(result)
start_time = result["startTime"]
start_time_in_unix_time = if start_time
Time.parse(start_time).to_f
else
Time.now.to_f
end
elapsed_time = result["elapsedTime"] || 0
count = result["count"]

attributes = result["attributes"] || []
converted_attributes = attributes.collect do |attribute|
name = attribute["name"]
type = attribute["type"]
[name, type]
end

status_code = 0
@header = [status_code, start_time_in_unix_time, elapsed_time]
records = result["records"]
if records.empty?
results = [[count], converted_attributes]
else
results = [[count], converted_attributes, records]
end
select_responses.first

@body = results
end
end

Expand Down

0 comments on commit 250f4c2

Please sign in to comment.