lib/gscraper/search/page.rb in gscraper-0.1.7 vs lib/gscraper/search/page.rb in gscraper-0.2.0
- old
+ new
@@ -1,46 +1,35 @@
+#
+#--
+# GScraper - A web-scraping interface to various Google Services.
+#
+# Copyright (c) 2007-2008 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#++
+#
+
require 'gscraper/search/result'
+require 'gscraper/page'
module GScraper
module Search
- class Page < Array
+ class Page < GScraper::Page
#
- # Creates a new Page object with the given _results_.
- #
- def initialize(results=[])
- super(results)
- end
-
- #
- # Returns a mapped Array of the results within the Page using the
- # given _block_. If the _block_ is not given, the page will be
- # returned.
- #
- # page.map # => Page
- #
- # page.map { |result| result.url } # => [...]
- #
- def map(&block)
- return self unless block
-
- mapped = []
-
- each { |result| mapped << block.call(result) }
- return mapped
- end
-
- #
- # Selects the results within the Page which match the given _block_.
- #
- # page.select { |result| result.title =~ /ruby/i }
- #
- def select(&block)
- Page.new(super(&block))
- end
-
- #
# Selects the results using the specified _block_.
#
# page.results_with { |result| result.title =~ /blog/ }
#
def results_with(&block)
@@ -158,44 +147,34 @@
# the Page.
#
# page.cached_urls # => [...]
#
def cached_urls
- map { |result| result.cached_url }
+ map { |result| result.cached_url }.compact
end
#
# Returns an Array containing the cached pages of the results within
# the Page.
#
# page.cached_pages # => [...]
#
def cached_pages
- map { |result| result.cached_page }
+ map { |result| result.cached_page }.compact
end
#
# Returns an Array containing the similar Query URLs of the results
# within the Page.
#
# page.similar_urls # => [...]
#
def similar_urls
- map { |result| result.similar_url }
+ map { |result| result.similar_url }.compact
end
#
- # Returns an Array containing the similar Queries of the results
- # within the Page.
- #
- # page.similar_queries # => [...]
- #
- def similar_queries
- map { |result| result.similar_query }
- end
-
- #
# Iterates over each result's rank within the Page, passing each to
# the given _block_.
#
# each_rank { |rank| puts rank }
#
@@ -262,24 +241,10 @@
def each_similar_url(&block)
similar_urls.each(&block)
end
#
- # Iterates over each result's similar Query within the Page, passing
- # each to the given _block_.
- #
- # each_similar_query do |q|
- # q.first_page do |page|
- # puts page.urls.join("\n")
- # end
- # end
- #
- def each_similar_query(&block)
- similar_queries.each(&block)
- end
-
- #
# Returns the ranks of the results that match the specified _block_.
#
# page.ranks_of { |result| result.title =~ /awesome/ }
#
def ranks_of(&block)
@@ -341,19 +306,9 @@
#
# page.similar_urls_of { |result| result.title =~ /what if/ }
#
def similar_urls_of(&block)
results_with(&block).similar_urls
- end
-
- #
- # Returns the similar Queries of the results that match the
- # specified _block_.
- #
- # page.similar_queries_of { |result| result.title =~ /hackety/ }
- #
- def similar_queries_of(&block)
- results_with(&block).similar_queries
end
end
end
end