Module: MTV::Music

Defined in:
lib/mtv-music.rb,
lib/mtv-music/base.rb,
lib/mtv-music/video.rb,
lib/mtv-music/artist.rb,
lib/mtv-music/version.rb

Defined Under Namespace

Modules: VERSION Classes: Artist, Base, MTVNetworkServiceError, Video

Constant Summary collapse

API_VERSION =
'1'
API_URL =
"http://api.mtvnservices.com/#{API_VERSION}/"

Instance Method Summary collapse

Instance Method Details

#escape_once(html) ⇒ Object



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

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



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

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

#tag_options(options, escape = true) ⇒ Object



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

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