Class XSPF
In: xspf-expanded.rb
lib/xspf.rb
Parent: Object

Methods

Classes and Modules

Class XSPF::Playlist
Class XSPF::Track
Class XSPF::Tracklist

Attributes

xspf  [R] 

Public Class methods

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

[Source]

     # 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

Public Instance methods

Encoding of the XML document or nil if not defined

[Source]

    # File xspf-expanded.rb, line 23
23:     def encoding
24:       @encoding
25:     end

[Source]

    # File xspf-expanded.rb, line 27
27:     def encoding=(value)
28:       @encoding = value
29:     end

A XSPF::Playlist object

[Source]

     # File lib/xspf.rb, line 146
146:   def playlist
147:     @playlist
148:   end

[Source]

     # 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.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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

Exports the XSPF object to XML

[Source]

     # File lib/xspf.rb, line 156
156:   def to_xml
157:     xml = REXML::Document.new
158:     xml << REXML::XMLDecl.new(@version, @encoding)
159:     xml << REXML::Document.new(@playlist.to_xml) unless @playlist.nil?
160:     xml.to_s
161:   end

Version for the XML document or nil if not defined

[Source]

   # File xspf-expanded.rb, line 3
3:     def version
4:       @version
5:     end

[Source]

   # File xspf-expanded.rb, line 7
7:     def version=(value)
8:       @version = value
9:     end

Protected Instance methods

The <playlist> section of the XSPF document (outputs XML code). This method is only used while parsing.

[Source]

     # File lib/xspf.rb, line 165
165:   def playlist_xml
166:     @xspf.root
167:   end

[Validate]