Class: PM::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/patchmaster/patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, start_bytes = nil, stop_bytes = nil) ⇒ Patch

Returns a new instance of Patch.



7
8
9
10
11
# File 'lib/patchmaster/patch.rb', line 7

def initialize(name, start_bytes=nil, stop_bytes=nil)
  @name, @start_bytes, @stop_bytes = name, start_bytes, stop_bytes
  @connections = []
  @running = false
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



5
6
7
# File 'lib/patchmaster/patch.rb', line 5

def connections
  @connections
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/patchmaster/patch.rb', line 5

def name
  @name
end

#start_bytesObject

Returns the value of attribute start_bytes.



5
6
7
# File 'lib/patchmaster/patch.rb', line 5

def start_bytes
  @start_bytes
end

#stop_bytesObject

Returns the value of attribute stop_bytes.



5
6
7
# File 'lib/patchmaster/patch.rb', line 5

def stop_bytes
  @stop_bytes
end

Instance Method Details

#<<(conn) ⇒ Object



13
14
15
# File 'lib/patchmaster/patch.rb', line 13

def <<(conn)
  @connections << conn
end

#inputsObject



17
18
19
# File 'lib/patchmaster/patch.rb', line 17

def inputs
  @connections.map(&:input).uniq
end

#running?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/patchmaster/patch.rb', line 29

def running?
  @running
end

#startObject

Send start_bytes to each connection.



22
23
24
25
26
27
# File 'lib/patchmaster/patch.rb', line 22

def start
  unless @running
    @connections.each { |conn| conn.start(@start_bytes) }
    @running = true
  end
end

#stopObject

Send stop_bytes to each connection, then call #stop on each connection.



34
35
36
37
38
39
# File 'lib/patchmaster/patch.rb', line 34

def stop
  if @running
    @running = false
    @connections.each { |conn| conn.stop(@stop_bytes) }
  end
end