Class: Lorax::InsertDelta
- Defined in:
- lib/lorax/delta/insert_delta.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
Returns the value of attribute node.
-
#position ⇒ Object
Returns the value of attribute position.
-
#xpath ⇒ Object
Returns the value of attribute xpath.
Instance Method Summary collapse
- #apply!(document) ⇒ Object
- #descriptor ⇒ Object
-
#initialize(node, xpath, position) ⇒ InsertDelta
constructor
A new instance of InsertDelta.
Methods inherited from Delta
Constructor Details
#initialize(node, xpath, position) ⇒ InsertDelta
Returns a new instance of InsertDelta.
5 6 7 8 9 |
# File 'lib/lorax/delta/insert_delta.rb', line 5 def initialize(node, xpath, position) @node = node @xpath = xpath @position = position end |
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
3 4 5 |
# File 'lib/lorax/delta/insert_delta.rb', line 3 def node @node end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/lorax/delta/insert_delta.rb', line 3 def position @position end |
#xpath ⇒ Object
Returns the value of attribute xpath.
3 4 5 |
# File 'lib/lorax/delta/insert_delta.rb', line 3 def xpath @xpath end |
Instance Method Details
#apply!(document) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/lorax/delta/insert_delta.rb', line 11 def apply!(document) # TODO: patch nokogiri to make inserting node copies efficient parent = document.at_xpath(xpath) raise NodeNotFoundError, xpath unless parent insert_node(node.dup, parent, position) end |
#descriptor ⇒ Object
18 19 20 |
# File 'lib/lorax/delta/insert_delta.rb', line 18 def descriptor [:insert, {:xpath => xpath, :position => position, :content => node.to_s}] end |