Class: Pastis::Paste
- Inherits:
-
Object
- Object
- Pastis::Paste
- Defined in:
- lib/pastis/paste.rb
Overview
Represents a paste, shoudn’t be created by hand
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#body ⇒ Object
(also: #to_s)
Body of the paste.
-
#initialize(attributes) ⇒ Paste
constructor
A new instance of Paste.
-
#preview ⇒ Object
5 first lines of the paste.
-
#raw_url ⇒ Object
Url of the raw paste.
-
#time ⇒ Object
Creation time.
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
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/pastis/paste.rb', line 10 def url @url end |
Instance Method Details
#body ⇒ Object 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 |
#preview ⇒ Object
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_url ⇒ Object
Url of the raw paste
13 14 15 |
# File 'lib/pastis/paste.rb', line 13 def raw_url "#{url}.txt" end |
#time ⇒ Object
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 |