class Gadgeto::VideoUrl
Constants
- SUPPORTED_SERVICE_TYPES
- VIMEO_EMBEDDED_TEMPLATE
- VIMEO_REGEXP
- YOUTUBE_EMBEDDED_TEMPLATE
- YOUTUBE_REGEXP
Attributes
url[RW]
Public Class Methods
new(url)
click to toggle source
supported_services()
click to toggle source
Returns all supported service types as array of symbols
# File lib/gadgeto/video_url.rb, line 62 def self.supported_services return SUPPORTED_SERVICE_TYPES end
supported_video_types()
click to toggle source
DEPRECATED: Please use supported_services
instead.
# 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
Public Instance Methods
embedded(options={})
click to toggle source
Returns the URL for this video embedded
Parameters¶ ↑
-
options
- Configuration for the embedded URL.
Options¶ ↑
-
:autoplay
- Autoplay on or off (default on)
# File lib/gadgeto/video_url.rb, line 46 def embedded(options={}) autoplay = options[:autoplay].nil? ? true : options[:autoplay] autoplay = !!autoplay ? '1' : '0' embeded_template = case self.service when :youtube then YOUTUBE_EMBEDDED_TEMPLATE when :vimeo then VIMEO_EMBEDDED_TEMPLATE end return embeded_template % [self.id, autoplay] end
id()
click to toggle source
Returns the own video service id
# 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()
click to toggle source
Set the own media type.
# 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
valid?()
click to toggle source
Returns true if the URL is valid
# File lib/gadgeto/video_url.rb, line 57 def valid? VideoUrl.valid?(self.url) end
Private Instance Methods
parse_video_id_for_regexp_and_index(regexp, index)
click to toggle source
Set video_id for a given regexp and index of match result
# File lib/gadgeto/video_url.rb, line 83 def parse_video_id_for_regexp_and_index(regexp, index) match_result = self.url.match(regexp) return match_result[index] if !!match_result end
parse_video_id_for_vimeo()
click to toggle source
Parse the vimeo video_id and set it in self
# File lib/gadgeto/video_url.rb, line 94 def parse_video_id_for_vimeo parse_video_id_for_regexp_and_index(VIMEO_REGEXP, 4) end
parse_video_id_for_youtube()
click to toggle source
Parse the youtube video_id and set it in self
# File lib/gadgeto/video_url.rb, line 89 def parse_video_id_for_youtube parse_video_id_for_regexp_and_index(YOUTUBE_REGEXP, 6) end