Class: FrequencyAnalyser::Aggregator

Inherits:
Struct
  • Object
show all
Defined in:
lib/frequency_analyser/aggregator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(counter = fa::Counter, aggregation = fa::Aggregation) ⇒ Aggregator



3
4
5
# File 'lib/frequency_analyser/aggregator.rb', line 3

def initialize(counter = fa::Counter, aggregation = fa::Aggregation)
  super
end

Instance Attribute Details

#aggregationObject

Returns the value of attribute aggregation



1
2
3
# File 'lib/frequency_analyser/aggregator.rb', line 1

def aggregation
  @aggregation
end

#counterObject

Returns the value of attribute counter



1
2
3
# File 'lib/frequency_analyser/aggregator.rb', line 1

def counter
  @counter
end

Class Method Details

.aggregate(*files) ⇒ Object



7
8
9
# File 'lib/frequency_analyser/aggregator.rb', line 7

def self.aggregate(*files)
  new.aggregate(*files)
end

Instance Method Details

#aggregate(*files) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/frequency_analyser/aggregator.rb', line 11

def aggregate(*files)
  hash = aggregation.new
  files = coerce(files)
  files.each do |file|
    file.each_line do |line|
      hash << counter.count(line)
    end
    reset(file)
  end
  hash
end