class AutoHtml::YouTube
YouTube
filter
Public Class Methods
new(width: 420, height: 315)
click to toggle source
# File lib/auto_html/youtube.rb, line 8 def initialize(width: 420, height: 315) @width = width @height = height end
Public Instance Methods
call(text)
click to toggle source
# File lib/auto_html/youtube.rb, line 13 def call(text) text.gsub(youtube_pattern) do youtube_id = Regexp.last_match(4) tag(:div, class: 'video youtube') do tag(:iframe, iframe_attributes(youtube_id)) { '' } end end end
Private Instance Methods
iframe_attributes(youtube_id)
click to toggle source
# File lib/auto_html/youtube.rb, line 38 def iframe_attributes(youtube_id) src = "//www.youtube.com/embed/#{youtube_id}" { width: @width, height: @height, src: src, frameborder: 0, allowfullscreen: 'yes' } end
youtube_pattern()
click to toggle source
# File lib/auto_html/youtube.rb, line 24 def youtube_pattern @youtube_pattern ||= %r{ (https?://)? (www.)? ( youtube\.com/watch\?v=| youtu\.be/| youtube\.com/watch\?feature=player_embedded&v= ) ([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)? }x end