Class: Anaximander::Discovery::Links

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable, Enumerable
Defined in:
lib/anaximander/discovery/links.rb

Overview

Collection of internal links on the given page.

Relative Paths

‘Anaximander::Discovery::Links` converts all relative paths into absolute paths using the base URL of the page being crawled.

# http://example.com
<a href="/contact">Contact</a>

Anaximander::Discovery::Links.new(Nokogiri::HTML(open("http://example.com")))
# => ["http://example.com/contact"]

Exclusions

- External links (ones outside the domain of the page
- Hash links (Javascript style links with href of "#")

Example

page = Nokogiri::HTML(open("http://example.com"))

Anaximander::Discovery::Links.new(page)
# => ["http://www.iana.org/domains/example"]

Instance Method Summary collapse

Constructor Details

#initialize(page, url) ⇒ Links

Parameters

page [Nokogiri::HTML] Parsed html of the page.
url  [String|URI] URL of the page to discover.


40
41
42
43
# File 'lib/anaximander/discovery/links.rb', line 40

def initialize(page, url)
  @page = page
  @url  = Url.new(url)
end

Instance Method Details

#<=>(other) ⇒ Object



49
50
51
# File 'lib/anaximander/discovery/links.rb', line 49

def <=>(other)
  to_a <=> other.to_a
end

#each(&block) ⇒ Object



45
46
47
# File 'lib/anaximander/discovery/links.rb', line 45

def each(&block)
  links.each(&block)
end