Class: RDFgrid::Reducer Abstract

Inherits:
Processor show all
Defined in:
lib/rdfgrid/reducer.rb

Overview

This class is abstract.

Direct Known Subclasses

Reducer::AvgReducer, Reducer::MaxReducer, Reducer::MinReducer, Reducer::SumReducer

Defined Under Namespace

Classes: AvgReducer, MaxReducer, MinReducer, SumReducer

Constant Summary

Constants inherited from Processor

SEPARATOR

Class Method Summary

Instance Method Summary

Methods inherited from Processor

#initialize, process!

Constructor Details

This class inherits a constructor from RDFgrid::Processor

Class Method Details

+ process(input, options = {}, &block)

This method returns an undefined value.

Parameters:

  • (IO, File, #each_line) input
  • (Hash{Symbol => Object}) options (defaults to: {})


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rdfgrid/reducer.rb', line 9

def self.process(input, options = {}, &block)
  reducer = self.new(options)
  values  = {}
  input.each_line do |line|
    key, value = line.chomp.split(SEPARATOR)
    (values[key] ||= []) << value
  end
  values.sort.each do |key, values|
    if block_given?
      reducer.call(key, values, &block)
    else
      reducer.call(key, values) do |key, value|
        puts [key, value].join(SEPARATOR)
      end
    end
  end
end

Instance Method Details

- call(key, values, &block)

This method returns an undefined value.

Parameters:

  • (Object) key
  • (Enumerable<Object>) values


31
32
33
34
35
# File 'lib/rdfgrid/reducer.rb', line 31

def call(key, values, &block)
  process(values) do |value|
    block.call(key, value)
  end
end

- (Proc) parser

Returns:

  • (Proc)


47
48
49
# File 'lib/rdfgrid/reducer.rb', line 47

def parser
  @options[:parser] ||= lambda { |value| value.to_i }
end

- process(values, &block)

This method is abstract.

This method returns an undefined value.

Parameters:

  • (Enumerable<Object>) values

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/rdfgrid/reducer.rb', line 41

def process(values, &block)
  raise NotImplementedError
end