Class: FiddleFart::Plnkr

Inherits:
Object
  • Object
show all
Defined in:
lib/fiddle_fart/plnkr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Plnkr

Returns a new instance of Plnkr.



5
6
7
# File 'lib/fiddle_fart/plnkr.rb', line 5

def initialize(attrs={})
  attrs.each { |k,v| instance_variable_set("@#{k}", v) }
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/fiddle_fart/plnkr.rb', line 3

def id
  @id
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/fiddle_fart/plnkr.rb', line 3

def username
  @username
end

Class Method Details

.parse(url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/fiddle_fart/plnkr.rb', line 9

def self.parse(url)
  obj = self.new
  if url.include?("embed.plnkr")
    host, domain, id, view = url.scan(/([^\/^:]+)/).flatten
  else
    host, domain, view, id = url.scan(/([^\/^:]+)/).flatten
  end
  obj.id = id.split("?").first
  obj
end

Instance Method Details

#as_jsonObject



30
31
32
33
34
35
36
# File 'lib/fiddle_fart/plnkr.rb', line 30

def as_json
  {
    edit_link: edit_link,
    embed_url: embed_url,
    share_link: share_link
  }
end


20
21
22
# File 'lib/fiddle_fart/plnkr.rb', line 20

def edit_link
  "http://plnkr.co/edit/#{@id}"
end

#embed_urlObject Also known as: share_link



24
25
26
# File 'lib/fiddle_fart/plnkr.rb', line 24

def embed_url
  "http://embed.plnkr.co/#{@id}/preview"
end