Class: Hpricot::Elem
- Inherits:
-
Object
- Object
- Hpricot::Elem
- Includes:
- AssertXPath::CommonXPathExtensions
- Defined in:
- lib/assert_xpath.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#[](index) ⇒ Object
:nodoc:.
- #drill(&block) ⇒ Object
-
#method_missing(*args, &block) ⇒ Object
:nodoc:.
- #node_type ⇒ Object
-
#text ⇒ Object
simulate REXML style - fetch child with text.
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:
878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/assert_xpath.rb', line 878 def method_missing(*args, &block) #:nodoc: symbol = args.shift.to_s.sub(/\!$/, '') children.grep(Hpricot::Elem).each do |kid| if kid.name == symbol kid.tribute(block) # ERGO assert on return value # ERGO pass kid in for if you want it return kid end end raise_magic_member_not_found(symbol, caller) # ERGO repurpose! end |
Instance Method Details
#[](index) ⇒ Object
:nodoc:
840 841 842 843 844 845 846 847 848 |
# File 'lib/assert_xpath.rb', line 840 def [](index) #:nodoc: # ERGO do this conflict with anything? if symbol = symbolic?(index) return attributes[symbol] if attributes.has_key? symbol raise_magic_member_not_found(symbol, caller) end super end |
#drill(&block) ⇒ Object
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
# File 'lib/assert_xpath.rb', line 858 def drill(&block) if block # ERGO harmonize with bang! version # ERGO deal if the key ain't a valid variable # ERGO get method_missing to stop returning [] unless tribute(block) # ERGO pass in self (node)? sib = self nil while (sib = sib.next_sibling) and sib.node_type != :element q = sib and _bequeath_attributes(sib).drill(&block) return sib if q raise Test::Unit::AssertionFailedError.new("can't find beyond <#{_esc xpath}>") end end return self # ERGO if block returns false/nil, find siblings until it passes. # throw a test failure if it don't. # ERGO axis concept end |
#node_type ⇒ Object
854 855 856 |
# File 'lib/assert_xpath.rb', line 854 def node_type return :element # ERGO make me less useless end |
#text ⇒ Object
simulate REXML style - fetch child with text
850 851 852 |
# File 'lib/assert_xpath.rb', line 850 def text # simulate REXML style - fetch child with text return (text? ? to_s : '') + children.select(&:text?).map(&:to_s).compact.join end |