Masafumi Yokoyama
null+****@clear*****
Tue Dec 6 17:09:54 JST 2016
Masafumi Yokoyama 2016-12-06 17:09:54 +0900 (Tue, 06 Dec 2016) New Revision: 3e3b9f16981f9d9b2299e97a1130cce565e75b06 https://github.com/ranguba/groonga-client/commit/3e3b9f16981f9d9b2299e97a1130cce565e75b06 Message: Extract methods Modified files: lib/groonga/client/response/select.rb Modified: lib/groonga/client/response/select.rb (+20 -12) =================================================================== --- lib/groonga/client/response/select.rb 2016-12-06 16:40:03 +0900 (247c449) +++ lib/groonga/client/response/select.rb 2016-12-06 17:09:54 +0900 (ddadd28) @@ -53,11 +53,7 @@ module Groonga body[1..-1].each do |record| if record.is_a?(::Hash) && record.first[1][1].none? {|key| key[0] == "_nsubrecs"} - @slices = {} - record.each do |key, slice_body| - n_hits, body = parse_match_records_v1(slice_body) - @slices[key] = body - end + @slices = parse_slices_v1(record) else @drilldowns = parse_drilldowns_v1([record]) end @@ -65,13 +61,7 @@ module Groonga else @n_hits, @records = parse_match_records_v3(body) @drilldowns = parse_drilldowns_v3(body["drilldowns"]) - @slices = {} - if body["slices"] - body["slices"].each do |key, records| - n_hits, body = parse_match_records_v3(records) - @slices[key] = body - end - end + @slices = parse_slices_v3(body["slices"]) end body end @@ -152,6 +142,15 @@ module Groonga end end + def parse_slices_v1(raw_slices) + slices = {} + (raw_slices || {}).each do |key, slice_body| + n_hits, body = parse_match_records_v1(slice_body) + slices[key] = body + end + slices + end + def parse_drilldowns_v3(raw_drilldowns) drilldowns = {} (raw_drilldowns || {}).each do |key, raw_drilldown| @@ -161,6 +160,15 @@ module Groonga drilldowns end + def parse_slices_v3(raw_slices) + slices = {} + (raw_slices || {}).each do |key, records| + n_hits, body = parse_match_records_v3(records) + slices[key] = body + end + slices + end + class Drilldown < Struct.new(:key, :n_hits, :records) # @deprecated since 0.2.6. Use {#records} instead. alias_method :items, :records -------------- next part -------------- HTML����������������������������... ダウンロード