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



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

def initialize(options)
  self.src = options[:src]
  self.width = options[:width] || 465
  self.height = options[:height] || 344
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#srcObject

Returns the value of attribute src.



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

def src
  @src
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Class Method Details

.recognizes?(src) ⇒ Boolean



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

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

Instance Method Details

#tagObject



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

def tag
  if src =~ URL_REGEXP
    %{<iframe width="#{width}" height="#{height}" src="https://www.youtube-nocookie.com/embed/#{$1}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>}
  end
end