Class: BadLinkFinder::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mirror_dir, path) ⇒ Page

Returns a new instance of Page.



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

def initialize(mirror_dir, path)
  @path = strip_html_ending(path)

  File.open(mirror_dir + path) do |file|
    @doc = Nokogiri::HTML(file.read)
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/bad_link_finder/page.rb', line 13

def path
  @path
end

Instance Method Details

#idObject



21
22
23
24
25
26
27
# File 'lib/bad_link_finder/page.rb', line 21

def id
  @id ||= begin
    if (article = @doc.xpath('(//article[not(ancestor::article)])').first)
      article['id']
    end
  end
end


15
16
17
18
19
# File 'lib/bad_link_finder/page.rb', line 15

def links
  @links ||= @doc.css('a').map do |a|
    strip_html_ending(a['href']) unless ignore_link?(a['href'])
  end.compact
end