Class: Zemus::Youtube
- Inherits:
-
Object
- Object
- Zemus::Youtube
- Defined in:
- lib/zemus/youtube.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url) ⇒ Youtube
constructor
A new instance of Youtube.
- #to_embed ⇒ Object
- #to_embed_image ⇒ Object
- #youtube_id ⇒ Object
Constructor Details
#initialize(url) ⇒ Youtube
Returns a new instance of Youtube.
12 13 14 |
# File 'lib/zemus/youtube.rb', line 12 def initialize(url) @url = url end |
Class Method Details
.valid?(url) ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'lib/zemus/youtube.rb', line 4 def self.valid?(url) [ /^http(s?):\/\/youtube.com/, /^http(s?):\/\/www.youtube.com/, /^http(s?):\/\/www.m.youtube.com/, /^http(s?):\/\/m.youtube.com/, /^http(s?)(s?):\/\/youtu.be/, /^http(s?):\/\/www.youtu.be/, /^m.youtube.com/, /^youtu.be/, /^youtube.com/ ].map do |link_style| url =~ link_style end.any? end |
Instance Method Details
#to_embed ⇒ Object
16 17 18 |
# File 'lib/zemus/youtube.rb', line 16 def "<iframe width='100%' height='600px' src='http://www.youtube.com/embed/#{youtube_id}?wmode=opaque' frameborder='0' allowfullscreen></iframe>" end |
#to_embed_image ⇒ Object
20 21 22 |
# File 'lib/zemus/youtube.rb', line 20 def "http://img.youtube.com/vi/#{youtube_id}/hqdefault.jpg" end |
#youtube_id ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zemus/youtube.rb', line 24 def youtube_id id = '' url = @url.gsub("&feature=player_embedded", "") if url =~ /\?v=/ id = url.split('?v=').last.split("&").first elsif url =~ /&v=/ id = url.split('&v=').last.split("&").first else id = url.split('/').last.split("&").first end id end |