Class: TallyCounter::KeyGenerate

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

Constant Summary collapse

NAME =
'tally_counter'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(interval, namespace = nil) ⇒ KeyGenerate

Returns a new instance of KeyGenerate.

Parameters:

  • a (Integer)

    seconds interval for Window use

  • optional (String)

    app namespace



34
35
36
37
# File 'lib/tally_counter.rb', line 34

def initialize(interval, namespace = nil)
  @window    = TallyCounter::Window.new(interval)
  @namespace = namespace
end

Instance Method Details

#for(time, offset = 0) ⇒ Object

Parameters:

  • time (Time)

    for a key, often Time.now

  • offset (Integer) (defaults to: 0)

    for window to step back



41
42
43
44
# File 'lib/tally_counter.rb', line 41

def for(time, offset = 0)
  timestamp = @window.floor(time, offset).to_i
  [@namespace, NAME, timestamp].compact.join(':')
end