Class: Nokogiri::XML::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/blather/core_ext/nokogiri.rb

Direct Known Subclasses

Blather::XMPPNode

Instance Method Summary collapse

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

Parameters:

  • name (#to_s)

    the name of the attribute

  • value (#to_s, nil)

    the new value or nil to remove it



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_setObject

: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

See Also:



36
37
38
# File 'lib/blather/core_ext/nokogiri.rb', line 36

def find_first(*paths)
  xpath(*paths).first
end

#nokogiri_xpathObject



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