Class: Sablon::Parser::MailMerge::ComplexField

Inherits:
MergeField
  • Object
show all
Defined in:
lib/sablon/parser/mail_merge.rb

Constant Summary

Constants inherited from MergeField

MergeField::KEY_PATTERN

Instance Attribute Summary

Attributes inherited from MergeField

#block_reference_count

Instance Method Summary collapse

Methods inherited from MergeField

#expression

Constructor Details

#initialize(nodes) ⇒ ComplexField

Returns a new instance of ComplexField.



45
46
47
48
49
# File 'lib/sablon/parser/mail_merge.rb', line 45

def initialize(nodes)
  super()
  @nodes = nodes
  @raw_expression = @nodes.flat_map {|n| n.search(".//w:instrText").map(&:content) }.join
end

Instance Method Details

#ancestors(*args) ⇒ Object



70
71
72
# File 'lib/sablon/parser/mail_merge.rb', line 70

def ancestors(*args)
  @nodes.first.ancestors(*args)
end

#end_nodeObject



78
79
80
# File 'lib/sablon/parser/mail_merge.rb', line 78

def end_node
  @nodes.last
end

#removeObject

removes only the merge field in question



61
62
63
# File 'lib/sablon/parser/mail_merge.rb', line 61

def remove
  remove_or_decrement_ref(*@nodes)
end

#remove_parent(selector) ⇒ Object



65
66
67
68
# File 'lib/sablon/parser/mail_merge.rb', line 65

def remove_parent(selector)
  node = @nodes.first
  remove_or_decrement_ref(node.ancestors(selector).first)
end

#replace(content, env) ⇒ Object



55
56
57
58
# File 'lib/sablon/parser/mail_merge.rb', line 55

def replace(content, env)
  replace_field_display(pattern_node, content, env)
  (@nodes - [pattern_node]).each(&:remove)
end

#start_nodeObject



74
75
76
# File 'lib/sablon/parser/mail_merge.rb', line 74

def start_node
  @nodes.first
end

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sablon/parser/mail_merge.rb', line 51

def valid?
  separate_node && get_display_node(pattern_node) && expression
end