[Groonga-commit] droonga/fluent-plugin-droonga at 548fc83 [output-attributes] Extract SimpleAttributesFormatter

Back to archive index

Yoji Shidara null+****@clear*****
Thu Jan 23 10:39:48 JST 2014


Yoji Shidara	2014-01-23 10:39:48 +0900 (Thu, 23 Jan 2014)

  New Revision: 548fc83382a2ae83ed933db34213eb498303f29f
  https://github.com/droonga/fluent-plugin-droonga/commit/548fc83382a2ae83ed933db34213eb498303f29f

  Message:
    Extract SimpleAttributesFormatter

  Modified files:
    lib/droonga/searcher.rb

  Modified: lib/droonga/searcher.rb (+34 -27)
===================================================================
--- lib/droonga/searcher.rb    2014-01-22 17:59:37 +0900 (2e72f14)
+++ lib/droonga/searcher.rb    2014-01-23 10:39:48 +0900 (8f8f153)
@@ -361,6 +361,38 @@ module Droonga
       end
     end
 
+    class SimpleAttributesFormatter
+      def format_attribute(attribute, table)
+        label = attribute[:label]
+        source = attribute[:source]
+        if source == "_subrecs"
+          sub_record_table = table.range
+          sub_attributes = attribute[:attributes].collect do |sub_attribute|
+            format_attribute(sub_attribute, sub_record_table)
+          end
+          {
+            "name" => label,
+            "attributes" => sub_attributes,
+          }
+        else
+          expression = attribute[:expression]
+          if expression
+            # TODO implement
+          else
+            column = table.column(source)
+            vector = column.respond_to?(:vector?) ? column.vector? : false
+            {"name" => label, "type" => column.range.name, "vector" => vector}
+          end
+        end
+      end
+
+      def format(attributes, table)
+        attributes.collect do |attribute|
+          format_attribute(attribute, table)
+        end
+      end
+    end
+
     class ResultFormatter
       class << self
         def format(search_request, search_result)
@@ -433,9 +465,8 @@ module Droonga
       end
 
       def format_attributes_simple(attributes)
-        attributes.collect do |attribute|
-          format_attribute_simple(attribute, @result.records)
-        end
+        formatter = SimpleAttributesFormatter.new
+        formatter.format(attributes, @result.records)
       end
 
       def format_attributes_complex(attributes)
@@ -448,30 +479,6 @@ module Droonga
         formatted_attributes
       end
 
-      def format_attribute_simple(attribute, table)
-        label = attribute[:label]
-        source = attribute[:source]
-        if source == "_subrecs"
-          sub_record_table = table.range
-          sub_attributes = attribute[:attributes].collect do |sub_attribute|
-            format_attribute_simple(sub_attribute, sub_record_table)
-          end
-          {
-            "name" => label,
-            "attributes" => sub_attributes,
-          }
-        else
-          expression = attribute[:expression]
-          if expression
-            # TODO implement
-          else
-            column = table.column(source)
-            vector = column.respond_to?(:vector?) ? column.vector? : false
-            {"name" => label, "type" => column.range.name, "vector" => vector}
-          end
-        end
-      end
-
       def format_attribute_complex(attribute, table)
         source = attribute[:source]
         if source == "_subrecs"
-------------- next part --------------
HTML����������������������������...
Download 



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