Class: Diagnostics::Sample::Controls::Clock::Incrementing
- Inherits:
-
Object
- Object
- Diagnostics::Sample::Controls::Clock::Incrementing
- Includes:
- Initializer
- Defined in:
- lib/diagnostics/sample/controls/clock.rb
Defined Under Namespace
Modules: Defaults
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #next ⇒ Object (also: #now)
- #start_time_nanoseconds ⇒ Object
Instance Attribute Details
#elapsed_seconds ⇒ Object
12 13 14 |
# File 'lib/diagnostics/sample/controls/clock.rb', line 12 def elapsed_seconds @elapsed_seconds ||= 0 end |
Class Method Details
.build(interval: nil, start_time: nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/diagnostics/sample/controls/clock.rb', line 19 def self.build(interval: nil, start_time: nil) interval ||= Defaults.interval_seconds start_time ||= Defaults.start_time interval_nanoseconds = interval * 1_000_000 new(start_time, interval_nanoseconds) end |
.example(**args) ⇒ Object
28 29 30 |
# File 'lib/diagnostics/sample/controls/clock.rb', line 28 def self.example(**args) build(**args) end |
Instance Method Details
#next ⇒ Object Also known as: now
32 33 34 35 36 37 38 |
# File 'lib/diagnostics/sample/controls/clock.rb', line 32 def next offset = elapsed_seconds self.elapsed_seconds += interval_nanoseconds start_time_nanoseconds + offset end |
#start_time_nanoseconds ⇒ Object
40 41 42 |
# File 'lib/diagnostics/sample/controls/clock.rb', line 40 def start_time_nanoseconds start_time.to_i * 1_000_000 end |