Class: TTFunk::Sum

Inherits:
Aggregate show all
Defined in:
lib/ttfunk/sum.rb

Overview

Sum aggreaget. Is sums all pushed values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_value = 0) ⇒ Sum

Returns a new instance of Sum.

Parameters:

  • init_value (#+) (defaults to: 0)

    initial value



12
13
14
15
# File 'lib/ttfunk/sum.rb', line 12

def initialize(init_value = 0)
  super()
  @value = init_value
end

Instance Attribute Details

#value#+ (readonly)

Value

Returns:

  • (#+)


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

def value
  @value
end

Instance Method Details

#<<(operand) ⇒ void

This method returns an undefined value.

Push a value. It will be added to the current value.

Parameters:

  • operand (any)


21
22
23
# File 'lib/ttfunk/sum.rb', line 21

def <<(operand)
  @value += coerce(operand)
end

#value_or(_default) ⇒ any

Get the stored value or default.

Parameters:

  • _default (any)

    Unused. Here for API compatibility.

Returns:

  • (any)


29
30
31
32
# File 'lib/ttfunk/sum.rb', line 29

def value_or(_default)
  # value should always be non-nil
  value
end