video_embed 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class VideoEmbed
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -25,7 +25,7 @@ class VideoEmbed
25
25
  private
26
26
 
27
27
  def video_id
28
- url.to_s.match(/vimeo.com\/(\d*)\??/)[1]
28
+ url.to_s.match(/vimeo.com(?:\/m)?\/(\d*)\??/)[1]
29
29
  end
30
30
  end
31
31
  end
@@ -3,7 +3,7 @@ require 'cgi'
3
3
  class VideoEmbed
4
4
  class YouTube
5
5
  def url?(url)
6
- url.host =~ /youtube\.com/
6
+ url.host =~ /(:?youtube\.com|youtu.be)/
7
7
  end
8
8
 
9
9
  def embed(url, options = {})
@@ -27,8 +27,16 @@ class VideoEmbed
27
27
  private
28
28
 
29
29
  def video_id
30
- params = CGI.parse(url.query)
31
- params['v'].first
30
+ if short_url?
31
+ url.path.match(/\/(.*)\??/)[1]
32
+ else
33
+ params = CGI.parse(url.query)
34
+ params['v'].first
35
+ end
36
+ end
37
+
38
+ def short_url?
39
+ url.host == 'youtu.be'
32
40
  end
33
41
  end
34
42
  end
@@ -7,6 +7,11 @@ describe VideoEmbed do
7
7
  video_embed.should eql(%Q{<iframe width="560" height="315" src="http://www.youtube.com/embed/4Z3r9X8OahA?rel=0" frameborder="0" allowfullscreen></iframe>})
8
8
  end
9
9
 
10
+ it 'returns embed html from a short url' do
11
+ video_embed = VideoEmbed.embed('http://youtu.be/4Z3r9X8OahA')
12
+ video_embed.should include('http://www.youtube.com/embed/4Z3r9X8OahA?rel=0')
13
+ end
14
+
10
15
  it 'accepts a custom width' do
11
16
  video_embed = VideoEmbed.embed('http://www.youtube.com/watch?v=NtgtMQwr3Ko', :width => 1280)
12
17
  video_embed.should match(/width="1280"/)
@@ -24,6 +29,11 @@ describe VideoEmbed do
24
29
  video_embed.should eql(%Q{<iframe src="http://player.vimeo.com/video/11040425?title=0&amp;byline=0&amp;portrait=0" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>})
25
30
  end
26
31
 
32
+ it 'returns embed html from a mobile url' do
33
+ video_embed = VideoEmbed.embed('http://vimeo.com/m/11040425')
34
+ video_embed.should include('http://player.vimeo.com/video/11040425?title=0&amp;byline=0&amp;portrait=0')
35
+ end
36
+
27
37
  it 'accepts a custom width' do
28
38
  video_embed = VideoEmbed.embed('http://vimeo.com/11040425', :width => 720)
29
39
  video_embed.should match(/width="720"/)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: video_embed
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lee Jones