Sha256: 8235da3991daea356c8994cb5bebe4ee86c02bc27b7a0c00e8fd53d1f49d77ae

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'rpaste/nopaste/result_set'
require 'rpaste/rpaste'

require 'hpricot'

module RPaste
  module NoPaste
    class Recent < ResultSet

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

      #
      # Returns the list of recent pastes on NoPaste. If _opts_ 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.
      #
      def self.get(opts={},&block)
        len = opts[:length]

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

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

        metadata = 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(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/nopaste/recent.rb