Class: Hpricot::Elem

Inherits:
Object
  • Object
show all
Includes:
AssertXPath::CommonXPathExtensions
Defined in:
lib/assert_xpath.rb

Overview

:nodoc:

Instance Method Summary collapse

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:



857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'lib/assert_xpath.rb', line 857

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:



819
820
821
822
823
824
825
826
827
# File 'lib/assert_xpath.rb', line 819

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



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/assert_xpath.rb', line 837

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_typeObject



833
834
835
# File 'lib/assert_xpath.rb', line 833

def node_type
  return :element  #  ERGO  make me less useless
end

#textObject

simulate REXML style - fetch child with text



829
830
831
# File 'lib/assert_xpath.rb', line 829

def text  #  simulate REXML style - fetch child with text
  return (text? ? to_s : '') + children.select(&:text?).map(&:to_s).compact.join
end