Sha256: 237239259ac52510e9cb51e68ba4fc80b1cb85f176990f5f144faa407e689f03

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

# -*- encoding: utf-8 -*-

module SiteValidator
  ##
  # Validator module is the one in charge of doing the validation loop
  # for all pages on a sitemap and output the errors
  #
  module Validator
    attr_writer :printer

    extend self

    ##
    # Parses a remote xml sitemap and checks markup validation for each url
    # Shows progress on dot-style (...F...FFE..). A dot is a valid page,
    # an F is a page with errors, and an E is an exception
    # After the checking is done, a detailed summary is written to filename
    def check(url, filename, max_pages)
      sitemap = SiteValidator::Sitemap.new(url, max_pages.to_i)
      say "Validating #{sitemap.pages.length} pages"

      sitemap.pages.each do |page|
        say_inline page.valid? ? "." : (page.errors.nil? ? 'E' : 'F')
      end

      SiteValidator::Reporter.generate_html(sitemap, filename)
      say "\nValidation finished, see the report at #{filename}"
    end

    private

    def printer
      @printer ||= STDOUT
    end

    ##
    # A shorter alias for printer.puts
    def say(text)
      printer.puts text
    end

    ##
    # A shorter alias for printer.print
    def say_inline(text)
      printer.print text
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
site_validator-2.1.2 lib/site_validator/validator.rb
site_validator-2.1.1 lib/site_validator/validator.rb
site_validator-2.1.0 lib/site_validator/validator.rb
site_validator-2.0.0 lib/site_validator/validator.rb
site_validator-1.7.4 lib/site_validator/validator.rb
site_validator-1.7.3 lib/site_validator/validator.rb
site_validator-1.7.2 lib/site_validator/validator.rb
site_validator-1.7.1 lib/site_validator/validator.rb
site_validator-1.7.0 lib/site_validator/validator.rb
site_validator-1.6.0 lib/site_validator/validator.rb
site_validator-1.5.0 lib/site_validator/validator.rb