Class: BadLinkFinder::Page
- Inherits:
-
Object
- Object
- BadLinkFinder::Page
- Defined in:
- lib/bad_link_finder/page.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(mirror_dir, path) ⇒ Page
constructor
A new instance of Page.
- #links ⇒ Object
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
#path ⇒ Object (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
#id ⇒ Object
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 |
#links ⇒ Object
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 |