Module: MediaEmbed::Handler

Defined in:
lib/media_embed/handler.rb

Constant Summary collapse

CODE =
-1

Instance Method Summary collapse

Instance Method Details

#embed(url) ⇒ Object



5
6
7
# File 'lib/media_embed/handler.rb', line 5

def embed(url)
  return template_for(url)
end

#template_for(url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/media_embed/handler.rb', line 9

def template_for(url)
  template = if match = youtube?(url)
               Video.youtube_template(match[CODE])
             elsif match = vimeo?(url)
               Video.vimeo_template(match[CODE])
             else
               ''
             end

  return template
end

#vimeo?(url) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/media_embed/handler.rb', line 26

def vimeo?(url)
  url.match vimeo_regex
end

#vimeo_regexObject



34
35
36
# File 'lib/media_embed/handler.rb', line 34

def vimeo_regex
  /vimeo\.com\/(channels\/\D*|groups\/\D*|album\/\d*\/video\/|video\/|)([^?\s]*)/
end

#youtube?(url) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/media_embed/handler.rb', line 22

def youtube?(url)
  url.match youtube_regex
end

#youtube_regexObject



30
31
32
# File 'lib/media_embed/handler.rb', line 30

def youtube_regex
  /youtu(\.be|be\.com)\/(watch\?v=|embed\/|)([^?\s]*)/
end