Class: Riak::Client::Decaying

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/client/decaying.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Decaying) initialize(opts = {})

@param The initial value @param Exponent base @param Timescale



9
10
11
12
13
14
# File 'lib/riak/client/decaying.rb', line 9

def initialize(opts = {})
  @p = opts[:p] || 0
  @e = opts[:e] || Math::E
  @r = opts[:r] || Math.log(0.5) / 10
  @t0 = Time.now
end

Instance Attribute Details

- (Object) e

A float which decays exponentially with time.



4
5
6
# File 'lib/riak/client/decaying.rb', line 4

def e
  @e
end

- (Object) p

Returns the value of attribute p



5
6
7
# File 'lib/riak/client/decaying.rb', line 5

def p
  @p
end

Instance Method Details

- (Object) <<(d)

Add d to current value.



17
18
19
# File 'lib/riak/client/decaying.rb', line 17

def <<(d)
  @p = value + d
end

- (Object) value

Return current value



22
23
24
25
26
27
# File 'lib/riak/client/decaying.rb', line 22

def value
  now = Time.now
  dt = now - @t0
  @t0 = now
  @p = @p * (@e ** (@r * dt))
end