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.
@@ -16,16 +16,20 @@ module Conred
16
16
  end
17
17
 
18
18
  class Video
19
- attr_reader :code
20
-
21
- def initialize(video_url)
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
- @code = video_from_youtube_url(video_url)
28
+ video_from_youtube_url
25
29
  elsif vimeo_video?
26
- @code = video_from_vimeo_url(video_url)
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(vimeo_url, width = 670, height = 450)
48
- if vimeo_url[/youtu\.be\/([^\?]*)/]
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
- "<iframe
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(youtube_url, width = 670, height = 450)
66
- if youtube_url[/youtu\.be\/([^\?]*)/]
69
+ def video_from_youtube_url
70
+ if @video_url[/youtu\.be\/([^\?]*)/]
67
71
  youtube_id = $1
68
72
  else
69
- youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
73
+ @video_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
70
74
  youtube_id = $5
71
75
  end
72
- "<iframe
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>".html_safe
85
+ </iframe>
86
+ eos
81
87
  end
82
88
  end
83
89
 
@@ -1,3 +1,3 @@
1
1
  module Conred
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
- # it "should not match any video video" do
42
- # Conred::Video.new("http://youtube.com/12311233").should not_be_vimeo_video
43
- # Conred::Video.new("ftp://vimeo.com/12311233").should not_be_vimeo_video
44
- # Conred::Video.new("http://www.youtube.com/watch?vimeo.com/12311233").should not_be_vimeo_video
45
- # Conred::Video.new("evil string http://vimeo.com/12311233").should not_be_vimeo_video
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.2
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-19 00:00:00.000000000 Z
12
+ date: 2012-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec