Yoji Shidara
null+****@clear*****
Thu Jan 23 11:05:42 JST 2014
Yoji Shidara 2014-01-23 11:05:42 +0900 (Thu, 23 Jan 2014) New Revision: de6cf3a0f34d1ffbd9d2c07a8eee8831588be05c https://github.com/droonga/fluent-plugin-droonga/commit/de6cf3a0f34d1ffbd9d2c07a8eee8831588be05c Message: Extract AttributeFormattable module Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+31 -25) =================================================================== --- lib/droonga/searcher.rb 2014-01-23 10:52:31 +0900 (e522bd3) +++ lib/droonga/searcher.rb 2014-01-23 11:05:42 +0900 (e9cca0a) @@ -361,28 +361,41 @@ module Droonga end end - class SimpleAttributesFormatter + module AttributeFormattable def format_attribute(attribute, table) label = attribute[:label] source = attribute[:source] if source == "_subrecs" sub_record_table = table.range sub_attributes = format(attribute[:attributes], sub_record_table) - { - "name" => label, - "attributes" => sub_attributes, - } + + format_attribute_subrecs(label, 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} + format_attribute_column(label, column) end end end + end + + class SimpleAttributesFormatter + include AttributeFormattable + + def format_attribute_subrecs(label, sub_attributes) + { + "name" => label, + "attributes" => sub_attributes, + } + end + + def format_attribute_column(label, column) + vector = column.respond_to?(:vector?) ? column.vector? : false + {"name" => label, "type" => column.range.name, "vector" => vector} + end def format(attributes, table) attributes.collect do |attribute| @@ -392,24 +405,17 @@ module Droonga end class ComplexAttributesFormatter - def format_attribute(attribute, table) - source = attribute[:source] - if source == "_subrecs" - sub_record_table = table.range - sub_attributes = format(attribute[:attributes], sub_record_table) - { - "attributes" => sub_attributes - } - else - expression = attribute[:expression] - if expression - # TODO implement - else - column = table.column(source) - vector = column.respond_to?(:vector?) ? column.vector? : false - {"type" => column.range.name, "vector" => vector} - end - end + include AttributeFormattable + + def format_attribute_subrecs(label, sub_attributes) + { + "attributes" => sub_attributes + } + end + + def format_attribute_column(label, column) + vector = column.respond_to?(:vector?) ? column.vector? : false + {"type" => column.range.name, "vector" => vector} end def format(attributes, table) -------------- next part -------------- HTML����������������������������...Download