[Groonga-commit] droonga/fluent-plugin-droonga at 1b22308 [master] Use SUB_FORMATTERS map to iterate over formatters

Back to archive index

Yoji Shidara null+****@clear*****
Thu Dec 19 19:55:41 JST 2013


Yoji Shidara	2013-12-19 19:55:41 +0900 (Thu, 19 Dec 2013)

  New Revision: 1b2230843ca7306f6e4c9bfbc07aca2a4b3b8bca
  https://github.com/droonga/fluent-plugin-droonga/commit/1b2230843ca7306f6e4c9bfbc07aca2a4b3b8bca

  Message:
    Use SUB_FORMATTERS map to iterate over formatters

  Modified files:
    lib/droonga/searcher.rb

  Modified: lib/droonga/searcher.rb (+12 -18)
===================================================================
--- lib/droonga/searcher.rb    2013-12-19 19:16:13 +0900 (8cd6782)
+++ lib/droonga/searcher.rb    2013-12-19 19:55:41 +0900 (1a2f13a)
@@ -325,6 +325,14 @@ module Droonga
     end
 
     class ResultFormatter
+      SUB_FORMATTERS = {
+        "count"       => :format_count,
+        "attribtues"  => :format_attributes,
+        "records"     => :format_records,
+        "startTime"   => :format_start_time,
+        "elapsedTime" => :format_elapsed_time
+      }
+
       class << self
         def format(search_request, search_result)
           new(search_request, search_result).format
@@ -339,24 +347,10 @@ module Droonga
       def format
         formatted_result = {}
 
-        if need_element_output?("count")
-          format_count(formatted_result)
-        end
-
-        if need_element_output?("attributes")
-          format_attributes(formatted_result)
-        end
-
-        if need_element_output?("records")
-          format_records(formatted_result)
-        end
-
-        if need_element_output?("startTime")
-          format_start_time(formatted_result)
-        end
-
-        if need_element_output?("elapsedTime")
-          format_elapsed_time(formatted_result)
+        SUB_FORMATTERS.each do |name, sub_formatter_method_name|
+          if need_element_output?(name)
+            method(sub_formatter_method_name).call(formatted_result)
+          end
         end
 
         formatted_result
-------------- next part --------------
HTML����������������������������...
Download 



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