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 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.'
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/xspf.rb', line 109 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.
83 84 85 |
# File 'lib/xspf.rb', line 83 def xspf @xspf end |
Instance Method Details
#playlist ⇒ Object
A XSPF::Playlist object
144 145 146 |
# File 'lib/xspf.rb', line 144 def playlist @playlist end |
#playlist=(value) ⇒ Object
148 149 150 151 |
# File 'lib/xspf.rb', line 148 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
154 155 156 157 158 159 |
# File 'lib/xspf.rb', line 154 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 |