Class: Gadgeto::VideoUrl
- Inherits:
-
Object
- Object
- Gadgeto::VideoUrl
- Defined in:
- lib/gadgeto/video_url.rb
Constant Summary collapse
- YOUTUBE_REGEXP =
/^.*((youtu.be\/)|(v\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/i
- VIMEO_REGEXP =
/http:\/\/(www\.)?vimeo.com\/(.*\/)?(\w*#)?(\d+)($|\/)/i
- YOUTUBE_EMBEDDED_TEMPLATE =
'http://www.youtube.com/embed/%s?wmode=transparent&autoplay=%s'
- VIMEO_EMBEDDED_TEMPLATE =
'http://player.vimeo.com/video/%s?title=0&byline=0&portrait=0&autoplay=%s'
- SUPPORTED_SERVICE_TYPES =
[:youtube, :vimeo]
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.supported_services ⇒ Object
Returns all supported service types as array of symbols.
-
.supported_video_types ⇒ Object
DEPRECATED: Please use
supported_services
instead. -
.valid?(url) ⇒ Boolean
Returns true if the URL is valid.
Instance Method Summary collapse
-
#embedded(options = {}) ⇒ Object
Returns the URL for this video embedded.
-
#id ⇒ Object
Returns the own video service id.
-
#initialize(url) ⇒ VideoUrl
constructor
Return a new instance with the given URL.
-
#service ⇒ Object
Set the own media type.
-
#valid? ⇒ Boolean
Returns true if the URL is valid.
Constructor Details
#initialize(url) ⇒ VideoUrl
Return a new instance with the given URL
Parameters
url
- URL of the video
18 19 20 |
# File 'lib/gadgeto/video_url.rb', line 18 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
12 13 14 |
# File 'lib/gadgeto/video_url.rb', line 12 def url @url end |
Class Method Details
.supported_services ⇒ Object
Returns all supported service types as array of symbols
62 63 64 |
# File 'lib/gadgeto/video_url.rb', line 62 def self.supported_services return SUPPORTED_SERVICE_TYPES end |
.supported_video_types ⇒ Object
DEPRECATED: Please use supported_services
instead.
67 68 69 70 |
# File 'lib/gadgeto/video_url.rb', line 67 def self.supported_video_types warn "[DEPRECATION] `supported_video_types` is deprecated. Please use `supported_services` instead." return supported_services end |
.valid?(url) ⇒ Boolean
Returns true if the URL is valid
Parameters
url
- URL to validate
76 77 78 |
# File 'lib/gadgeto/video_url.rb', line 76 def self.valid?(url) !!url.match(/(#{YOUTUBE_REGEXP})|(#{VIMEO_REGEXP})/) end |
Instance Method Details
#embedded(options = {}) ⇒ Object
Returns the URL for this video embedded
Parameters
-
options
- Configuration for the embedded URL.
Options
-
:autoplay
- Autoplay on or off (default on)
46 47 48 49 50 51 52 53 54 |
# File 'lib/gadgeto/video_url.rb', line 46 def (={}) autoplay = [:autoplay].nil? ? true : [:autoplay] autoplay = !!autoplay ? '1' : '0' = case self.service when :youtube then YOUTUBE_EMBEDDED_TEMPLATE when :vimeo then VIMEO_EMBEDDED_TEMPLATE end return % [self.id, autoplay] end |
#id ⇒ Object
Returns the own video service id
32 33 34 35 36 37 |
# File 'lib/gadgeto/video_url.rb', line 32 def id case self.service when :youtube then parse_video_id_for_youtube when :vimeo then parse_video_id_for_vimeo end end |
#service ⇒ Object
Set the own media type.
23 24 25 26 27 28 29 |
# File 'lib/gadgeto/video_url.rb', line 23 def service case self.url when YOUTUBE_REGEXP then :youtube when VIMEO_REGEXP then :vimeo else nil end end |