Class: RPaste::PasteBin::Recent
- Defined in:
- lib/rpaste/pastebin/recent.rb
Constant Summary collapse
- URL =
'http://pastebin.com/'
- MAX_LENGTH =
10
Class Method Summary collapse
-
.get(opts = {}, &block) ⇒ Object
Returns the list of recent pastes on PasteBin.
Methods inherited from ResultSet
#by_author, #clear, #each_by_author, #each_paste, #each_paste_by_author, #each_paste_on_date, #each_paste_with_name, #each_paste_with_syntax, #each_paste_with_text, #each_with_name, #initialize, #paste, #pastes, #pastes_by_author, #pastes_on_date, #pastes_with, #pastes_with_name, #pastes_with_syntax, #pastes_with_text, #with_name
Constructor Details
This class inherits a constructor from RPaste::ResultSet
Class Method Details
.get(opts = {}, &block) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rpaste/pastebin/recent.rb', line 19 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] = rows.map do |row| name = row.search('a').first.get_attribute('href').gsub(/^.*\//,'') = row.search('a').inner_text ago = row.inner_text Metadata.new(name,,ago) end new_recent = self.new() block.call(new_recent) if block return new_recent end |