[Groonga-commit] droonga/droonga-engine at 250f4c2 [master] groonga: Extract method to convert main select result

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Apr 28 18:28:07 JST 2014


YUKI Hiroshi	2014-04-28 18:28:07 +0900 (Mon, 28 Apr 2014)

  New Revision: 250f4c218742db42cc0db1b7374f817c47cde483
  https://github.com/droonga/droonga-engine/commit/250f4c218742db42cc0db1b7374f817c47cde483

  Message:
    groonga: Extract method to convert main select result

  Modified files:
    lib/droonga/plugins/groonga/select.rb

  Modified: lib/droonga/plugins/groonga/select.rb (+34 -28)
===================================================================
--- lib/droonga/plugins/groonga/select.rb    2014-04-28 18:15:22 +0900 (b0e3468)
+++ lib/droonga/plugins/groonga/select.rb    2014-04-28 18:28:07 +0900 (48fe58b)
@@ -139,37 +139,43 @@ module Droonga
 
         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
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index