Class: Loba::Internal::TimeKeeper Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeTimeKeeper

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

#timenumObject (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

#timewasObject (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

#pingHash

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

Returns:

  • (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



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

Returns:

  • (NilClass)

    nil



34
35
36
37
38
39
# File 'lib/loba/internal/time_keeper.rb', line 34

def reset!
  @timewas = Time.now
  @timenum = 0

  nil
end