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

#soundcloud?(url) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/media_embed/handler.rb', line 32

def soundcloud?(url)
  url.match soundcloud_regex
end

#soundcloud_regexObject



44
45
46
# File 'lib/media_embed/handler.rb', line 44

def soundcloud_regex
  /soundcloud.com\/(.*\/[a-zA-Z0-9\-\_]*)/
end

#template_for(url) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# 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])
             elsif match = soundcloud?(url)
               Podcast.soundcloud_template(match[CODE])
             else
               ''
             end

  return template
end

#vimeo?(url) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/media_embed/handler.rb', line 28

def vimeo?(url)
  url.match vimeo_regex
end

#vimeo_regexObject



40
41
42
# File 'lib/media_embed/handler.rb', line 40

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

#youtube?(url) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/media_embed/handler.rb', line 24

def youtube?(url)
  url.match youtube_regex
end

#youtube_regexObject



36
37
38
# File 'lib/media_embed/handler.rb', line 36

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