Class: Tickly::NodeProcessor
- Inherits:
-
Object
- Object
- Tickly::NodeProcessor
- Defined in:
- lib/tickly/node_processor.rb
Overview
A combination of a Parser and an Evaluator Evaluates a passed Nuke script without expanding it’s inner arguments. The TCL should look like Nuke’s node commands:
NodeClass {
foo
baz bad
}
You have to add the Classes that you want to instantiate for nodes using add_node_handler_class and every time the parser encounters that node the node will be instantiated and the node options (actually TCL commands) will be passed to the constructor, as a Ruby Hash with string keys. Every value of the knobs hash will be the AST as returned by the Parser.
class Blur
def initialize(knobs_hash)
puts knobs_hash.inspect
end
end
e = Tickly::NodeProcessor.new
e.add_node_handler_class Blur
e.parse(File.open("/path/to/script.nk")) do | blur_node |
# do whatever you want to the node instance
end
Defined Under Namespace
Classes: Ratchet
Instance Method Summary collapse
-
#add_node_handler_class(class_object) ⇒ Object
Add a Class object that can instantiate node handlers.
-
#initialize ⇒ NodeProcessor
constructor
A new instance of NodeProcessor.
-
#parse(io_or_str, &nuke_node_callback) ⇒ Object
Parses from the passed IO or string and yields every node that has been instantiated.
Constructor Details
#initialize ⇒ NodeProcessor
Returns a new instance of NodeProcessor.
29 30 31 32 33 |
# File 'lib/tickly/node_processor.rb', line 29 def initialize @evaluator = Tickly::Evaluator.new @parser = Ratchet.new @parser.expr_callback = method(:filter_expression) end |
Instance Method Details
#add_node_handler_class(class_object) ⇒ Object
Add a Class object that can instantiate node handlers. The last part of the class name has to match the name of the Nuke node that you want to capture. For example, to capture Tracker3 nodes a name like this will do:
Whatever::YourModule::Better::Tracker3
39 40 41 |
# File 'lib/tickly/node_processor.rb', line 39 def add_node_handler_class(class_object) @evaluator.add_node_handler_class(class_object) end |
#parse(io_or_str, &nuke_node_callback) ⇒ Object
Parses from the passed IO or string and yields every node that has been instantiated
45 46 47 48 49 |
# File 'lib/tickly/node_processor.rb', line 45 def parse(io_or_str, &nuke_node_callback) raise LocalJumpError, "NodeProcesssor#parse totally requires a block" unless block_given? @node_handler = nuke_node_callback @parser.parse(io_or_str) end |