Class: Loba::Internal::TimeKeeper Private
- Inherits:
-
Object
- Object
- Loba::Internal::TimeKeeper
- Includes:
- Singleton
- Defined in:
- lib/loba/internal/time_keeper.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal class for tracking time stamps; should not be used directly
Instance Attribute Summary collapse
-
#timenum ⇒ Object
readonly
private
Count of timestamping occurances so far.
-
#timewas ⇒ Object
readonly
private
Previous timestamped Time value.
Instance Method Summary collapse
-
#initialize ⇒ TimeKeeper
constructor
private
A new instance of TimeKeeper.
-
#ping ⇒ Hash
private
Increments timestamping, including attributes
timenum
andtimewas
. -
#reset! ⇒ NilClass
private
Resets timestamping.
Constructor Details
#initialize ⇒ TimeKeeper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TimeKeeper.
14 15 16 |
# File 'lib/loba/internal/time_keeper.rb', line 14 def initialize reset! end |
Instance Attribute Details
#timenum ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Count of timestamping occurances so far
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/loba/internal/time_keeper.rb', line 10 class TimeKeeper include Singleton attr_reader :timewas, :timenum def initialize reset! end # Increments timestamping, including attributes +timenum+ and +timewas+ # @return [Hash] timestamp details # * :number => [Integer] incremented count of pings so far (attribute +timenum+) # * :now => [Time] current date and time # * :change => [Float] difference in seconds from any previous ping or reset def ping @timenum += 1 now = Time.now change = now - @timewas @timewas = now { number: @timenum, now: now, change: change } end # Resets timestamping # @return [NilClass] nil def reset! @timewas = Time.now @timenum = 0 nil end end |
#timewas ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Previous timestamped Time value
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/loba/internal/time_keeper.rb', line 10 class TimeKeeper include Singleton attr_reader :timewas, :timenum def initialize reset! end # Increments timestamping, including attributes +timenum+ and +timewas+ # @return [Hash] timestamp details # * :number => [Integer] incremented count of pings so far (attribute +timenum+) # * :now => [Time] current date and time # * :change => [Float] difference in seconds from any previous ping or reset def ping @timenum += 1 now = Time.now change = now - @timewas @timewas = now { number: @timenum, now: now, change: change } end # Resets timestamping # @return [NilClass] nil def reset! @timewas = Time.now @timenum = 0 nil end end |
Instance Method Details
#ping ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Increments timestamping, including attributes timenum
and timewas
23 24 25 26 27 28 29 30 |
# File 'lib/loba/internal/time_keeper.rb', line 23 def ping @timenum += 1 now = Time.now change = now - @timewas @timewas = now { number: @timenum, now: now, change: change } end |
#reset! ⇒ NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resets timestamping
34 35 36 37 38 39 |
# File 'lib/loba/internal/time_keeper.rb', line 34 def reset! @timewas = Time.now @timenum = 0 nil end |