Class: Magellan::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/magellan/result.rb

Overview

The resulting data from crawling a url

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, url, destination_url, linked_resources, content_type) ⇒ Result

create a new result, with the status code, url, destination url, linked resources and content type, see attr_readers for more information about these fields



14
15
16
17
18
19
20
# File 'lib/magellan/result.rb', line 14

def initialize(status_code,url,destination_url,linked_resources,content_type) # :nodoc:
  @status_code = status_code
  @url = url
  @destination_url = destination_url
  @linked_resources = linked_resources
  @content_type = content_type
end

Instance Attribute Details

#destination_urlObject (readonly)

The destination URL after following redirects



9
10
11
# File 'lib/magellan/result.rb', line 9

def destination_url
  @destination_url
end

#linked_resourcesObject (readonly)

Relative linked resources (based off of the kinds of links you are looking for)



11
12
13
# File 'lib/magellan/result.rb', line 11

def linked_resources
  @linked_resources
end

#status_codeObject (readonly)

The http status code returned by the request for the specified url



5
6
7
# File 'lib/magellan/result.rb', line 5

def status_code
  @status_code
end

#urlObject (readonly)

The original URL requested



7
8
9
# File 'lib/magellan/result.rb', line 7

def url
  @url
end

Instance Method Details

#absolute_linked_resourcesObject

Absolute links to resources



23
24
25
# File 'lib/magellan/result.rb', line 23

def absolute_linked_resources # :nodoc:
  absolute_links = linked_resources.map { |linked_resource| linked_resource.to_s.to_absolute_url(destination_url) }.compact
end

#html_content?Boolean

Was the document text/html

Returns:

  • (Boolean)


28
29
30
# File 'lib/magellan/result.rb', line 28

def html_content?
  @content_type.starts_with?("text/html")
end