-
Notifications
You must be signed in to change notification settings - Fork 2
/
terminal.rb
35 lines (32 loc) · 1.01 KB
/
terminal.rb
1
2
3
4
5
6
7
8
9
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
module Circuits
# A terminal holds a logical state, it can be attatched to components
class Terminal
# Creates the terminal
# @param opts [Hash] Options to create the Output with
# @option opts [Boolean] :state The initial state of the Output
def initialize(opts = {})
@terminal = opts[:terminal]
@next_state = opts[:state] || false
@state = opts[:state] || false
end
# Gets the state of the terminal
# @return [Boolean] The state of the output
def get
@state
end
# The other terminal to read from next {#tock} or a state to be in now
# @param [Boolean, Terminal] terminal The terminal or state to output
def set(terminal)
if terminal.class == Terminal
@terminal = terminal
else
@terminal = nil
@state = @next_state = terminal
end
end
# Sets the state to be that of the terminal or state last passed by {#set}
def tock
@state = @terminal.nil? ? @next_state : @terminal.get
end
end
end