Class: Cma

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



2
3
4
# File 'lib/rbma/cma.rb', line 2

def count
  @count
end

#currentObject (readonly)

Returns the value of attribute current.



4
5
6
# File 'lib/rbma/cma.rb', line 4

def current
  @current
end

#lastObject (readonly)

Returns the value of attribute last.



3
4
5
# File 'lib/rbma/cma.rb', line 3

def last
  @last
end

Instance Method Details

#compute(current:, last: nil, count: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rbma/cma.rb', line 6

def compute(current:, last: nil, count: nil)
  if last && count
    @last = (last*count + current).to_f
    @current = @last/ (count + 1)
  elsif last == nil && count == nil
    @count = @count ? @count + 1 : 1
    @last  = @last  ? @last : 0
    @last = (@last + current)
    @current = @last.to_f/@count
  end
end