Class: Docx::NodesToFix
- Inherits:
-
Object
- Object
- Docx::NodesToFix
- Defined in:
- lib/docx/nodes_to_fix.rb
Instance Attribute Summary collapse
-
#current_node ⇒ Object
Returns the value of attribute current_node.
-
#node_list ⇒ Object
Returns the value of attribute node_list.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #fix ⇒ Object
- #forget ⇒ Object
-
#initialize ⇒ NodesToFix
constructor
A new instance of NodesToFix.
- #remember(node, index) ⇒ Object
Constructor Details
#initialize ⇒ NodesToFix
Returns a new instance of NodesToFix.
4 5 6 |
# File 'lib/docx/nodes_to_fix.rb', line 4 def initialize forget end |
Instance Attribute Details
#current_node ⇒ Object
Returns the value of attribute current_node.
3 4 5 |
# File 'lib/docx/nodes_to_fix.rb', line 3 def current_node @current_node end |
#node_list ⇒ Object
Returns the value of attribute node_list.
3 4 5 |
# File 'lib/docx/nodes_to_fix.rb', line 3 def node_list @node_list end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/docx/nodes_to_fix.rb', line 3 def value @value end |
Instance Method Details
#fix ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/docx/nodes_to_fix.rb', line 24 def fix @node_list.each do |obj| node = obj[:node] range = obj[:range] new_val = node.value new_val[range] = value.to_s || '' node.value = new_val if new_val =~ /^\s+/ && node.parent node.parent.add_attribute('xml:space', 'preserve') end self.value = nil end end |
#forget ⇒ Object
8 9 10 11 12 |
# File 'lib/docx/nodes_to_fix.rb', line 8 def forget @current_node = nil @node_list = [] @value = '' end |
#remember(node, index) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/docx/nodes_to_fix.rb', line 14 def remember(node, index) new_node = current_node.nil? || current_node != node if new_node @current_node = node @node_list << {:node => node, :range => index..index} else @node_list.last[:range] = (node_list.last[:range].min)..index end end |