Class: Nokogiri::XML::Node
- Inherits:
-
Object
- Object
- Nokogiri::XML::Node
- Defined in:
- lib/niceogiri/core_ext/nokogiri.rb
Overview
Nokogiri::Node extensions
Direct Known Subclasses
Instance Method Summary collapse
-
#[]=(name, value) ⇒ Object
Override Nokogiri’s attribute setter to add the ability to kill an attribute by setting it to nil and to be able to lookup an attribute by symbol.
- #attr_set ⇒ Object
-
#find_first(*paths) ⇒ Object
Return the first element at a specified xpath.
- #nokogiri_xpath ⇒ Object
-
#xpath(*paths) ⇒ Object
(also: #find)
Override Nokogiri’s #xpath method to add the ability to use symbols for lookup and namespace designation.
Instance Method Details
#[]=(name, value) ⇒ Object
Override Nokogiri’s attribute setter to add the ability to kill an attribute by setting it to nil and to be able to lookup an attribute by symbol
17 18 19 20 21 22 23 24 25 |
# File 'lib/niceogiri/core_ext/nokogiri.rb', line 17 def []=(name, value) name = name.to_s if value.nil? remove_attribute name else value = value.is_a?(Array) ? value.join : value attr_set name, value.to_s end end |
#attr_set ⇒ Object
11 |
# File 'lib/niceogiri/core_ext/nokogiri.rb', line 11 alias_method :attr_set, :[]= |
#find_first(*paths) ⇒ Object
Return the first element at a specified xpath
43 44 45 |
# File 'lib/niceogiri/core_ext/nokogiri.rb', line 43 def find_first(*paths) xpath(*paths).first end |
#nokogiri_xpath ⇒ Object
27 |
# File 'lib/niceogiri/core_ext/nokogiri.rb', line 27 alias_method :nokogiri_xpath, :xpath |
#xpath(*paths) ⇒ Object Also known as: find
Override Nokogiri’s #xpath method to add the ability to use symbols for lookup and namespace designation
30 31 32 33 34 35 36 37 38 |
# File 'lib/niceogiri/core_ext/nokogiri.rb', line 30 def xpath(*paths) paths[0] = paths[0].to_s if paths.size > 1 && (namespaces = paths.pop).is_a?(Hash) paths << namespaces.inject({}) { |h,v| h[v[0].to_s] = v[1]; h } end nokogiri_xpath *paths end |