Class: BadLinkFinder::PageChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bad_link_finder/page_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, page, result_cache) ⇒ PageChecker

Returns a new instance of PageChecker.



5
6
7
8
9
10
# File 'lib/bad_link_finder/page_checker.rb', line 5

def initialize(host, page, result_cache)
  host = host.chomp('/') + '/'
  @page = page
  @page_url = URI.join(host, page.path).to_s
  @result_cache = result_cache
end

Instance Attribute Details

#page_urlObject (readonly)

Returns the value of attribute page_url.



12
13
14
# File 'lib/bad_link_finder/page_checker.rb', line 12

def page_url
  @page_url
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bad_link_finder/page_checker.rb', line 14

def each_bad_link(&block)
  if @bad_links
    @bad_links.each(&block)
  else
    @bad_links = @page.links.map do |raw_link|
      link = @result_cache.fetch(raw_link) || @result_cache.store(raw_link, BadLinkFinder::Link.new(@page_url, raw_link))

      unless link.valid?
        yield link
        next link
      end
    end.compact
  end
end