Class: XSPF
- Inherits:
-
Object
- Object
- XSPF
- Defined in:
- lib/xspf.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Playlist, Track, Tracklist
Constant Summary collapse
- ATTRIBUTES =
:stopdoc:
%w{ version encoding }
- VERSION_RDOC =
'Version for the XML document or _nil_ if not defined'
- ENCODING_RDOC =
'Encoding of the XML document or _nil_ if not defined'
- OUTPUT_FORMATS =
%w{ m3u html smil rdf soundblox }
- M3U_RDOC =
'Creates a .m3u playlist from the XSPF document. This method makes use of the official XSPF to M3U XSLT transformation by Lucas Gonze.'
- HTML_RDOC =
'Outputs the playlist as an HTML page. This method makes use of the official XSPF to HTML XSLT transformation by Lucas Gonze.'
- SMIL_RDOC =
'Creates a .smil playlist from the XSPF document. This method makes use of the official XSPF to SMIL XSLT transformation by Lucas Gonze.'
- SOUNDBLOX_RDOC =
'Creates a SoundBlox playlist from the XSPF document. This method makes use of the official XSPF to SoundBlox XSLT tranformation by Lucas Gonze.'
- RDF_RDOC =
'Creates a RDF feed from the XSPF document. This method makes use of the XSPF to RDF XSLT transformation by Libby Miller.'
Instance Attribute Summary collapse
-
#xspf ⇒ Object
readonly
Returns the value of attribute xspf.
Instance Method Summary collapse
-
#initialize(source = nil) ⇒ XSPF
constructor
Creates a XSPF object from a file or string (parse mode) or from a hash or nil (generation mode).
-
#playlist ⇒ Object
A XSPF::Playlist object.
- #playlist=(value) ⇒ Object
-
#to_xml ⇒ Object
Exports the XSPF object to XML.
Constructor Details
#initialize(source = nil) ⇒ XSPF
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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/xspf.rb', line 120 def initialize(source = nil) if ( source.nil? || source.instance_of?(Hash) ) then @version = if source.nil? || !source.has_key?(:version) '1.0' else source[:version] end @encoding = if source.nil? || !source.has_key?(:encoding) 'UTF-8' else source[:encoding] end @playlist = nil @playlist = if !source.nil? && source.has_key?(:playlist) then if source[:playlist].instance_of?(XSPF::Playlist) source[:playlist] else raise(TypeError, 'You must pass a file/string (parsing mode) or a hash/nothing (generator mode) as argument to XSPF#new') end end elsif ( source.instance_of?(File) || source.instance_of?(String) ) then @xspf = REXML::Document.new(source) ATTRIBUTES.each do |attrib| eval('@' + attrib + '= parse_' + attrib) end @playlist = XSPF::Playlist.new(self) else raise(TypeError, 'You must pass a file/string (parsing mode) or a hash/nothing (generator mode) as argument to XSPF#new') end end |
Instance Attribute Details
#xspf ⇒ Object (readonly)
Returns the value of attribute xspf.
93 94 95 |
# File 'lib/xspf.rb', line 93 def xspf @xspf end |
Instance Method Details
#playlist ⇒ Object
A XSPF::Playlist object
155 156 157 |
# File 'lib/xspf.rb', line 155 def playlist @playlist end |
#playlist=(value) ⇒ Object
159 160 161 162 |
# File 'lib/xspf.rb', line 159 def playlist=(value) raise(TypeError, 'The playlist must be an instance of XSPF::Playlist') unless value.instance_of?(XSPF::Playlist) @playlist = value end |
#to_xml ⇒ Object
Exports the XSPF object to XML
165 166 167 168 169 170 |
# File 'lib/xspf.rb', line 165 def to_xml xml = REXML::Document.new xml << REXML::XMLDecl.new(@version, @encoding) xml << REXML::Document.new(@playlist.to_xml) unless @playlist.nil? xml.to_s end |