Class: GScraper::Search::Page

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

Instance Method Summary collapse

Methods inherited from Page

#initialize, #map, #select

Constructor Details

This class inherits a constructor from GScraper::Page

Instance Method Details

#cached_pagesArray<Mechanize::Page>

Returns the Cached Pages of the results in the page.

Returns:

  • (Array<Mechanize::Page>)

    The Cached Pages of the results.



351
352
353
# File 'lib/gscraper/search/page.rb', line 351

def cached_pages
  each_cached_page.to_a
end

#cached_pages_of {|result| ... } ⇒ Array<Mechanize::Page>

Returns the cached pages of the results that match the given block.

Examples:

page.cached_pages_of { |result| result.title =~ /dude/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<Mechanize::Page>)

    The Cached Page of the results which match the given block.



475
476
477
# File 'lib/gscraper/search/page.rb', line 475

def cached_pages_of(&block)
  results_with(&block).cached_pages
end

#cached_urlsArray<URI::HTTP>

Returns the Cached URLs of the results in the page.

Returns:

  • (Array<URI::HTTP>)

    The Cached URLs of the results.



341
342
343
# File 'lib/gscraper/search/page.rb', line 341

def cached_urls
  each_cached_url.to_a
end

#cached_urls_of {|result| ... } ⇒ Array<URI::HTTP>

Returns the Cached URLs of the results that match the given block.

Examples:

page.cached_urls_of { |result| result.title =~ /howdy/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<URI::HTTP>)

    The Cached URLs of the results which match the given block.



456
457
458
# File 'lib/gscraper/search/page.rb', line 456

def cached_urls_of(&block)
  results_with(&block).cached_urls
end

#each_cached_page {|cached_page| ... } ⇒ Enumerator

Iterates over each result's cached pages within the page.

Examples:

each_cached_page { |page| puts page.readlines }

Yields:

  • (cached_page)

    The given block will be passed the Cached Page of each result in the page.

Yield Parameters:

  • cached_page (Mechanize::Page)

    The Cached Page of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



263
264
265
266
267
268
269
# File 'lib/gscraper/search/page.rb', line 263

def each_cached_page
  return enum_for(:each_cached_page) unless block_given?

  each do |result|
    yield result.cached_page if result.cached_page
  end
end

#each_cached_url {|cached_url| ... } ⇒ Enumerator

Iterates over each result's cached URLs within the page.

Examples:

each_cached_url { |cached_url| puts cached_url }

Yields:

  • (cached_url)

    The given block will be passed the Cached URL of each result in the page.

Yield Parameters:

  • cached_url (URI::HTTP)

    The Cached URL of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



239
240
241
242
243
244
245
# File 'lib/gscraper/search/page.rb', line 239

def each_cached_url
  return enum_for(:each_cached_url) unless block_given?

  each do |result|
    yield result.cached_url if result.cached_url
  end
end

#each_rank {|rank| ... } ⇒ Enumerator

Iterates over each result's rank within the page.

Examples:

each_rank { |rank| puts rank }

Yields:

  • (rank)

    The given block will be passed the ranks of each result in the page.

Yield Parameters:

  • rank (Integer)

    The rank of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



151
152
153
154
155
# File 'lib/gscraper/search/page.rb', line 151

def each_rank
  return enum_for(:each_rank) unless block_given?

  each { |result| yield result.rank }
end

#each_similar_url {|similar_url| ... } ⇒ Enumerator

Iterates over each result's similar Query URLs within the page.

Examples:

each_similar_url { |similar_url| puts similar_url }

Yields:

  • (similar_url)

    The given block will be passed the Similar Query URL of each result in the page.

Yield Parameters:

  • similar_url (URI::HTTP)

    The Cached URL of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



287
288
289
290
291
292
293
# File 'lib/gscraper/search/page.rb', line 287

def each_similar_url
  return enum_for(:each_similar_url) unless block_given?

  each do |result|
    yield result.similar_url if result.similar_url
  end
end

#each_summary {|summary| ... } ⇒ Enumerator

Iterates over each result's summary within the page.

Examples:

each_summary { |summary| puts summary }

Yields:

  • (summary)

    The given block will be passed the summary of each result in the page.

Yield Parameters:

  • summary (String)

    The summary of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



217
218
219
220
221
# File 'lib/gscraper/search/page.rb', line 217

def each_summary
  return enum_for(:each_summary) unless block_given?

  each { |result| yield result.summary }
end

#each_title {|title| ... } ⇒ Enumerator

Iterates over each result's title within the page.

Examples:

each_title { |title| puts title }

Yields:

  • (title)

    The given block will be passed the title of each result in the page.

Yield Parameters:

  • title (String)

    The title of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



173
174
175
176
177
# File 'lib/gscraper/search/page.rb', line 173

def each_title
  return enum_for(:each_title) unless block_given?

  each { |result| yield result.title }
end

#each_url {|url| ... } ⇒ Enumerator

Iterates over each result's url within the page.

Examples:

each_url { |url| puts url }

Yields:

  • (url)

    The given block will be passed the URL of each result in the page.

Yield Parameters:

  • url (URI::HTTP)

    The URL of a result in the page.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



195
196
197
198
199
# File 'lib/gscraper/search/page.rb', line 195

def each_url
  return enum_for(:each_url) unless block_given?

  each { |result| yield result.url }
end

#ranksArray<Integer>

Returns the ranks of the results in the page.

