Sha256: 0e075a422afe107a78a31f66d7354d663acf9dc8aabcb5b2de413a6831e0feee

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

require 'awesome_bot/links'
require 'awesome_bot/net'
require 'awesome_bot/output'
require 'awesome_bot/result'

# Check links
module AwesomeBot
  NUMBER_OF_THREADS = 10

  class << self
    def check(content, options=nil)
      if options.nil?
        white_listed = nil
        skip_dupe = false
        timeout = nil
      else
        white_listed = options['whitelist']
        skip_dupe = options['allowdupe']
        timeout = options['timeout']
      end

      links = links_filter(links_find(content))

      r = Result.new(links, white_listed)
      r.skip_dupe = skip_dupe

      r.dupes = r.links.select { |e| r.links.count(e) > 1 }

      yield "Links to check: #{r.links.count}" if block_given?
      yield ", #{r.links_white_listed.count} white listed" if r.white_listing && block_given?
      uniq = r.links.uniq.count

      yield ", #{uniq} unique" if uniq != r.links.count && block_given?
      yield "\n" if block_given?
      total = pad_list r.links.uniq
      r.links.uniq.each_with_index do |u, j|
        yield "  #{pad_text j + 1, total}. #{u} \n" if block_given?
      end

      yield 'Checking URLs: ' if block_given? && r.links.count > 0
      r.status =
        statuses(r.links.uniq, NUMBER_OF_THREADS, timeout) do |s|
          yield log_status s if block_given?
        end
      yield "\n" if block_given?

      return r if !r.white_listing || (r.links_white_listed.count == 0)

      yield 'Checking white listed URLs: ' if block_given?
      r.white_listed =
        statuses(r.links_white_listed.uniq, NUMBER_OF_THREADS, nil) do |s|
          yield log_status s if block_given?
        end
      yield "\n" if block_given?

      r
    end # check
  end # class
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
awesome_bot-1.13.10 lib/awesome_bot/check.rb
awesome_bot-1.13.9 lib/awesome_bot/check.rb
awesome_bot-1.13.8 lib/awesome_bot/check.rb
awesome_bot-1.13.7 lib/awesome_bot/check.rb
awesome_bot-1.13.6 lib/awesome_bot/check.rb
awesome_bot-1.13.5 lib/awesome_bot/check.rb
awesome_bot-1.13.4 lib/awesome_bot/check.rb
awesome_bot-1.13.3 lib/awesome_bot/check.rb
awesome_bot-1.13.2 lib/awesome_bot/check.rb
awesome_bot-1.13.1 lib/awesome_bot/check.rb
awesome_bot-1.13.0 lib/awesome_bot/check.rb
awesome_bot-1.12.1 lib/awesome_bot/check.rb
awesome_bot-1.12.0 lib/awesome_bot/check.rb
awesome_bot-1.11.0 lib/awesome_bot/check.rb
awesome_bot-1.10.0 lib/awesome_bot/check.rb