Class: Circuits::Terminal::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/circuits/terminal/output.rb

Overview

Gets set tcked then read

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Output

Creates the output

Parameters:

  • opts (Hash) (defaults to: {})

    Options to create the Output with

Options Hash (opts):

  • :state (Boolean)

    The initial state of the Output

  • :terminal (Input, Output)

    The terminal to read from



10
11
12
13
# File 'lib/circuits/terminal/output.rb', line 10

def initialize(opts = {})
  @next_state = opts[:terminal] || opts[:state] || false
  tock
end

Instance Method Details

#getBoolean

Gets the state of the terminal

Returns:

  • (Boolean)

    The state of the output



17
18
19
# File 'lib/circuits/terminal/output.rb', line 17

def get
  @state
end

#set(state) ⇒ Object

The next state

Parameters:

  • state (Boolean, Terminal)

    The terminal or state to output



23
24
25
# File 'lib/circuits/terminal/output.rb', line 23

def set(state)
  @next_state = state
end

#tockObject

Sets the state what was last set



28
29
30
31
32
33
34
# File 'lib/circuits/terminal/output.rb', line 28

def tock
  if [Input, Output].include? @next_state.class
    @state = @next_state.get
  else
    @state = @next_state
  end
end