Skip to content

Commit

Permalink
Use SUB_FORMATTERS map to iterate over formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Dec 19, 2013
1 parent d623044 commit 1b22308
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/droonga/searcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ def log_tag
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
Expand All @@ -339,24 +347,10 @@ def initialize(search_request, search_result)
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
Expand Down

0 comments on commit 1b22308

Please sign in to comment.