Class: HasVimeoVideo::VimeoVideo

Inherits:
Object
  • Object
show all
Defined in:
lib/has_vimeo_video/vimeo_video.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ VimeoVideo

Returns a new instance of VimeoVideo.



8
9
10
# File 'lib/has_vimeo_video/vimeo_video.rb', line 8

def initialize url
  @url = url
end

Class Method Details

.regexObject



4
5
6
# File 'lib/has_vimeo_video/vimeo_video.rb', line 4

def self.regex
  /https?:\/\/(www\.)?vimeo.com\/(\d+)/
end

Instance Method Details

#embed_urlObject



33
34
35
# File 'lib/has_vimeo_video/vimeo_video.rb', line 33

def embed_url
  "http://player.vimeo.com/video/#{id}"
end

#idObject



12
13
14
15
16
17
18
# File 'lib/has_vimeo_video/vimeo_video.rb', line 12

def id
  return @id if @id
  return unless @url
  if result = @url.match(self.class.regex)
    @id = result[2]
  end
end

#infoObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/has_vimeo_video/vimeo_video.rb', line 20

def info
  return @info if @info
  return unless id
  @info = Vimeo::Simple::Video.info(id)
  if @info.parsed_response and @info.parsed_response[0]
    @info = @info.parsed_response[0]
  else
    @info = nil
  end
rescue
  @info = nil
end

#thumbnailObject



37
38
39
40
# File 'lib/has_vimeo_video/vimeo_video.rb', line 37

def thumbnail
  return unless info
  info["thumbnail_large"]
end