Class: MTV::Music::Video

Inherits:
Base
  • Object
show all
Defined in:
lib/mtv-music/base.rb,
lib/mtv-music/video.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attribute, attributes, fetch_and_parse, #initialize, #initialize_with_polymorphism, name_with_demodulization, search

Constructor Details

This class inherits a constructor from MTV::Music::Base

Class Method Details

.api_path(method, id = nil) ⇒ Object

Workaround for case-sensitivity for Video aliases



35
36
37
38
# File 'lib/mtv-music/video.rb', line 35

def api_path(method, id = nil)
  parameters = [self.name.downcase, id, method].compact
  return parameters.collect!{|param| CGI::escape(param.to_s)}.join('/')
end

Instance Method Details

#artistObject



27
28
29
# File 'lib/mtv-music/video.rb', line 27

def artist
  Artist.new(@artist_uri)
end

#embed_code(options = {}) ⇒ Object Also known as: to_html

<embed src=“media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:235854

width="448" height="366" type="application/x-shockwave-flash"
allowFullScreen="true" allowScriptAccess="always" flashvars="autoPlay=false" />


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mtv-music/video.rb', line 15

def embed_code(options = {})
  options.update({
    :src    => @media_uri,
    :type   => "application/x-shockwave-flash",
    :width  => "448",
    :height => "366",
    :allowFullScreen   => "true",
    :allowScriptAccess => "always",
    :flashvars         => "autoPlay=false"})
  tag(:embed, options)
end

#escape_once(html) ⇒ Object



63
64
65
# File 'lib/mtv-music/video.rb', line 63

def escape_once(html)
  html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| ERB::Util::HTML_ESCAPE[special] }
end

#tag(name, options = nil, open = false, escape = true) ⇒ Object

Taken from ActionView#TagHelper



42
43
44
# File 'lib/mtv-music/video.rb', line 42

def tag(name, options = nil, open = false, escape = true)
  "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}"
end

#tag_options(options, escape = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mtv-music/video.rb', line 46

def tag_options(options, escape = true)
  unless options.blank?
   attrs = []
   if escape
     options.each do |key, value|
       next unless value
       key = key.to_s
       value = Set.new(%w(disabled readonly multiple)).include?(key) ? key : escape_once(value)
       attrs << %(#{key}="#{value}")
     end
   else
     attrs = options.map { |key, value| %(#{key}="#{value}") }
   end
   " #{attrs.sort * ' '}" unless attrs.empty?
  end
end