Class: RubyReduce::Reduce

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_reduce/reduce.rb

Instance Method Summary collapse

Constructor Details

#initialize(map_result, reduce) ⇒ Reduce

Returns a new instance of Reduce.



3
4
5
6
7
8
# File 'lib/ruby_reduce/reduce.rb', line 3

def initialize(map_result, reduce)
  @map_result = map_result
  @reduce = reduce

  @result = {}
end

Instance Method Details

#emit(result) ⇒ Object



10
11
12
13
# File 'lib/ruby_reduce/reduce.rb', line 10

def emit(result)
  @result[@current_key] ||= []
  @result[@current_key] << result
end

#reduceObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_reduce/reduce.rb', line 15

def reduce
  @map_result.each do |key, values|
    @current_key = key
    values.each do |value|
      instance_exec value, &@reduce
    end
  end

  @result
end