# File lib/microformat.rb, line 183
    def build_hash(doc, attributes = @attributes)
      hash = {}

      # rel="bookmark" pattern
      if bookmark = extract_bookmark(doc)
        hash[:bookmark] = bookmark
      end

      # rel="license" pattern
      if license = extract_license(doc)
        hash[:license] = license
      end

      # rel="tag" pattern
      if tags = extract_tags(doc)
        hash[:tags] = tags
      end

      [:one, :many].each do |name|
        attributes[name].each do |attribute|
          is_hash = attribute.is_a? Hash
          key = is_hash ? attribute.keys.first : attribute

          found = doc/".#{key.no_bang.to_s.gsub('_','-')}"
          raise InvalidMicroformat if found.empty? && key.to_s =~ /!/
          next if found.empty?

          if is_hash && attribute[key].is_a?(Hash)
            built_hash = build_hash(found, attribute[key])
            key = key.no_bang
            if built_hash.size.zero? && found.size.nonzero?
              hash[key] = found.map { |f| parse_element(f) }
              hash[key] = hash[key].first if name == :one
            else
              hash[key] = built_hash
            end
          else
            target = is_hash ? attribute[key] : nil
            key = key.no_bang
            if name == :many
              hash[key] ||= [] 
              hash[key] += found.map { |f| parse_element(f, target) }
            else
              hash[key] = parse_element(found.first, target) 
            end
          end
          hash[key] = hash[key].first if hash[key].is_a?(Array) && hash[key].size == 1
        end
      end

      hash.merge extract_includes(doc)
    end