def fetch(iterator, name, args, block)
attrs = args[:attrs]
limit = args[:limit]
text = args[:text]
attrs ||= {}
if attrs != nil and not attrs.respond_to? :keys
attrs = {'class' => attrs}
end
bucket = []
catch(:stop_iteration) do
iterator.call do |item|
match = false
if block
match = true if block.call(item)
elsif item.is_a? Tag
if not text and (not name or PageElement.matches(item, name))
match = true
attrs.each_pair do |attr, matchAgainst|
check = item[attr]
unless PageElement.matches(check, matchAgainst)
match = false
break
end
end
end
elsif text
match = PageElement.matches(item, text)
end
if match
bucket.push(item)
if limit and bucket.length >= limit
throw :stop_iteration
end
end
end
end
return bucket
end