Class: AdHocTemplate::Parser::TagNode

Inherits:
Parser::Node
  • Object
show all
Defined in:
lib/ad_hoc_template/parser.rb

Direct Known Subclasses

FallbackNode, IterationNode, ValueNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/ad_hoc_template/parser.rb', line 12

def type
  @type
end

Instance Method Details

#cast(node_type = Parser::TagNode) ⇒ Object



46
47
48
# File 'lib/ad_hoc_template/parser.rb', line 46

def cast(node_type=Parser::TagNode)
  node_type.new.concat(clone)
end

#contains_any_fallback_tag?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ad_hoc_template/parser.rb', line 30

def contains_any_fallback_tag?
  any? {|sub_node| sub_node.kind_of? Parser::FallbackNode }
end

#contains_any_value_assigned_tag_node?(record) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/ad_hoc_template/parser.rb', line 20

def contains_any_value_assigned_tag_node?(record)
  each_tag_node do |node|
    return true if node.contains_any_value_assigned_tag_node?(record)
  end
end

#contains_any_value_tag?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ad_hoc_template/parser.rb', line 26

def contains_any_value_tag?
  each_tag_node {|node| return true if node.contains_any_value_tag? }
end

#format_sub_nodes(data_loader, memo) ⇒ Object



55
56
57
# File 'lib/ad_hoc_template/parser.rb', line 55

def format_sub_nodes(data_loader, memo)
  map {|leaf| leaf.accept(data_loader, memo) }.join
end

#inner_iteration_tag_labelsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ad_hoc_template/parser.rb', line 34

def inner_iteration_tag_labels
  names = []
  each_tag_node do |node|
    next unless node.kind_of? IterationNode
    names.push node.type if node.type
    inner_names = node.inner_iteration_tag_labels
    names.concat inner_names if inner_names
  end

  names unless names.empty?
end

#push(node = TreeStack::Node.new) ⇒ Object



14
15
16
17
18
# File 'lib/ad_hoc_template/parser.rb', line 14

def push(node=TreeStack::Node.new)
  first_leaf = node[0]
  node[0] = assign_value_to_type(first_leaf) if empty? && first_leaf
  super
end

#select_fallback_nodesObject



50
51
52
53
# File 'lib/ad_hoc_template/parser.rb', line 50

def select_fallback_nodes
  nodes = select {|sub_node| sub_node.kind_of? Parser::FallbackNode }
  nodes.empty? ? nil : nodes
end