gadgeto 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.3
4
+ - jruby-18mode
5
+ - rbx-18mode
4
6
  - ruby-head
5
7
 
6
8
  notifications:
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # gadgeto 0.1.0, 2012-01-18
2
+
3
+ * Gadgeto::VideoUrl
4
+
1
5
  # gadgeto 0.0.1, 2012-01-08
2
6
 
3
7
  * require 'gadgeto/all'
data/README.rdoc CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Collection of ruby code snippets.
4
4
 
5
- {<img src="https://secure.travis-ci.org/avarteqgmbh/gadgeto.png" />}[http://travis-ci.org/avarteqgmbh/gadgeto]
5
+ == Build Status {<img src="https://secure.travis-ci.org/avarteqgmbh/gadgeto.png" />}[http://travis-ci.org/avarteqgmbh/gadgeto]
6
+ == Dependency Status {<img src="https://gemnasium.com/avarteqgmbh/gadgeto.png" />}[https://gemnasium.com/avarteqgmbh/gadgeto]
6
7
 
7
8
  = Usage
8
9
 
@@ -69,7 +70,7 @@ For example:
69
70
 
70
71
  Gadgeto::TimeOfDay.valid?("09:15") #=> true
71
72
 
72
- t = Gadgeto::TimeOfDay.new("08:30") #=> 08:00
73
+ t = Gadgeto::TimeOfDay.new("08:30") #=> 08:30
73
74
  t.hour #=> 8
74
75
  t.minute #=> 30
75
76
  t.to_i #=> 480
@@ -90,7 +91,18 @@ For example:
90
91
  obj.extend(Gadgeto::SanitizeFilename)
91
92
  obj.sanitize_filename("foo bar.zip") #=> "foo_bar.zip"
92
93
 
93
- == Copyright
94
+ == Gadgeto::VideoUrl
94
95
 
95
- Copyright (c) 2012 Robert Gogolok, Matthias Zirnstein. See LICENSE.txt for
96
- further details.
96
+ require 'gadgeto/video_url'
97
+
98
+ Gadgeto::VideoUrl.valid?("http://vimeo.com/11384488") #=> true
99
+ Gadgeto::VideoUrl.supported_video_types #=> [:youtube, :vimeo]
100
+
101
+ video_url = Gadgeto::VideoUrl.new('http://www.youtube.com/watch?v=0zM3nApSvMg')
102
+ video_url.valid? #=> true
103
+ video_url.service #=> :youtube
104
+ video_url.id #=> "0zM3nApSvMg"
105
+
106
+ = Contributors
107
+
108
+ See https://github.com/avarteqgmbh/gadgeto/contributors
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/gadgeto.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gadgeto"
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Gogolok", "Matthias Zirnstein"]
12
- s.date = "2012-01-08"
12
+ s.date = "2012-01-18"
13
13
  s.email = "rgogolok@avarteq.de"
14
14
  s.extra_rdoc_files = [
15
15
  "ChangeLog.markdown",
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".rspec",
20
21
  ".travis.yml",
21
22
  "ChangeLog.markdown",
22
23
  "Gemfile",
@@ -31,10 +32,12 @@ Gem::Specification.new do |s|
31
32
  "lib/gadgeto/email/validators.rb",
32
33
  "lib/gadgeto/sanitize_filename.rb",
33
34
  "lib/gadgeto/time_of_day.rb",
35
+ "lib/gadgeto/video_url.rb",
34
36
  "spec/lib/gadgeto/dslable_spec.rb",
35
37
  "spec/lib/gadgeto/email_spec.rb",
36
38
  "spec/lib/gadgeto/sanitize_filename_spec.rb",
37
39
  "spec/lib/gadgeto/time_of_day_spec.rb",
40
+ "spec/lib/gadgeto/video_url_spec.rb",
38
41
  "spec/spec_helper.rb",
39
42
  "test/helper.rb",
40
43
  "test/test_gadgeto.rb"
data/lib/gadgeto/all.rb CHANGED
@@ -2,3 +2,4 @@ require 'gadgeto/dslable'
2
2
  require 'gadgeto/email'
3
3
  require 'gadgeto/sanitize_filename'
4
4
  require 'gadgeto/time_of_day'
5
+ require 'gadgeto/video_url'
@@ -0,0 +1,92 @@
1
+ module Gadgeto
2
+ class VideoUrl
3
+
4
+ YOUTUBE_REGEXP = /^.*((youtu.be\/)|(v\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/i
5
+ VIMEO_REGEXP = /http:\/\/(www\.)?vimeo.com\/(.*\/)?(\w*#)?(\d+)($|\/)/i
6
+
7
+ YOUTUBE_EMBEDDED_TEMPLATE = 'http://www.youtube.com/embed/%s?wmode=transparent&autoplay=%s'
8
+ VIMEO_EMBEDDED_TEMPLATE = 'http://player.vimeo.com/video/%s?title=0&amp;byline=0&amp;portrait=0&autoplay=%s'
9
+
10
+ SUPPORTED_SERVICE_TYPES = [:youtube, :vimeo]
11
+
12
+ attr_accessor :url
13
+
14
+ # Return a new instance with the given URL
15
+ #
16
+ # === Parameters
17
+ # <tt>url</tt> - URL of the video
18
+ def initialize(url)
19
+ @url = url
20
+ end
21
+
22
+ # Set the own media type.
23
+ def service
24
+ case self.url
25
+ when YOUTUBE_REGEXP then :youtube
26
+ when VIMEO_REGEXP then :vimeo
27
+ else nil
28
+ end
29
+ end
30
+
31
+ # Returns the own video service id
32
+ def id
33
+ case self.service
34
+ when :youtube then parse_video_id_for_youtube
35
+ when :vimeo then parse_video_id_for_vimeo
36
+ end
37
+ end
38
+
39
+ # Returns the URL for this video embedded
40
+ #
41
+ # === Parameters
42
+ # * <tt>options</tt> - Configuration for the embedded URL.
43
+ #
44
+ # === Options
45
+ # * <tt>:autoplay</tt> - Autoplay on or off (default on)
46
+ def embedded(options={})
47
+ autoplay = options[:autoplay].nil? ? true : options[:autoplay]
48
+ autoplay = !!autoplay ? '1' : '0'
49
+ embeded_template = case self.service
50
+ when :youtube then YOUTUBE_EMBEDDED_TEMPLATE
51
+ when :vimeo then VIMEO_EMBEDDED_TEMPLATE
52
+ end
53
+ return embeded_template % [self.id, autoplay]
54
+ end
55
+
56
+ # Returns true if the URL is valid
57
+ def valid?
58
+ VideoUrl.valid?(self.url)
59
+ end
60
+
61
+ # Returns all supported service types as array of symbols
62
+ def self.supported_video_types
63
+ return SUPPORTED_SERVICE_TYPES
64
+ end
65
+
66
+ # Returns true if the URL is valid
67
+ #
68
+ # === Parameters
69
+ # <tt>url</tt> - URL to validate
70
+ def self.valid?(url)
71
+ !!url.match(/(#{YOUTUBE_REGEXP})|(#{VIMEO_REGEXP})/)
72
+ end
73
+
74
+ private
75
+
76
+ # Set video_id for a given regexp and index of match result
77
+ def parse_video_id_for_regexp_and_index(regexp, index)
78
+ match_result = self.url.match(regexp)
79
+ return match_result[index] if !!match_result
80
+ end
81
+
82
+ # Parse the youtube video_id and set it in self
83
+ def parse_video_id_for_youtube
84
+ parse_video_id_for_regexp_and_index(YOUTUBE_REGEXP, 6)
85
+ end
86
+
87
+ # Parse the vimeo video_id and set it in self
88
+ def parse_video_id_for_vimeo
89
+ parse_video_id_for_regexp_and_index(VIMEO_REGEXP, 4)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require File.join(File.dirname(__FILE__), '../../../lib/gadgeto/video_url')
3
+
4
+ YOUTUBE_LINKS = [ 'http://www.youtube.com/v/0zM3nApSvMg?fs=1&amp;hl=en_US&amp;rel=0',
5
+ 'http://www.youtube.com/embed/0zM3nApSvMg?rel=0',
6
+ 'http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index',
7
+ 'http://www.youtube.com/watch?v=0zM3nApSvMg',
8
+ 'http://youtu.be/0zM3nApSvMg',
9
+ 'http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s' ]
10
+
11
+ VIMEO_LINKS = [ 'http://vimeo.com/channels/hd#11384488',
12
+ 'http://vimeo.com/groups/brooklynbands/videos/11384488',
13
+ 'http://vimeo.com/staffpicks#11384488',
14
+ 'http://vimeo.com/11384488' ]
15
+
16
+ describe Gadgeto::VideoUrl do
17
+
18
+ describe 'instance methods' do
19
+ let(:youtube_video_url){ Gadgeto::VideoUrl.new('http://www.youtube.com/embed/0zM3nApSvMg?rel=0') }
20
+ let(:vimeo_video_url){ Gadgeto::VideoUrl.new('http://vimeo.com/11384488') }
21
+
22
+ describe '#id' do
23
+ it 'should return the youtube video-id for a youtube video url' do
24
+ youtube_video_url.id.should eq('0zM3nApSvMg')
25
+ end
26
+
27
+ it 'should return the vimeo video-id for a vimeo video url' do
28
+ vimeo_video_url.id.should eq('11384488')
29
+ end
30
+ end
31
+
32
+ describe '#service' do
33
+ it 'should return "youtube" for a youtube video url' do
34
+ youtube_video_url.service.should eq(:youtube)
35
+ end
36
+
37
+ it 'should return "vimeo" for a vimeo video url' do
38
+ vimeo_video_url.service.should eq(:vimeo)
39
+ end
40
+ end
41
+
42
+ describe '#embedded' do
43
+ it 'should return the url for embedded video for youtube with autplay true default' do
44
+ youtube_video_url.embedded.should eq('http://www.youtube.com/embed/0zM3nApSvMg?wmode=transparent&autoplay=1')
45
+ end
46
+
47
+ it 'should return the url for embedded video for youtube with autoplay false if set' do
48
+ youtube_video_url.embedded(:autoplay => false).should eq('http://www.youtube.com/embed/0zM3nApSvMg?wmode=transparent&autoplay=0')
49
+ end
50
+
51
+ it 'should return the url for embedded video for vimeo with autoplay true default' do
52
+ vimeo_video_url.embedded.should eq('http://player.vimeo.com/video/11384488?title=0&amp;byline=0&amp;portrait=0&autoplay=1')
53
+ end
54
+
55
+ it 'should return the url for embedded video for vimeo with autoplay false if set' do
56
+ vimeo_video_url.embedded(:autoplay => false).should eq('http://player.vimeo.com/video/11384488?title=0&amp;byline=0&amp;portrait=0&autoplay=0')
57
+ end
58
+ end
59
+
60
+ describe '#valid?' do
61
+ it 'should return true for a valid youtube url' do
62
+ YOUTUBE_LINKS.each do |youtube_url|
63
+ Gadgeto::VideoUrl.new(youtube_url).should be_valid
64
+ end
65
+ end
66
+
67
+ it 'should return true for a valid vimeo url' do
68
+ VIMEO_LINKS.each do |vimeo_url|
69
+ Gadgeto::VideoUrl.new(vimeo_url).should be_valid
70
+ end
71
+ end
72
+
73
+ it 'should return false for a unsupported url' do
74
+ Gadgeto::VideoUrl.new('http://www.imnotthaaatvalid.de/7777as882128as').should_not be_valid
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'class methods' do
80
+
81
+ describe '#valid?' do
82
+ it 'should return true for a valid youtube url' do
83
+ YOUTUBE_LINKS.each do |youtube_url|
84
+ Gadgeto::VideoUrl.valid?(youtube_url).should be_true
85
+ end
86
+ end
87
+
88
+ it 'should return true for a valid vimeo url' do
89
+ VIMEO_LINKS.each do |vimeo_url|
90
+ Gadgeto::VideoUrl.valid?(vimeo_url).should be_true
91
+ end
92
+ end
93
+
94
+ it 'should return false for a unsupported url' do
95
+ Gadgeto::VideoUrl.valid?('http://www.imnotthaaatvalid.de/7777as882128as').should be_false
96
+ end
97
+ end
98
+
99
+ describe '#supported_video_types' do
100
+ it 'should return the supported service types' do
101
+ Gadgeto::VideoUrl.supported_video_types.should eq([:youtube, :vimeo])
102
+ end
103
+ end
104
+ end
105
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gadgeto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-08 00:00:00.000000000 Z
13
+ date: 2012-01-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jeweler
17
- requirement: &70148854034140 !ruby/object:Gem::Requirement
17
+ requirement: &70352404188660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.6.4
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70148854034140
25
+ version_requirements: *70352404188660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- requirement: &70148854032960 !ruby/object:Gem::Requirement
28
+ requirement: &70352404187960 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.9.2.2
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70148854032960
36
+ version_requirements: *70352404187960
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rdoc
39
- requirement: &70148854029880 !ruby/object:Gem::Requirement
39
+ requirement: &70352404187100 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70148854029880
47
+ version_requirements: *70352404187100
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: simplecov
50
- requirement: &70148854115860 !ruby/object:Gem::Requirement
50
+ requirement: &70352404186340 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70148854115860
58
+ version_requirements: *70352404186340
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
- requirement: &70148854113660 !ruby/object:Gem::Requirement
61
+ requirement: &70352404185820 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: 2.8.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70148854113660
69
+ version_requirements: *70352404185820
70
70
  description:
71
71
  email: rgogolok@avarteq.de
72
72
  executables: []
@@ -76,6 +76,7 @@ extra_rdoc_files:
76
76
  - LICENSE.txt
77
77
  - README.rdoc
78
78
  files:
79
+ - .rspec
79
80
  - .travis.yml
80
81
  - ChangeLog.markdown
81
82
  - Gemfile
@@ -90,10 +91,12 @@ files:
90
91
  - lib/gadgeto/email/validators.rb
91
92
  - lib/gadgeto/sanitize_filename.rb
92
93
  - lib/gadgeto/time_of_day.rb
94
+ - lib/gadgeto/video_url.rb
93
95
  - spec/lib/gadgeto/dslable_spec.rb
94
96
  - spec/lib/gadgeto/email_spec.rb
95
97
  - spec/lib/gadgeto/sanitize_filename_spec.rb
96
98
  - spec/lib/gadgeto/time_of_day_spec.rb
99
+ - spec/lib/gadgeto/video_url_spec.rb
97
100
  - spec/spec_helper.rb
98
101
  - test/helper.rb
99
102
  - test/test_gadgeto.rb
@@ -112,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
115
  version: '0'
113
116
  segments:
114
117
  - 0
115
- hash: 2068368173826465699
118
+ hash: 2891582605362777025
116
119
  required_rubygems_version: !ruby/object:Gem::Requirement
117
120
  none: false
118
121
  requirements: