# File lib/rubyful_soup.rb, line 114
  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
          #A tag matches if its name matches and its attributes line up.
          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
          #A text matches if its string value matches the given text
          #criterion.
          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