conred 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/conred.rb +27 -21
- data/lib/conred/version.rb +1 -1
- data/spec/conred_spec.rb +34 -6
- metadata +2 -2
data/lib/conred.rb
CHANGED
@@ -16,16 +16,20 @@ module Conred
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Video
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def initialize(video_url, width = 670, height = 450, error_message = "Video url you have provided is invalid")
|
20
|
+
@width = width
|
21
|
+
@height = height
|
22
22
|
@video_url = video_url
|
23
|
+
@error_message = error_message
|
24
|
+
end
|
25
|
+
|
26
|
+
def code
|
23
27
|
if youtube_video?
|
24
|
-
|
28
|
+
video_from_youtube_url
|
25
29
|
elsif vimeo_video?
|
26
|
-
|
30
|
+
video_from_vimeo_url
|
27
31
|
else
|
28
|
-
|
32
|
+
@error_message
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -44,40 +48,42 @@ module Conred
|
|
44
48
|
end
|
45
49
|
|
46
50
|
|
47
|
-
def video_from_vimeo_url
|
48
|
-
if
|
51
|
+
def video_from_vimeo_url
|
52
|
+
if @video_url[/vimeo\.com\/([0-9]*)/]
|
49
53
|
vimeo_id = $1
|
50
|
-
else
|
51
|
-
vimeo_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
|
52
|
-
vimeo_id = $5
|
53
54
|
end
|
54
|
-
|
55
|
+
<<-eos
|
56
|
+
<iframe
|
57
|
+
id='vimeo_video'
|
55
58
|
src='http://player.vimeo.com/video/#{vimeo_id}'
|
56
|
-
width='#{width}'
|
57
|
-
height='#{height}'
|
59
|
+
width='#{@width}'
|
60
|
+
height='#{@height}'
|
58
61
|
frameborder='0'
|
59
62
|
webkitAllowFullScreen
|
60
63
|
mozallowfullscreen
|
61
64
|
allowFullScreen>
|
62
65
|
</iframe>"
|
66
|
+
eos
|
63
67
|
end
|
64
68
|
|
65
|
-
def video_from_youtube_url
|
66
|
-
if
|
69
|
+
def video_from_youtube_url
|
70
|
+
if @video_url[/youtu\.be\/([^\?]*)/]
|
67
71
|
youtube_id = $1
|
68
72
|
else
|
69
|
-
|
73
|
+
@video_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
|
70
74
|
youtube_id = $5
|
71
75
|
end
|
72
|
-
|
76
|
+
<<-eos
|
77
|
+
<iframe
|
73
78
|
id='youtube_video'
|
74
79
|
title='YouTube video player'
|
75
|
-
width='#{width}'
|
76
|
-
height='#{height}'
|
80
|
+
width='#{@width}'
|
81
|
+
height='#{@height}'
|
77
82
|
src='http://www.youtube.com/embed/#{ youtube_id }'
|
78
83
|
frameborder='0'
|
79
84
|
allowfullscreen>
|
80
|
-
</iframe>
|
85
|
+
</iframe>
|
86
|
+
eos
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
data/lib/conred/version.rb
CHANGED
data/spec/conred_spec.rb
CHANGED
@@ -21,6 +21,35 @@ describe Conred do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe Conred::Video do
|
24
|
+
before do
|
25
|
+
@vimeo_embed_code = <<-eos
|
26
|
+
<iframe
|
27
|
+
id='vimeo_video'
|
28
|
+
src='http://player.vimeo.com/video/49556689'
|
29
|
+
width='450'
|
30
|
+
height='300'
|
31
|
+
frameborder='0'
|
32
|
+
webkitAllowFullScreen
|
33
|
+
mozallowfullscreen
|
34
|
+
allowFullScreen>
|
35
|
+
</iframe>"
|
36
|
+
eos
|
37
|
+
|
38
|
+
@youtube_embed_code =
|
39
|
+
<<-eos
|
40
|
+
<iframe
|
41
|
+
id='youtube_video'
|
42
|
+
title='YouTube video player'
|
43
|
+
width='450'
|
44
|
+
height='300'
|
45
|
+
src='http://www.youtube.com/embed/Lrj5Kxdzouc'
|
46
|
+
frameborder='0'
|
47
|
+
allowfullscreen>
|
48
|
+
</iframe>
|
49
|
+
eos
|
50
|
+
|
51
|
+
|
52
|
+
end
|
24
53
|
it "should match youtube video" do
|
25
54
|
Conred::Video.new("http://www.youtube.com/watch?v=SZt5RFzqEfY&feature=g-all-fbc").should be_youtube_video
|
26
55
|
Conred::Video.new("http://youtu.be/SZt5RFzqEfY").should be_youtube_video
|
@@ -38,12 +67,11 @@ describe Conred do
|
|
38
67
|
Conred::Video.new("http://www.vimeo.com/12311233http://youtube.com/12311233").youtube_video? == false
|
39
68
|
Conred::Video.new("eeevil vimeo www.vimeo.com/12311233").youtube_video? == false
|
40
69
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# end
|
70
|
+
it "should return correct embed code" do
|
71
|
+
Conred::Video.new("http://www.youtube.com/watch?v=Lrj5Kxdzouc", 450, 300).code.should == @youtube_embed_code
|
72
|
+
Conred::Video.new("http://vimeo.com/49556689", 450, 300).code.should == @vimeo_embed_code
|
73
|
+
Conred::Video.new("http://google.com/12311233", 450, 300, "Some mistake in url").code.should == "Some mistake in url"
|
74
|
+
end
|
47
75
|
end
|
48
76
|
|
49
77
|
describe Conred::Links do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|