Class: GC::Video
- Inherits:
-
Object
- Object
- GC::Video
- Defined in:
- lib/video.rb,
lib/video/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#params ⇒ Object
Returns the value of attribute params.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #embed(dim = '560x315', options = {}) ⇒ Object
-
#initialize(link) ⇒ Video
constructor
A new instance of Video.
- #thumbnail(size = :default) ⇒ Object
- #youtube? ⇒ Boolean
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
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/video.rb', line 6 def id @id end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/video.rb', line 6 def params @params end |
#provider ⇒ Object
Returns the value of attribute provider.
6 7 8 |
# File 'lib/video.rb', line 6 def provider @provider end |
#uri ⇒ Object
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 dim='560x315', ={} [:load] = true if [:load].nil? h,w = dim.split('x') if youtube? @embed = %(<iframe width="#{h}" height="#{w}" #{[:load] ? 'src' : 'data-src'}="http://www.youtube.com/embed/#{id}?html5=1") .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
21 22 23 |
# File 'lib/video.rb', line 21 def youtube? provider == :youtube end |