Sha256: c599217f5df6b57feb52b70ae99c6768d65d7ec273729362a2f40d4bdb8b28a7

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

module W3clove
  require 'open-uri'
  require 'nokogiri'
  require 'w3c_validators'
  include W3CValidators

  extend self

  ##
  # Parses a remote xml sitemap and checks markup validation for each url within
  def check_sitemap(sitemap_url)
    validator = MarkupValidator.new

    totals = {:errors => 0, :warnings => 0}

    doc = Nokogiri::XML(open(sitemap_url))
    doc.css('loc').collect {|item| item.text}.each do |url|
      puts "\nValidating markup of #{url}"
      results = validator.validate_uri(url)
      puts "#{results.errors.count} errors, #{results.warnings.count} warnings"
      totals[:errors] += results.errors.count
      totals[:warnings] += results.warnings.count
    end

    puts "\nTOTAL:#{totals[:errors]} errors, #{totals[:warnings]} warnings"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
w3clove-0.0.1 lib/w3clove.rb