Class: Bulldog::Processor::ArgumentTree

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldog/processor/argument_tree.rb

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#headsObject (readonly)

Returns the value of attribute heads.



11
12
13
# File 'lib/bulldog/processor/argument_tree.rb', line 11

def heads
  @heads
end

#rootObject (readonly)

Returns the value of attribute root.



11
12
13
# File 'lib/bulldog/processor/argument_tree.rb', line 11

def root
  @root
end

#stylesObject (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

#argumentsObject

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

#inspectObject



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