Class: LinkThumbnailer::VideoParser

Inherits:
Object
  • Object
show all
Defined in:
lib/link_thumbnailer/video_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video) ⇒ VideoParser

Returns a new instance of VideoParser.



8
9
10
11
12
# File 'lib/link_thumbnailer/video_parser.rb', line 8

def initialize(video)
  @parser = ::VideoInfo.new(video.src.to_s)
rescue ::VideoInfo::UrlError
  @parser = nil
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



6
7
8
# File 'lib/link_thumbnailer/video_parser.rb', line 6

def parser
  @parser
end

Instance Method Details

#durationObject



26
27
28
29
30
# File 'lib/link_thumbnailer/video_parser.rb', line 26

def duration
  parser.duration
rescue NoMethodError, ::OpenURI::HTTPError
  nil
end

#embed_codeObject



38
39
40
41
42
# File 'lib/link_thumbnailer/video_parser.rb', line 38

def embed_code
  parser.embed_code
rescue NoMethodError, ::OpenURI::HTTPError
  nil
end

#idObject



14
15
16
17
18
# File 'lib/link_thumbnailer/video_parser.rb', line 14

def id
  parser.video_id
rescue NoMethodError
  nil
end

#providerObject



32
33
34
35
36
# File 'lib/link_thumbnailer/video_parser.rb', line 32

def provider
  parser.provider
rescue NoMethodError, ::OpenURI::HTTPError
  nil
end

#sizeObject



20
21
22
23
24
# File 'lib/link_thumbnailer/video_parser.rb', line 20

def size
  [parser.width, parser.height]
rescue NoMethodError, ::OpenURI::HTTPError
  []
end