Class: Bulldog::Processor::ArgumentTree
- Inherits:
-
Object
- Object
- Bulldog::Processor::ArgumentTree
- Defined in:
- lib/bulldog/processor/argument_tree.rb
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#heads ⇒ Object
readonly
Returns the value of attribute heads.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
- #add(style, arguments, &callback) ⇒ Object
-
#arguments ⇒ Object
Return the list of arguments the tree represents.
-
#each_callback(&block) ⇒ Object
Yield each callback, along with the styles they apply to, in the order they appear in the tree.
-
#initialize(styles) ⇒ ArgumentTree
constructor
A new instance of ArgumentTree.
- #inspect ⇒ Object
- #output(style, path) ⇒ Object
Constructor Details
#initialize(styles) ⇒ ArgumentTree
Returns a new instance of ArgumentTree.
4 5 6 7 8 9 |
# File 'lib/bulldog/processor/argument_tree.rb', line 4 def initialize(styles) @styles = styles @root = Node.new(styles) @heads = {} styles.each{|s| @heads[s] = @root} end |
Instance Attribute Details
#heads ⇒ Object (readonly)
Returns the value of attribute heads.
11 12 13 |
# File 'lib/bulldog/processor/argument_tree.rb', line 11 def heads @heads end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/bulldog/processor/argument_tree.rb', line 11 def root @root end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
11 12 13 |
# File 'lib/bulldog/processor/argument_tree.rb', line 11 def styles @styles end |
Instance Method Details
#add(style, arguments, &callback) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bulldog/processor/argument_tree.rb', line 13 def add(style, arguments, &callback) # Assume that if the arguments are the same for a node, the # callback will be identical. child = heads[style].children.find do |node| node.arguments == arguments end if child child.styles << style else child = Node.new([style], arguments, &callback) heads[style].children << child end heads[style] = child end |
#arguments ⇒ Object
Return the list of arguments the tree represents.
41 42 43 44 45 46 47 48 |
# File 'lib/bulldog/processor/argument_tree.rb', line 41 def arguments arguments = visit_node_for_arguments([], root, false) # Don't specify -write for the last output file. arguments[-2] == '-write' or raise "[BULLDOG BUG]: expected second last argument to be -write in: #{arguments.inspect}" arguments.delete_at(-2) arguments end |
#each_callback(&block) ⇒ Object
Yield each callback, along with the styles they apply to, in the order they appear in the tree.
54 55 56 |
# File 'lib/bulldog/processor/argument_tree.rb', line 54 def each_callback(&block) visit_node_for_callbacks(root, block) end |
#inspect ⇒ Object
32 33 34 35 36 |
# File 'lib/bulldog/processor/argument_tree.rb', line 32 def inspect io = StringIO.new inspect_node(io, @root) io.string end |
#output(style, path) ⇒ Object
28 29 30 |
# File 'lib/bulldog/processor/argument_tree.rb', line 28 def output(style, path) heads[style].outputs << path end |