| Class | XSPF |
| In: |
xspf-expanded.rb
lib/xspf.rb |
| Parent: | Object |
| xspf | [R] |
Creates a XSPF object from a file or string (parse mode) or from a hash or nil (generation mode).
Possible keys in the hash: :version, :encoding
# File lib/xspf.rb, line 111
111: def initialize(source = nil)
112: if ( source.nil? || source.instance_of?(Hash) ) then
113: @version = if source.nil? || !source.has_key?(:version)
114: '1.0'
115: else
116: source[:version]
117: end
118: @encoding = if source.nil? || !source.has_key?(:encoding)
119: 'UTF-8'
120: else
121: source[:encoding]
122: end
123: @playlist = nil
124: @playlist = if !source.nil? && source.has_key?(:playlist) then
125: if source[:playlist].instance_of?(XSPF::Playlist)
126: source[:playlist]
127: else
128: raise(TypeError, 'You must pass a file/string (parsing mode) or a hash/nothing (generator mode) as argument to XSPF#new')
129: end
130: end
131:
132: elsif ( source.instance_of?(File) || source.instance_of?(String) ) then
133: @xspf = REXML::Document.new(source)
134: ATTRIBUTES.each do |attrib|
135: eval('@' + attrib + '= parse_' + attrib)
136: end
137:
138: @playlist = XSPF::Playlist.new(self)
139:
140: else
141: raise(TypeError, 'You must pass a file/string (parsing mode) or a hash/nothing (generator mode) as argument to XSPF#new')
142: end
143: end
Encoding of the XML document or nil if not defined
# File xspf-expanded.rb, line 23
23: def encoding
24: @encoding
25: end
A XSPF::Playlist object
# File lib/xspf.rb, line 146
146: def playlist
147: @playlist
148: end
# File lib/xspf.rb, line 150
150: def playlist=(value)
151: raise(TypeError, 'The playlist must be an instance of XSPF::Playlist') unless value.instance_of?(XSPF::Playlist)
152: @playlist = value
153: end
Outputs the playlist as an HTML page. This method makes use of the official XSPF to HTML XSLT transformation by Lucas Gonze.
# File xspf-expanded.rb, line 53
53: def to_html
54: xslt = XML::XSLT.new
55: xslt.xml = self.to_xml
56: xslt.xsl = REXML::Document.new( File.new( './lib/xspf2html.xsl' ) )
57: xslt.serve
58: end
Creates a .m3u playlist from the XSPF document. This method makes use of the official XSPF to M3U XSLT transformation by Lucas Gonze.
# File xspf-expanded.rb, line 43
43: def to_m3u
44: xslt = XML::XSLT.new
45: xslt.xml = self.to_xml
46: xslt.xsl = REXML::Document.new( File.new( './lib/xspf2m3u.xsl' ) )
47: xslt.serve
48: end
Creates a .smil playlist from the XSPF document. This method makes use of the official XSPF to SMIL XSLT transformation by Lucas Gonze.
# File xspf-expanded.rb, line 63
63: def to_smil
64: xslt = XML::XSLT.new
65: xslt.xml = self.to_xml
66: xslt.xsl = REXML::Document.new( File.new( './lib/xspf2smil.xsl' ) )
67: xslt.serve
68: end
Creates a SoundBlox playlist from the XSPF document. This method makes use of the official XSPF to SoundBlox XSLT tranformation by Lucas Gonze.
# File xspf-expanded.rb, line 73
73: def to_soundblox
74: xslt = XML::XSLT.new
75: xslt.xml = self.to_xml
76: xslt.xsl = REXML::Document.new( File.new( './lib/xspf2soundblox.xsl' ) )
77: xslt.serve
78: end
Version for the XML document or nil if not defined
# File xspf-expanded.rb, line 3 3: def version 4: @version 5: end