Class: XML::Node
- Inherits:
-
Object
- Object
- XML::Node
- Includes:
- AssertXPath::CommonXPathExtensions
- Defined in:
- lib/assert_xpath.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#[](index) ⇒ Object
def attributes hash = {} each_attr{|attr| hash = attr.value } return hash # ERGO uh, was there a leaner way?? end.
- #get_path(xpath) ⇒ Object (also: #/)
- #inner_text(interstitial = '') ⇒ Object
-
#method_missing(*args, &block) ⇒ Object
:nodoc:.
- #search(xpath, &block) ⇒ Object (also: #each_element)
- #text ⇒ Object
Methods included from AssertXPath::CommonXPathExtensions
#identifiable?, #raise_magic_member_not_found, #symbolic?, #tribute
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
:nodoc:
937 938 939 940 941 942 943 944 945 946 947 948 949 |
# File 'lib/assert_xpath.rb', line 937 def method_missing(*args, &block) #:nodoc: # ERGO use the define_method trick here symbol = args.shift.to_s symbol.sub!(/\!$/, '') kid = if symbol == '/' find_first('/') else find_first("./#{symbol}") end return _bequeath_attributes(kid).drill(&block) if kid raise_magic_member_not_found(symbol, caller) end |
Instance Method Details
#[](index) ⇒ Object
def attributes
hash = {}
each_attr{|attr| hash[attr.name] = attr.value }
return hash # ERGO uh, was there a leaner way??
end
926 927 928 |
# File 'lib/assert_xpath.rb', line 926 def [](index) #:nodoc: return attributes[index.to_s] || super end |
#get_path(xpath) ⇒ Object Also known as: /
930 931 932 933 |
# File 'lib/assert_xpath.rb', line 930 def get_path(xpath) node = find_first(xpath.to_s) return _bequeath_attributes(node) if node end |
#inner_text(interstitial = '') ⇒ Object
914 915 916 917 918 |
# File 'lib/assert_xpath.rb', line 914 def inner_text(interstitial = '') array = [] self.find( 'descendant-or-self::text()' ).each{|x| array << x } return array.join(interstitial) end |
#search(xpath, &block) ⇒ Object Also known as: each_element
901 902 903 904 905 906 907 |
# File 'lib/assert_xpath.rb', line 901 def search(xpath, &block) if block find(xpath, "x:http://www.w3.org/1999/xhtml").each(&block) #find(xpath, &block) end return [find_first(xpath, "x:http://www.w3.org/1999/xhtml")] end |
#text ⇒ Object
910 911 912 |
# File 'lib/assert_xpath.rb', line 910 def text find_first('text()').to_s end |