Sha256: 050fbbbc7ef98d5d32d640a616f4f0b7b0ed5323ea9e5099821d18f9b4bbc1d2
Contents?: true
Size: 1.76 KB
Versions: 2
Compression:
Stored size: 1.76 KB
Contents
require 'colorize' require 'sitemap_check/sitemap' class SitemapCheck def self.check $stdout.sync = true new.check end def initialize(http = HTTPClient.new) self.start_time = Time.now self.exit_code = 0 puts "Expanding Sitemaps from #{ENV['CHECK_URL']}" self.sitemaps = Sitemap.new(ENV['CHECK_URL'], http).sitemaps end def check check_indexes check_pages stats exit exit_code end protected attr_accessor :sitemaps, :exit_code, :start_time, :logger private def stats puts "checked #{sitemaps.count} sitemaps and #{checked_pages} in #{time_taken} seconds" puts "thats #{pages_per_second} pages per second" end def pages_per_second checked_pages / time_taken end def time_taken Time.now - start_time end def checked_pages sitemaps.map(&:checked).reduce(&:+) end def check_indexes sitemaps.reject(&:exists?).each do |sitemap| puts " #{sitemap.url} does not exist".red.bold self.exit_code = 1 end puts '' end def good_sitemaps sitemaps.select(&:exists?) end def check_pages good_sitemaps.each { |sitemap| check_pages_in(sitemap) } end def check_pages_in(sitemap) puts "Checking #{sitemap.url}" if sitemap.missing_pages.any? missing_pages(sitemap) else if sitemap.checked > 0 a_ok(sitemap) else nothing_doing end end puts '' end def missing_pages(sitemap) self.exit_code = 1 puts " checked #{sitemap.checked} pages and #{sitemap.missing_pages.count} were missing".red.bold end def a_ok(sitemap) puts " checked #{sitemap.checked} pages and everything was ok".green.bold end def nothing_doing puts ' this sitemap did not contain any pages'.green end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sitemap_check-0.1.2 | lib/sitemap_check.rb |
sitemap_check-0.1.1 | lib/sitemap_check.rb |