Class: Crabbs::Page

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

Instance Method Summary collapse

Constructor Details

#initialize(html, url) ⇒ Page

Returns a new instance of Page.



6
7
8
9
# File 'lib/crabbs/page.rb', line 6

def initialize(html, url)
  @html = Nokogiri::HTML(html)
  @url = url
end

Instance Method Details



11
12
13
14
15
16
17
18
19
20
# File 'lib/crabbs/page.rb', line 11

def links
  links = @html.css('a[href]').map { |a| Crabbs::Link.new a['href'] }

  links
    .select { |link| link.same_host_as? @url }
    .select(&:has_valid_fragment?)
    .select(&:has_html_extension?)
    .map { |link| link.join @url }
    .uniq
end