Class: FindDeadLink::HtmlDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/find_dead_link/html_doc.rb

Constant Summary collapse

IGNORE_URLS_START_WITH =
['#', 'javascript', 'mailto']

Instance Method Summary collapse

Constructor Details

#initialize(html_content) ⇒ HtmlDoc

Returns a new instance of HtmlDoc.



5
6
7
# File 'lib/find_dead_link/html_doc.rb', line 5

def initialize(html_content)
  @html_content = html_content
end

Instance Method Details



9
10
11
12
13
# File 'lib/find_dead_link/html_doc.rb', line 9

def get_links
  @html_content.css('a').collect do |link| 
    link["href"] unless ignore?(link["href"])
  end.compact
end

#ignore?(url) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/find_dead_link/html_doc.rb', line 15

def ignore?(url)
  return true if url.nil?
  IGNORE_URLS_START_WITH.each{|element|  return true if url.start_with?(element) }
  false
end