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:
832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/assert_xpath.rb', line 832 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:
794 795 796 797 798 799 800 801 802 |
# File 'lib/assert_xpath.rb', line 794 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
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
# File 'lib/assert_xpath.rb', line 812 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
808 809 810 |
# File 'lib/assert_xpath.rb', line 808 def node_type return :element # ERGO make me less useless end |
#text ⇒ Object
simulate REXML style - fetch child with text
804 805 806 |
# File 'lib/assert_xpath.rb', line 804 def text # simulate REXML style - fetch child with text return (text? ? to_s : '') + children.select(&:text?).map(&:to_s).compact.join end |