Class: Pastie::Paste
- Inherits:
-
Object
- Object
- Pastie::Paste
- Defined in:
- lib/pastie-api/paste.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(html) ⇒ Paste
constructor
Initializes a pastie from server html response.
-
#link ⇒ Object
Return direct link to paste page.
-
#private? ⇒ Boolean
Returns true if paste is private.
-
#raw_link ⇒ Object
Returns direct link to paste contents.
Constructor Details
#initialize(html) ⇒ Paste
Initializes a pastie from server html response
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pastie-api/paste.rb', line 7 def initialize(html) url = html.scan(/http:\/\/pastie.org\/pastes\/([\d]{1,})\/text(\?key=([A-Za-z\d]{1,}))?/) unless url.nil? url.flatten! @id = url[0] ; @key = url[2] @content = Request.fetch(raw_link) else raise 'Invalid html!' end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/pastie-api/paste.rb', line 4 def content @content end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/pastie-api/paste.rb', line 3 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/pastie-api/paste.rb', line 3 def key @key end |
Instance Method Details
#link ⇒ Object
Return direct link to paste page
24 25 26 |
# File 'lib/pastie-api/paste.rb', line 24 def link BASE_URL + (private? ? "/private/#{@key}" : "/#{@id}") end |
#private? ⇒ Boolean
Returns true if paste is private
29 30 31 |
# File 'lib/pastie-api/paste.rb', line 29 def private? !@key.nil? end |
#raw_link ⇒ Object
Returns direct link to paste contents
19 20 21 |
# File 'lib/pastie-api/paste.rb', line 19 def raw_link BASE_URL + "/pastes/#{@id}/text" + (private? ? "?key=#{@key}" : '') end |