Class: PM::Trigger
- Inherits:
-
Object
- Object
- PM::Trigger
- Defined in:
- lib/patchmaster/trigger.rb
Overview
A Trigger executes code when it sees a particular array of bytes. Instruments have zero or more triggers.
Since we want to save them to files, we store the text representation as well.
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
-
#code_chunk ⇒ Object
Returns the value of attribute code_chunk.
Instance Method Summary collapse
-
#initialize(bytes, code_chunk) ⇒ Trigger
constructor
A new instance of Trigger.
- #method_missing(sym, *args) ⇒ Object
-
#signal(bytes) ⇒ Object
If
bytes
matches our @bytes array then run @code_chunk. - #to_s ⇒ Object
Constructor Details
#initialize(bytes, code_chunk) ⇒ Trigger
Returns a new instance of Trigger.
12 13 14 |
# File 'lib/patchmaster/trigger.rb', line 12 def initialize(bytes, code_chunk) @bytes, @code_chunk = bytes, code_chunk end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
16 17 18 |
# File 'lib/patchmaster/trigger.rb', line 16 def method_missing(sym, *args) PM::PatchMaster.instance.send(sym, *args) end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
10 11 12 |
# File 'lib/patchmaster/trigger.rb', line 10 def bytes @bytes end |
#code_chunk ⇒ Object
Returns the value of attribute code_chunk.
10 11 12 |
# File 'lib/patchmaster/trigger.rb', line 10 def code_chunk @code_chunk end |
Instance Method Details
#signal(bytes) ⇒ Object
If bytes
matches our @bytes array then run @code_chunk.
21 22 23 24 25 26 27 |
# File 'lib/patchmaster/trigger.rb', line 21 def signal(bytes) if bytes == @bytes pm = PM::PatchMaster.instance @code_chunk.run(pm) pm.gui.refresh if pm.gui end end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/patchmaster/trigger.rb', line 29 def to_s "#{@bytes.inspect} => #{(@code_chunk.text || '# no block text found').gsub(/\n\s*/, '; ')}" end |