Class: AVR::Clock
Direct Known Subclasses
Defined Under Namespace
Classes: Sink
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#sinks ⇒ Object
readonly
Returns the value of attribute sinks.
-
#ticks ⇒ Object
Returns the value of attribute ticks.
-
#watches ⇒ Object
readonly
Returns the value of attribute watches.
Instance Method Summary collapse
- #clear_sinks ⇒ Object
-
#initialize(name = nil) ⇒ Clock
constructor
A new instance of Clock.
- #notify_at_tick(tick, sink) ⇒ Object
- #push_sink(sink) ⇒ Object
- #tick(_source = nil, _ticks = nil) ⇒ Object
- #unshift_sink(sink) ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ Clock
Returns a new instance of Clock.
52 53 54 55 56 57 58 59 60 |
# File 'lib/avr/clock.rb', line 52 def initialize(name = nil) @name = name @sinks = T.let([], T::Array[Sink]) @watches = T.let({}, T::Hash[Integer, T.untyped]) @ticks = T.let(0, Integer) @count = T.let(0, Integer) @scale = T.let(1, Integer) @last_tick = T.let(0, Integer) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
43 44 45 |
# File 'lib/avr/clock.rb', line 43 def count @count end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/avr/clock.rb', line 34 def name @name end |
#scale ⇒ Object
Returns the value of attribute scale.
49 50 51 |
# File 'lib/avr/clock.rb', line 49 def scale @scale end |
#sinks ⇒ Object (readonly)
Returns the value of attribute sinks.
37 38 39 |
# File 'lib/avr/clock.rb', line 37 def sinks @sinks end |
#ticks ⇒ Object
Returns the value of attribute ticks.
46 47 48 |
# File 'lib/avr/clock.rb', line 46 def ticks @ticks end |
#watches ⇒ Object (readonly)
Returns the value of attribute watches.
40 41 42 |
# File 'lib/avr/clock.rb', line 40 def watches @watches end |
Instance Method Details
#clear_sinks ⇒ Object
73 74 75 |
# File 'lib/avr/clock.rb', line 73 def clear_sinks @sinks = [] end |
#notify_at_tick(tick, sink) ⇒ Object
78 79 80 81 |
# File 'lib/avr/clock.rb', line 78 def notify_at_tick(tick, sink) @watches[tick] ||= [] @watches[tick] << sink end |
#push_sink(sink) ⇒ Object
68 69 70 |
# File 'lib/avr/clock.rb', line 68 def push_sink(sink) sinks.push(sink) end |
#tick(_source = nil, _ticks = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/avr/clock.rb', line 84 def tick(_source = nil, _ticks = nil) @count += 1 if (@count % @scale).zero? @last_tick = @ticks sinks.each do |sink| sink.tick(self, @ticks) end watches[@ticks]&.each do |watch| watch.tick(self, @ticks) end @ticks += 1 end @last_tick end |
#unshift_sink(sink) ⇒ Object
63 64 65 |
# File 'lib/avr/clock.rb', line 63 def unshift_sink(sink) sinks.unshift(sink) end |