Yoji Shidara
null+****@clear*****
Tue Dec 24 19:19:41 JST 2013
Yoji Shidara 2013-12-24 19:19:41 +0900 (Tue, 24 Dec 2013) New Revision: 6943d69484af5b626465bfc0d5e62c8a422a4384 https://github.com/droonga/fluent-plugin-droonga/commit/6943d69484af5b626465bfc0d5e62c8a422a4384 Message: Simplify format method Reflecting review http://sourceforge.jp/projects/groonga/lists/archive/commit/2013-December/016840.html (In short, it says that meta programming in this case is too much.) Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+22 -19) =================================================================== --- lib/droonga/searcher.rb 2013-12-24 19:24:20 +0900 (bf62ecc) +++ lib/droonga/searcher.rb 2013-12-24 19:19:41 +0900 (c9ce5a5) @@ -329,14 +329,6 @@ 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 @@ -351,24 +343,35 @@ module Droonga def format formatted_result = {} - SUB_FORMATTERS.each do |name, sub_formatter_method_name| - if need_element_output?(name) - formatted_result[name] = - method(sub_formatter_method_name).call - end + output_elements.each do |name| + value = format_element(name) + next if value.nil? + formatted_result[name] = value end formatted_result end private - def need_element_output?(element) - params =****@reque***** - - elements = params["elements"] - return false if elements.nil? + def format_element(name) + case name + when "count" + format_count + when "attributes" + format_attributes + when "records" + format_records + when "startTime" + format_start_time + when "elapsedTime" + format_elapsed_time + else + nil + end + end - elements.include?(element) + def output_elements + @request.output["elements"] || [] end def format_count -------------- next part -------------- HTML����������������������������... Download