Module: AssertXPath::CommonXPathExtensions

Included in:
Hpricot::Doc, Hpricot::Elem, REXML::Element, XML::Node
Defined in:
lib/assert_xpath.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/assert_xpath.rb', line 81

def[](index)
  if symbol = symbolic?(index)
    return attributes[symbol]  if attributes.has_key? symbol
    raise_magic_member_not_found(symbol, caller)
  end

  return super  #  ERGO  test this works?
end

#identifiable?(str) ⇒ Boolean

ERGO self. ?

Returns:

  • (Boolean)


97
98
99
# File 'lib/assert_xpath.rb', line 97

def identifiable?(str)  #  ERGO  self. ?
  return str =~ /^ [[:alpha:]] [[:alnum:]_]* $/ix
end

#raise_magic_member_not_found(symbol, whats_caller_ERGO) ⇒ Object

Raises:



90
91
92
93
94
95
# File 'lib/assert_xpath.rb', line 90

def raise_magic_member_not_found(symbol, whats_caller_ERGO)
  raise AFE,  #  ERGO  merge with other raiser(s)
        "missing attribute: `#{symbol}` in " +
          "<#{ name } #{ attributes.keys.join(' ') }>",
        whats_caller_ERGO
end

#symbolic?(index) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/assert_xpath.rb', line 77

def symbolic?(index)
  return index.to_s  if (index.kind_of? String or index.kind_of? Symbol)
end

#tribute(block) ⇒ Object

ERGO mock the YarWiki and run its tests locally!!!



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/assert_xpath.rb', line 103

def tribute(block)
  stash = {}  # put back the ones we changed!

  if block
    varz = instance_variables

    attributes.each do |key, value|
      if identifiable?(key)  #  deal if the key ain't a valid variable
        key = "@#{ key }"
        stash[key] = instance_variable_get(key)  if varz.include?(key)
#p stash[key]
        instance_variable_set key, value
      end
    end

    return instance_eval(&block)
  end
ensure  #  put them back!
  stash.each{|key, value|  instance_variable_set(key, value)  }
end