Class: RPaste::PasteBin::Paste

Inherits:
RPaste::Paste show all
Defined in:
lib/rpaste/pastebin/paste.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Attributes inherited from RPaste::Paste

#author, #date, #name, #syntax, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RPaste::Paste

#to_a, #to_s

Constructor Details

#initialize(name = nil, author = nil, date = nil, syntax = nil, retained = nil, text = nil, &block) ⇒ Paste

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.



18
19
20
21
22
# File 'lib/rpaste/pastebin/paste.rb', line 18

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

Instance Attribute Details

#retainedObject (readonly)

Time to retain



11
12
13
# File 'lib/rpaste/pastebin/paste.rb', line 11

def retained
  @retained
end

Class Method Details

.paste(name) ⇒ Object

Retrieves the PasteBin Paste object associated with the specified name.



35
36
37
38
39
40
41
42
# File 'lib/rpaste/pastebin/paste.rb', line 35

def self.paste(name)
  page = RPaste.open_page("#{PREFIX_URL}#{name}")

  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

Instance Method Details

#urlObject

Returns the URL of the PasteBin Paste object.



27
28
29
# File 'lib/rpaste/pastebin/paste.rb', line 27

def url
  "#{PREFIX_URL}#{@name}"
end