module Zenaton::Traits::WithDuration
Module to calculate duration between events
Public Instance Methods
_get_duration()
click to toggle source
@return [Integer, NilClass] Duration in seconds
# File lib/zenaton/traits/with_duration.rb, line 10 def _get_duration return unless @buffer now, now_dup = _init_now_then @buffer.each do |time_unit, time_value| now_dup = _apply_duration(time_unit, time_value, now_dup) end diff_in_seconds(now, now_dup) end
Private Instance Methods
_apply_duration(time_unit, time_value, time)
click to toggle source
# File lib/zenaton/traits/with_duration.rb, line 40 def _apply_duration(time_unit, time_value, time) time + time_value.send(time_unit) end
_init_now_then()
click to toggle source
# File lib/zenaton/traits/with_duration.rb, line 28 def _init_now_then Time.zone = self.class.class_variable_get(:@@_timezone) || 'UTC' now = Time.zone.now Time.zone = nil # Resets time zone [now, now.dup] end
_push(method_name, value)
click to toggle source
# File lib/zenaton/traits/with_duration.rb, line 35 def _push(method_name, value) @buffer ||= {} @buffer[method_name] = value end
diff_in_seconds(before, after)
click to toggle source
# File lib/zenaton/traits/with_duration.rb, line 44 def diff_in_seconds(before, after) (after - before).to_i end