Sha256: 89f33e65ff22bf1a0d9792719ad8b225de6196cc0438999ce8cc67065f8d88f2

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require 'rpaste/paste'
require 'rpaste/rpaste'

require 'hpricot'

module RPaste
  module NoPaste
    class Paste < RPaste::Paste

      PREFIX_URL = 'http://rafb.net/p/'

      # Description of the entry
      attr_accessor :description

      #
      # Creates a new NoPaste Paste object with the given _name_, _author_,
      # _date_, _syntax_, _description_ and _text_.
      #
      def initialize(name=nil,author=nil,date=nil,syntax=nil,description=nil,text=nil,&block)
        @description = description

        super(name,author,date,syntax,text,&block)
      end

      #
      # Returns the URL of the NoPaste Paste object.
      #
      def url
        "#{PREFIX_URL}#{@name}.html"
      end

      #
      # Retrieves the NoPaste Paste object associated with the specified
      # _name_. If _opts_ are given they will be used in accessing the
      # NoPaste website.
      #
      def self.paste(name,opts={})
        page = Hpricot(RPaste.open("#{PREFIX_URL}#{name}.html",opts))

        return Paste.new(name) do |paste|
          paste.syntax = page.search('//table[1]/tr[1]/td/small/b[1]').inner_text
          paste.author = page.search('//table[1]/tr[1]/td/small/b[2]').inner_text
          paste.description = page.search('//table[1]/tr[2]/td/small').inner_text.gsub(/^Description: /,'')
          paste.text = page.search('#codemain').inner_text
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rpaste-0.0.9 lib/rpaste/nopaste/paste.rb