Sha256: 109076879241507d1904e30a5c25d03b81e162353bd729bfdec46b55888d912c

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

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

module RPaste
  module PasteBin
    class Paste < RPaste::Paste

      PREFIX_URL = 'http://pastebin.com/'

      # Time to retain
      attr_reader :retained

      #
      # Creates a new PasteBin Paste object with the given _name_, _author_,
      # _date_, _syntax_, _retained_ and _text_. If a block is given, then
      # it will be passed the newly created PasteBin Paste object.
      #
      def initialize(name=nil,author=nil,date=nil,syntax=nil,retained=nil,text=nil,&block)
        @retained = retained

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

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

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

        return Paste.new(name) do |paste|
          paste.text = page.search('//div.text/ol/li').inner_text
          paste.author = page.search('#content/h1[1]'.inner_text.gsub(/Posted by /,'').split(' on ')
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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