Sha256: 8a3e9eb1c8f981a087664140b2317f79d4bf9c83b362e4f01ebbffcc769e0642
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
require 'rpaste/pastebin/result_set' require 'rpaste/rpaste' require 'hpricot' module RPaste module PasteBin class Recent < ResultSet URL = 'http://pastebin.com/' MAX_LENGTH = 10 # # Returns the list of recent pastes on PasteBin. If _opts_ are # given they will be used in accessing the PasteBin website. If a # _block_ is given, it will be passed the list of recent pastes. # def self.get(opts={},&block) len = opts[:length] if (len.nil? || len>MAX_LENGTH) len = MAX_LENGTH else len = len.to_i end page = Hpricot(RPaste.open(URL,opts)) rows = page.search('#menu/ul/li')[0...len] metadata = rows.map do |row| name = row.search('a').first.get_attribute('href').gsub(/^.*\//,'') author = row.search('a').inner_text ago = row.inner_text Metadata.new(name,author,ago) end new_recent = self.new(metadata) block.call(new_recent) if block return new_recent end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rpaste-0.0.9 | lib/rpaste/pastebin/recent.rb |