Class: Pastis::Paste

Inherits:
Object
  • Object
show all
Defined in:
lib/pastis/paste.rb

Overview

Represents a paste, shoudn’t be created by hand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Paste

Returns a new instance of Paste.



4
5
6
7
8
# File 'lib/pastis/paste.rb', line 4

def initialize(attributes)
  %w(url body time preview).each do |attribute|
    instance_variable_set("@#{attribute}", attributes[attribute.intern])
  end
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/pastis/paste.rb', line 10

def url
  @url
end

Instance Method Details

#bodyObject Also known as: to_s

Body of the paste



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

def body
  @body ||= get(raw_url)
end

#previewObject

5 first lines of the paste



18
19
20
# File 'lib/pastis/paste.rb', line 18

def preview
  @preview ||= body.split("\n")[0, 6].join("\n")
end

#raw_urlObject

Url of the raw paste



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

def raw_url
  "#{url}.txt"
end

#timeObject

Creation time



23
24
25
# File 'lib/pastis/paste.rb', line 23

def time
  @time ||= Time.parse(Hpricot(get(url)).at("#paste_date").innerText)
end