def match(obj, attr=nil)
return match(Element.new(obj, attr)) if attr
return obj=~@name.to_s if obj.is_a?(Regexp)
return @name==obj if obj.is_a?(Symbol)
return is_a?(obj) if obj.is_a?(Module)
raise ArgumentError unless obj.is_a?(Element)
return false unless @name==obj.name
obj.attributes.all? do |k, v|
(v.nil? && !@attributes.include?(k)) ||
(@attributes.include?(k) && (v.is_a?(Regexp) ? v =~ @attributes[k] : PCString[v] == PCString[@attributes[k]]))
end and obj.contents.all? do |i|
case i
when Element
has_element?(i)
when String
pcstring_contents.include?(PCString.new(i))
when PCString
pcstring_contents.include?(i)
when Regexp
@contents.any?{|c| c.is_a?(String) and i=~c}
end
end
end