lib/gscraper/search/page.rb in gscraper-0.3.0 vs lib/gscraper/search/page.rb in gscraper-0.4.0
- old
+ new
@@ -1,9 +1,9 @@
#
# GScraper - A web-scraping interface to various Google Services.
#
-# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
+# Copyright (c) 2007-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@@ -49,19 +49,17 @@
# page.results_with_title(/awesome/) do |result|
# puts result.url
# end
#
def results_with_title(title)
- unless block_given?
- enum_for(:results_with_title,title)
- else
- results_with do |result|
- if result.title.match(title)
- yield result
+ return enum_for(:results_with_title,title) unless block_given?
- true
- end
+ results_with do |result|
+ if result.title.match(title)
+ yield result
+
+ true
end
end
end
#
@@ -86,19 +84,17 @@
# page.results_with_url(/^https:\/\//) do |result|
# puts result.title
# end
#
def results_with_url(url)
- unless block_given?
- enum_for(:results_with_url,url)
- else
- results_with do |result|
- if result.url.match(url)
- yield result
+ return enum_for(:results_with_url,url) unless block_given?
- true
- end
+ results_with do |result|
+ if result.url.match(url)
+ yield result
+
+ true
end
end
end
#
@@ -123,19 +119,17 @@
# page.results_with_summary(/Scientifically/) do |result|
# puts result.url
# end
#
def results_with_summary(summary)
- unless block_given?
- enum_for(:results_with_summary,summary)
- else
- results_with do |result|
- if result.summary.match(summary)
- yield result
+ return enum_for(:results_with_summary,summary) unless block_given?
- true
- end
+ results_with do |result|
+ if result.summary.match(summary)
+ yield result
+
+ true
end
end
end
#
@@ -153,15 +147,13 @@
#
# @example
# each_rank { |rank| puts rank }
#
def each_rank
- unless block_given?
- enum_for(:each_rank)
- else
- each { |result| yield result.rank }
- end
+ return enum_for(:each_rank) unless block_given?
+
+ each { |result| yield result.rank }
end
#
# Iterates over each result's title within the page.
#
@@ -177,15 +169,13 @@
#
# @example
# each_title { |title| puts title }
#
def each_title
- unless block_given?
- enum_for(:each_title)
- else
- each { |result| yield result.title }
- end
+ return enum_for(:each_title) unless block_given?
+
+ each { |result| yield result.title }
end
#
# Iterates over each result's url within the page.
#
@@ -201,15 +191,13 @@
#
# @example
# each_url { |url| puts url }
#
def each_url
- unless block_given?
- enum_for(:each_url)
- else
- each { |result| yield result.url }
- end
+ return enum_for(:each_url) unless block_given?
+
+ each { |result| yield result.url }
end
#
# Iterates over each result's summary within the page.
#
@@ -225,15 +213,13 @@
#
# @example
# each_summary { |summary| puts summary }
#
def each_summary
- unless block_given?
- enum_for(:each_summary)
- else
- each { |result| yield result.summary }
- end
+ return enum_for(:each_summary) unless block_given?
+
+ each { |result| yield result.summary }
end
#
# Iterates over each result's cached URLs within the page.
#
@@ -249,16 +235,14 @@
#
# @example
# each_cached_url { |cached_url| puts cached_url }
#
def each_cached_url
- unless block_given?
- enum_for(:each_cached_url)
- else
- each do |result|
- yield result.cached_url if result.cached_url
- end
+ return enum_for(:each_cached_url) unless block_given?
+
+ each do |result|
+ yield result.cached_url if result.cached_url
end
end
#
# Iterates over each result's cached pages within the page.
@@ -275,16 +259,14 @@
#
# @example
# each_cached_page { |page| puts page.readlines }
#
def each_cached_page
- unless block_given?
- enum_for(:each_cached_page)
- else
- each do |result|
- yield result.cached_page if result.cached_page
- end
+ return enum_for(:each_cached_page) unless block_given?
+
+ each do |result|
+ yield result.cached_page if result.cached_page
end
end
#
# Iterates over each result's similar Query URLs within the page.
@@ -301,16 +283,14 @@
#
# @example
# each_similar_url { |similar_url| puts similar_url }
#
def each_similar_url
- unless block_given?
- enum_for(:each_similar_url)
- else
- each do |result|
- yield result.similar_url if result.similar_url
- end
+ return enum_for(:each_similar_url) unless block_given?
+
+ each do |result|
+ yield result.similar_url if result.similar_url
end
end
#
# Returns the ranks of the results in the page.
@@ -419,10 +399,10 @@
def titles_of(&block)
results_with(&block).titles
end
#
- # Returns the urls of the results that match the given block.
+ # Returns the URLs of the results that match the given block.
#
# @yield [result]
# The given block will be used to filter the results in the page.
#
# @yieldparam [Result] result