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.new) ⇒ Aggregator

Returns a new instance of Aggregator.



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

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

Instance Attribute Details

#aggregationObject

Returns the value of attribute aggregation

Returns:

  • (Object)

    the current value of aggregation



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

def aggregation
  @aggregation
end

#counterObject

Returns the value of attribute counter

Returns:

  • (Object)

    the current value of 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
# File 'lib/frequency_analyser/aggregator.rb', line 11

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