def PageElement.matches(chunk, how_to_match)
if chunk.is_a? Array
chunk.each do |tag|
return true if tag.is_a? NavigableString and matches(tag, how_to_match)
end
return false
elsif how_to_match.is_a? Proc
return how_to_match.call(chunk)
elsif chunk.is_a? Tag
chunk = chunk.name
end
unless chunk.is_a? String
chunk = chunk.to_s
end
if how_to_match.is_a? Regexp
return how_to_match.match(chunk) != nil
elsif how_to_match.is_a? Array
return how_to_match.find {|x| x == chunk} != nil
elsif how_to_match.is_a? Hash
return how_to_match[chunk] != nil
else
return how_to_match.to_s == chunk
end
end