Class: RPaste::NoPaste::Paste

Inherits:
Paste
  • Object
show all
Defined in:
lib/rpaste/nopaste/paste.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Attributes inherited from Paste

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Paste

#to_a, #to_s

Constructor Details

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

Creates a new NoPaste Paste object with the given name, author, date, syntax, description and text.



19
20
21
22
23
# File 'lib/rpaste/nopaste/paste.rb', line 19

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

Instance Attribute Details

#descriptionObject

Description of the entry



13
14
15
# File 'lib/rpaste/nopaste/paste.rb', line 13

def description
  @description
end

Class Method Details

.paste(name, opts = {}) ⇒ Object

Retrieves the NoPaste Paste object associated with the specified name. If opts are given they will be used in accessing the NoPaste website.



37
38
39
40
41
42
43
44
45
46
# File 'lib/rpaste/nopaste/paste.rb', line 37

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

Instance Method Details

#urlObject

Returns the URL of the NoPaste Paste object.



28
29
30
# File 'lib/rpaste/nopaste/paste.rb', line 28

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