Class: Qcmd::Action
- Inherits:
-
Object
- Object
- Qcmd::Action
- Defined in:
- lib/qcmd/action.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Class Method Summary collapse
-
.evaluate(action_input) ⇒ Object
initialize and evaluate in one shot.
Instance Method Summary collapse
-
#command ⇒ Object
the raw command.
- #evaluate ⇒ Object
-
#initialize(expression) ⇒ Action
constructor
A new instance of Action.
- #osc_address ⇒ Object
- #osc_address=(value) ⇒ Object
- #osc_arguments ⇒ Object
-
#osc_message ⇒ Object
the default command builder.
- #parse(expression) ⇒ Object
Constructor Details
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/qcmd/action.rb', line 3 def code @code end |
Class Method Details
.evaluate(action_input) ⇒ Object
initialize and evaluate in one shot
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/qcmd/action.rb', line 6 def self.evaluate action_input is_cue_action = false if action_input.is_a?(String) is_cue_action = %w(cue cue_id).include?(action_input.split.first) else is_cue_action = ['cue', 'cue_id', :cue, :cue_id].include?(action_input.first) end if is_cue_action CueAction.new(action_input).evaluate else Action.new(action_input).evaluate end end |
Instance Method Details
#command ⇒ Object
the raw command
94 95 96 |
# File 'lib/qcmd/action.rb', line 94 def command code[0] end |
#evaluate ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/qcmd/action.rb', line 30 def evaluate if code.size == 0 nil else @code = code.map do |token| if token.is_a?(Action) Qcmd.debug "[Action evaluate] evaluating nested action: #{ token.code.inspect }" token.evaluate else token end end Qcmd.debug "[Action evaluate] evaluating code: #{ code.inspect }" end end |
#osc_address ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/qcmd/action.rb', line 76 def osc_address # prefix w/ slash if necessary if %r[^/] !~ code[0].to_s "/#{ code[0] }" else code[0] end end |
#osc_address=(value) ⇒ Object
85 86 87 |
# File 'lib/qcmd/action.rb', line 85 def osc_address=(value) code[0] = value end |
#osc_arguments ⇒ Object
89 90 91 |
# File 'lib/qcmd/action.rb', line 89 def osc_arguments stringify code[1..-1] end |
#osc_message ⇒ Object
the default command builder
72 73 74 |
# File 'lib/qcmd/action.rb', line 72 def OSC::Message.new osc_address.to_s, *osc_arguments end |
#parse(expression) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/qcmd/action.rb', line 49 def parse(expression) # unwrap nested arrays if expression.size == 1 && expression[0].is_a?(Array) expression = expression[0] end expression.map do |token| if token.is_a?(Array) if [:cue, :cue_id].include?(token.first) Qcmd.debug "nested cue action detected in #{ expression.inspect }" CueAction.new(token) else Action.new(token) end else token end end.tap {|exp| Qcmd.debug "[Action parse] returning: #{ exp.inspect }" } end |