Module: Gembed

Defined in:
lib/gembed.rb,
lib/gembed/loom.rb,
lib/gembed/vimeo.rb,
lib/gembed/youtube.rb

Defined Under Namespace

Classes: Loom, Vimeo, Youtube

Class Method Summary collapse

Class Method Details

.find_source(url) ⇒ Object

Gets domain of the url



33
34
35
# File 'lib/gembed.rb', line 33

def find_source(url)
  @source = url.match(/\/\/[www.]*[a-zA-Z0-9]*\.[a-z]*/).to_s.gsub(/\/\/[www.]*/,'')
end

.get_id(url) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/gembed.rb', line 23

def get_id(url)
  source = find_source(url)
  if @sources[source].nil?
    return "Source not supported"
  else
    @sources[source].find_id(url)
  end
end

.insert(url) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/gembed.rb', line 14

def insert(url)
  source = find_source(url)
  if @sources[source].nil?
    return source_error(url)
  else
    @sources[source].embed(url)
  end
end

.source_error(url) ⇒ Object



37
38
39
40
# File 'lib/gembed.rb', line 37

def source_error(url)
  result = "<a href='#{url}' target='_blank'>#{url}</a>"
  result.respond_to?(:html_safe) ? result.html_safe : result
end