Class: Summarizer

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

Constant Summary collapse

MERGE_WITH_PLUS =
-> (_k, o, n) { o + n }

Instance Method Summary collapse

Constructor Details

#initialize(collection, options = {}) ⇒ Summarizer

Returns a new instance of Summarizer.



4
5
6
7
# File 'lib/summarizer.rb', line 4

def initialize(collection, options = {})
  @collection = collection
  @merge_type =  options[:merge_type] || MERGE_WITH_PLUS
end

Instance Method Details

#reduce(inital_state, &block) ⇒ Object



9
10
11
# File 'lib/summarizer.rb', line 9

def reduce(inital_state, &block)
  @collection.reduce(inital_state, &merge_step(block))
end