Class: Sablon::Parser::MailMerge::ComplexField
- Inherits:
-
MergeField
- Object
- MergeField
- Sablon::Parser::MailMerge::ComplexField
- Defined in:
- lib/sablon/parser/mail_merge.rb
Constant Summary
Constants inherited from MergeField
Instance Attribute Summary
Attributes inherited from MergeField
Instance Method Summary collapse
- #ancestors(*args) ⇒ Object
- #end_node ⇒ Object
-
#initialize(nodes) ⇒ ComplexField
constructor
A new instance of ComplexField.
-
#remove ⇒ Object
removes only the merge field in question.
- #remove_parent(selector) ⇒ Object
- #replace(content, env) ⇒ Object
- #start_node ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from MergeField
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_node ⇒ Object
78 79 80 |
# File 'lib/sablon/parser/mail_merge.rb', line 78 def end_node @nodes.last end |
#remove ⇒ Object
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_node ⇒ Object
74 75 76 |
# File 'lib/sablon/parser/mail_merge.rb', line 74 def start_node @nodes.first end |
#valid? ⇒ Boolean
51 52 53 |
# File 'lib/sablon/parser/mail_merge.rb', line 51 def valid? separate_node && get_display_node(pattern_node) && expression end |