Class: Nokogiri::XML::Node
- Inherits:
-
Object
- Object
- Nokogiri::XML::Node
- Defined in:
- lib/blather/core_ext/nokogiri.rb
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
:nodoc:.
-
#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
15 16 17 18 |
# File 'lib/blather/core_ext/nokogiri.rb', line 15 def []=(name, value) name = name.to_s value.nil? ? remove_attribute(name) : attr_set(name, value.to_s) end |
#attr_set ⇒ Object
:nodoc:
9 |
# File 'lib/blather/core_ext/nokogiri.rb', line 9 alias_method :attr_set, :[]= |
#find_first(*paths) ⇒ Object
Return the first element at a specified xpath
36 37 38 |
# File 'lib/blather/core_ext/nokogiri.rb', line 36 def find_first(*paths) xpath(*paths).first end |
#nokogiri_xpath ⇒ Object
20 |
# File 'lib/blather/core_ext/nokogiri.rb', line 20 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
23 24 25 26 27 28 29 30 31 |
# File 'lib/blather/core_ext/nokogiri.rb', line 23 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 |