Class: Preprocessor::Video::YouTube

Inherits:
Object
  • Object
show all
Defined in:
lib/preprocessor/video.rb

Constant Summary collapse

URL_REGEXP =
/youtube\.com\/(?:watch\?v=|v\/)([^\/?&]+)/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ YouTube

Returns a new instance of YouTube.



13
14
15
# File 'lib/preprocessor/video.rb', line 13

def initialize(options)
  self.src = options[:src]
end

Instance Attribute Details

#srcObject

Returns the value of attribute src.



10
11
12
# File 'lib/preprocessor/video.rb', line 10

def src
  @src
end

Class Method Details

.recognizes?(src) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/preprocessor/video.rb', line 24

def self.recognizes?(src)
  src =~ URL_REGEXP
end

Instance Method Details

#tagObject



17
18
19
20
21
22
# File 'lib/preprocessor/video.rb', line 17

def tag
  if src =~ URL_REGEXP
    url = "http://www.youtube.com/v/#{$1}"
    %{<object width="425" height="344"><param name="movie" value="#{url}"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="#{url}" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>}
  end
end