Sha256: c3a6eaaa0c9796a870bf015f2141958a11a8ff483b279c8c181fb9dfc00151f8
Contents?: true
Size: 1.75 KB
Versions: 4
Compression:
Stored size: 1.75 KB
Contents
# #-- # 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 #++ # module GScraper class Page < Array # # Creates a new Page object with the given _elements_. If a _block_ # is given, it will be passed the newly created Page object. # def initialize(elements=[],&block) super(elements) block.call(self) if block end # # Returns a mapped Array of the elements within the Page using the # given _block_. If the _block_ is not given, the page will be # returned. # # page.map # => Page # # page.map { |element| element.field } # => [...] # def map(&block) return self unless block mapped = [] each { |element| mapped << block.call(element) } return mapped end # # Selects the elements within the Page which match the given _block_. # # page.select { |element| element.field =~ /ruby/i } # def select(&block) self.class.new(super(&block)) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
gscraper-0.2.0 | lib/gscraper/page.rb |
gscraper-0.2.1 | lib/gscraper/page.rb |
gscraper-0.2.2 | lib/gscraper/page.rb |
gscraper-0.2.3 | lib/gscraper/page.rb |