Class: VideoPlayer::Parser
- Inherits:
-
Object
- Object
- VideoPlayer::Parser
- Defined in:
- lib/video_player.rb
Constant Summary collapse
- DefaultWidth =
'420'- DefaultHeight =
'315'- DefaultAutoPlay =
true- YouTubeRegex =
/\A(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/i- VimeoRegex =
/\Ahttps?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/i- IzleseneRegex =
/\Ahttp:\/\/(?:.*?)\izlesene\.com\/video\/([\w\-\.]+[^#?\s]+)\/(.*)?$/i- WistiaRegex =
/\Ahttps?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/i
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#url ⇒ Object
Returns the value of attribute url.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #autoplay ⇒ Object
- #embed_code ⇒ Object
- #iframe_code(src) ⇒ Object
-
#initialize(url, width = DefaultWidth, height = DefaultHeight, autoplay = DefaultAutoPlay) ⇒ Parser
constructor
A new instance of Parser.
- #izlesene_embed(video_id) ⇒ Object
- #vimeo_embed(video_id) ⇒ Object
- #wistia_embed(video_id) ⇒ Object
- #youtube_embed(video_id) ⇒ Object
Constructor Details
#initialize(url, width = DefaultWidth, height = DefaultHeight, autoplay = DefaultAutoPlay) ⇒ Parser
Returns a new instance of Parser.
20 21 22 23 24 25 |
# File 'lib/video_player.rb', line 20 def initialize(url, width = DefaultWidth, height = DefaultHeight, autoplay = DefaultAutoPlay) @url = url @width = width @height = height @autoplay = autoplay end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
18 19 20 |
# File 'lib/video_player.rb', line 18 def height @height end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/video_player.rb', line 18 def url @url end |
#width ⇒ Object
Returns the value of attribute width.
18 19 20 |
# File 'lib/video_player.rb', line 18 def width @width end |
Instance Method Details
#autoplay ⇒ Object
42 43 44 |
# File 'lib/video_player.rb', line 42 def autoplay !!@autoplay ? '1' : '0' end |
#embed_code ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/video_player.rb', line 27 def case when matchdata = url.match(YouTubeRegex) (matchdata[4]) when matchdata = url.match(VimeoRegex) (matchdata[2]) when matchdata = url.match(IzleseneRegex) (matchdata[2]) when matchdata = url.match(WistiaRegex) (matchdata[4]) else false end end |
#iframe_code(src) ⇒ Object
46 47 48 |
# File 'lib/video_player.rb', line 46 def iframe_code(src) %{<iframe src="#{src}" width="#{width}" height="#{height}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>} end |
#izlesene_embed(video_id) ⇒ Object
60 61 62 63 |
# File 'lib/video_player.rb', line 60 def (video_id) src = "//www.izlesene.com/embedplayer/#{video_id}/?autoplay=#{autoplay}&showrel=0&showinfo=0" iframe_code(src) end |
#vimeo_embed(video_id) ⇒ Object
55 56 57 58 |
# File 'lib/video_player.rb', line 55 def (video_id) src = "//player.vimeo.com/video/#{video_id}?autoplay=#{autoplay}" iframe_code(src) end |
#wistia_embed(video_id) ⇒ Object
65 66 67 68 |
# File 'lib/video_player.rb', line 65 def (video_id) src = "//fast.wistia.net/embed/iframe/#{video_id}/?autoplay=#{autoplay}&showrel=0&showinfo=0" iframe_code(src) end |
#youtube_embed(video_id) ⇒ Object
50 51 52 53 |
# File 'lib/video_player.rb', line 50 def (video_id) src = "//www.youtube.com/embed/#{video_id}?autoplay=#{autoplay}&rel=0" iframe_code(src) end |