Class: GScraper::Search::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank, title, url, summary, cached_url = nil, similar_url = nil) ⇒ Result

Creates a new GScraper::Search::Result object.

Parameters:

  • rank (Integer)

    The rank of the result.

  • title (String)

    The title of the result.

  • summary (String)

    The summary of the result.

  • cached_url (URI::HTTP) (defaults to: nil)

    The Cached URL for the result.

  • similar_url (URI::HTTP) (defaults to: nil)

    The Similar Query URL for the result.



64
65
66
67
68
69
70
71
72
73
# File 'lib/gscraper/search/result.rb', line 64

def initialize(rank,title,url,summary,cached_url=nil,similar_url=nil)
  @agent = GScraper.web_agent

  @rank        = rank
  @title       = title
  @url         = url
  @summary     = summary
  @cached_url  = cached_url
  @similar_url = similar_url
end

Instance Attribute Details

#cached_urlObject (readonly)

URL of the cached result page



41
42
43
# File 'lib/gscraper/search/result.rb', line 41

def cached_url
  @cached_url
end

#rankObject (readonly)

Rank of the result page



29
30
31
# File 'lib/gscraper/search/result.rb', line 29

def rank
  @rank
end

#similar_urlObject (readonly)

URL of the similar results Query



44
45
46
# File 'lib/gscraper/search/result.rb', line 44

def similar_url
  @similar_url
end

#summaryObject (readonly)

Summary from the result page



38
39
40
# File 'lib/gscraper/search/result.rb', line 38

def summary
  @summary
end

#titleObject (readonly)

Title of the result page



32
33
34
# File 'lib/gscraper/search/result.rb', line 32

def title
  @title
end

#urlObject (readonly)

URL of the result page



35
36
37
# File 'lib/gscraper/search/result.rb', line 35

def url
  @url
end

Instance Method Details

#cached_pageMechanize::Page

Fetches the Cached Page of the result.

Returns:

  • (Mechanize::Page)

    The Cached Page for the result.



91
92
93
# File 'lib/gscraper/search/result.rb', line 91

def cached_page
  @agent.get(@cached_url) if @cached_url
end

#pageMechanize::Page

Fetches the page of the result.

Returns:

  • (Mechanize::Page)

    The page the result represents.



81
82
83
# File 'lib/gscraper/search/result.rb', line 81

def page
  @agent.get(@url)
end

#to_sString

The result's title.

Returns:

  • (String)

    The title of the result.



101
102
103
# File 'lib/gscraper/search/result.rb', line 101

def to_s
  @title.to_s
end