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(options = {}, &block) ⇒ Object
Returns the list of recent pastes on PasteBin.
Methods inherited from ResultSet
#authors, #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, #names, #paste, #pastes, #pastes_by_author, #pastes_on_date, #pastes_with, #pastes_with_name, #pastes_with_syntax, #pastes_with_text, #select, #with_name
Constructor Details
This class inherits a constructor from RPaste::ResultSet
Class Method Details
.get(options = {}, &block) ⇒ Object
Returns the list of recent pastes on PasteBin. If options 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.
options may also contain the following keys:
:length
-
The maximum number of results to return.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rpaste/pastebin/recent.rb', line 22 def self.get(={},&block) len = [:length] if (len.nil? || len>MAX_LENGTH) len = MAX_LENGTH else len = len.to_i end page = RPaste.open_page(URL,) 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 |