Class: TallyCounter::Window
- Inherits:
-
Object
- Object
- TallyCounter::Window
- Defined in:
- lib/tally_counter.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
-
#floor(time, offset = 0) ⇒ Object
Returns the floor time for a given window.
-
#initialize(interval) ⇒ Window
constructor
A new instance of Window.
Constructor Details
#initialize(interval) ⇒ Window
Returns a new instance of Window.
12 13 14 |
# File 'lib/tally_counter.rb', line 12 def initialize(interval) @interval = interval end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
9 10 11 |
# File 'lib/tally_counter.rb', line 9 def interval @interval end |
Instance Method Details
#floor(time, offset = 0) ⇒ Object
Returns the floor time for a given window. For example, if the interval is 5 minutes and it is 12:38, the floor would be 12:35. If offset is 1, the floor would be 12:30
22 23 24 25 |
# File 'lib/tally_counter.rb', line 22 def floor(time, offset = 0) epoch_time = time.to_i - interval * offset Time.at((epoch_time / interval) * interval) end |