Returns:

  • (Array<Integer>)

    The ranks of the results.



301
302
303
# File 'lib/gscraper/search/page.rb', line 301

def ranks
  each_rank.to_a
end

#ranks_of {|result| ... } ⇒ Array<Integer>

Returns the ranks of the results that match the given block.

Examples:

page.ranks_of { |result| result.title =~ /awesome/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<Integer>)

    The ranks of the results which match the given block.



380
381
382
# File 'lib/gscraper/search/page.rb', line 380

def ranks_of(&block)
  results_with(&block).ranks
end

#results_with_summary(summary) {|result| ... } ⇒ Array<Result>

Selects the results with the matching summary.

Examples:

page.results_with_summary(/cheese cake/) # => Page
page.results_with_summary(/Scientifically/) do |result|
  puts result.url
end

Parameters:

  • summary (String, Regexp)

    The summary to search for.

Yields:

  • (result)

    The given block will be passed each matching result.

Yield Parameters:

  • result (Result)

    A result with the matching summary.

Returns:

  • (Array<Result>)

    The results with the matching summary.



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/gscraper/search/page.rb', line 123

def results_with_summary(summary)
  return enum_for(:results_with_summary,summary) unless block_given?

  results_with do |result|
    if result.summary.match(summary)
      yield result

      true
    end
  end
end

#results_with_title(title) {|result| ... } ⇒ Array<Result>

Selects the results with the matching title.

Examples:

page.results_with_title('hackety org') #=> Page
page.results_with_title(/awesome/) do |result|
  puts result.url
end

Parameters:

  • title (String, Regexp)

    The title to search for.

Yields:

  • (result)

    The given block will be passed each matching result.

Yield Parameters:

  • result (Result)

    A result with the matching title.

Returns:

  • (Array<Result>)

    The results with the matching title.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gscraper/search/page.rb', line 53

def results_with_title(title)
  return enum_for(:results_with_title,title) unless block_given?

  results_with do |result|
    if result.title.match(title)
      yield result

      true
    end
  end
end

#results_with_url(url) {|result| ... } ⇒ Array<Result>

Selects the results with the matching URL.

Examples:

page.results_with_url(/\.com/) # => Page
page.results_with_url(/^https:\/\//) do |result|
  puts result.title
end

Parameters:

  • url (String, Regexp)

    The URL to search for.

Yields:

  • (result)

    The given block will be passed each matching result.

Yield Parameters:

  • result (Result)

    A result with the matching URL.

Returns:

  • (Array<Result>)

    The results with the matching URL.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gscraper/search/page.rb', line 88

def results_with_url(url)
  return enum_for(:results_with_url,url) unless block_given?

  results_with do |result|
    if result.url.match(url)
      yield result

      true
    end
  end
end

#similar_urlsArray<URI::HTTP>

Returns the Similar Query URLs of the results in the page.

Returns:

  • (Array<URI::HTTP>)

    The Similar Query URLs of the results.



361
362
363
# File 'lib/gscraper/search/page.rb', line 361

def similar_urls
  each_similar_url.to_a
end

#similar_urls_of {|result| ... } ⇒ Array<URI::HTTP>

Returns the Similar Query URLs of the results that match the given block.

Examples:

page.similar_urls_of { |result| result.title =~ /what if/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<URI::HTTP>)

    The Similar Query URLs of the results which match the given block.



495
496
497
# File 'lib/gscraper/search/page.rb', line 495

def similar_urls_of(&block)
  results_with(&block).similar_urls
end

#summariesArray<String>

Returns the summaries of the results in the page.

Returns:

  • (Array<String>)

    The summaries of the results.



331
332
333
# File 'lib/gscraper/search/page.rb', line 331

def summaries
  each_summary.to_a
end

#summaries_of {|result| ... } ⇒ Array<String>

Returns the summaries of the results that match the given block.

Examples:

page.summaries_of { |result| result.title =~ /what if/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<String>)

    The summaries of the results which match the given block.



437
438
439
# File 'lib/gscraper/search/page.rb', line 437

def summaries_of(&block)
  results_with(&block).summaries
end

#titlesArray<String>

Returns the titles of the results in the page.

Returns:

  • (Array<String>)

    The titles of the results.



311
312
313
# File 'lib/gscraper/search/page.rb', line 311

def titles
  each_title.to_a
end

#titles_of {|result| ... } ⇒ Array<String>

Returns the titles of the results that match the given block.

Examples:

page.titles_of { |result| result.url.include?('www') }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<String>)

    The titles of the results which match the given block.



399
400
401
# File 'lib/gscraper/search/page.rb', line 399

def titles_of(&block)
  results_with(&block).titles
end

#urlsArray<URI::HTTP>

Returns the URLs of the results in the page.

Returns:

  • (Array<URI::HTTP>)

    The URLs of the results.



321
322
323
# File 'lib/gscraper/search/page.rb', line 321

def urls
  each_url.to_a
end

#urls_of {|result| ... } ⇒ Array<URI::HTTP>

Returns the URLs of the results that match the given block.

Examples:

page.urls_of { |result| result.summary =~ /awesome pants/ }

Yields:

  • (result)

    The given block will be used to filter the results in the page.

Yield Parameters:

  • result (Result)

    A result in the page.

Returns:

  • (Array<URI::HTTP>)

    The URLs of the results which match the given block.



418
419
420
# File 'lib/gscraper/search/page.rb', line 418

def urls_of(&block)
  results_with(&block).urls
end