Class: Nokogiri::XML::Document
- Inherits:
-
Object
- Object
- Nokogiri::XML::Document
- Defined in:
- lib/quiverstaskrunner/helpers/xmlhelper.rb
Instance Method Summary collapse
- #add_node_under_css_selector(css_selector, node) ⇒ Object
- #update_node_at_css_selector(css_selector, attributes = {}, content = {}) ⇒ Object
Instance Method Details
#add_node_under_css_selector(css_selector, node) ⇒ Object
6 7 8 9 |
# File 'lib/quiverstaskrunner/helpers/xmlhelper.rb', line 6 def add_node_under_css_selector(css_selector, node) nodes = node.is_a?(Array) ? node : [node] self.css(css_selector).each { |n| nodes.each { |x| n.add_child(x) } } end |
#update_node_at_css_selector(css_selector, attributes = {}, content = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/quiverstaskrunner/helpers/xmlhelper.rb', line 11 def update_node_at_css_selector(css_selector, attributes={}, content={}) attribute_exists = !attributes.nil? && attributes.any? content_exists = !content.nil? && content.any? self.css(css_selector).each { |n| if attribute_exists attributes.each { |k,v| n[k.to_s] = v} end if content_exists n.content = content end } end |