Class: RPaste::NoPaste::Recent

Inherits:
ResultSet
  • Object
show all
Defined in:
lib/rpaste/nopaste/recent.rb

Constant Summary collapse

URL =
'http://www.rafb.net/paste/results.html'

Class Method Summary collapse

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 NoPaste. If options are given they will be used in accessing the NoPaste 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.



20
21
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/nopaste/recent.rb', line 20

def self.get(options={},&block)
  len = options[:length]

  if len.nil? || len==0
    len = -1
  else
    len = len.to_i+1
  end

  page = RPaste.open_page(URL,options)
  rows = page.search('//div.filelist/table/tr')[1..len]

   = rows.map do |row|
    name = row.search('td[4]/a').first.get_attribute('href').gsub(/^.*\//,'').gsub(/\..*$/,'')
    date = row.search('td[1]').inner_text
    syntax = row.search('td[2]').inner_text
    author = row.search('td[3]').inner_text
    description = row.search('td[4]/a').inner_text

    Metadata.new(name,author,date,syntax,description)
  end

  new_recent = self.new()

  block.call(new_recent) if block
  return new_recent
end