Class: GC::Video

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

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Video

Returns a new instance of Video.



8
9
10
11
12
13
14
15
# File 'lib/video.rb', line 8

def initialize link
  @link = link
  @uri = URI(@link)
  @provider = case @uri.host
              when /youtube.com/ then :youtube
              end
  @params = Hash[*@uri.query.split('&').map { |kv| sp = kv.split('='); sp[0] = sp[0].to_sym; sp }.flatten]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#providerObject

Returns the value of attribute provider.



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

def provider
  @provider
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#embed(dim = '560x315', options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/video.rb', line 25

def embed dim='560x315', options={}
  options[:load] = true if options[:load].nil?
  h,w = dim.split('x')
  if youtube?
    @embed = %(<iframe width="#{h}" height="#{w}" #{options[:load] ? 'src' : 'data-src'}="http://www.youtube.com/embed/#{id}?html5=1")
    options.each do | k,v|
      next if k == :load
      @embed += %( data-#{k}="#{v}")
    end
    @embed += %( frameborder="0" allowfullscreen></iframe>)
  end
end

#thumbnail(size = :default) ⇒ Object



38
39
40
# File 'lib/video.rb', line 38

def thumbnail size=:default
  "//img.youtube.com/vi/#{id}/#{size == :full ? '0' : 'default'}.jpg" if youtube?
end

#youtube?Boolean

Returns:

  • (Boolean)


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

def youtube?
  provider == :youtube
end