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

Methods

Attributes

playlist  [R] 

Public Class methods

Creates a XSPF::Playlist from a XSPF document (parse mode) or from a hash of values (generation mode)

Possible keys in the hash: :xmlns, :version, :title, :creator, :annotation, :info, :location, :identifier, :image, :date, :license, :attribution, :extension, :link_rel, :link_content, :meta_rel, :meta_content

[Source]

     # File lib/xspf.rb, line 227
227:   def initialize(source = nil)
228: 
229:     if ( source.instance_of?(Hash) || source.nil? ) then
230: 
231:       ATTRIBUTES.each do |attrib|
232:         add_instance_variable(source, attrib)
233:       end
234: 
235:       ELEMENTS.each do |element|
236:         add_instance_variable(source, element)
237:       end
238: 
239:       ATTRIBUTE_AND_ELEMENT.each do |ae|
240:         add_instance_variable(source, "#{ae}_content" )
241:         add_instance_variable(source, "#{ae}_rel" )
242:       end
243: 
244:       @tracklist = if ( !source.nil? && source.has_key?(:tracklist) && source[:tracklist].instance_of?(XSPF::Tracklist) )
245:                       source[:tracklist]
246:                     else
247:                       nil
248:                     end
249: 
250:     elsif source.instance_of?(XSPF) then
251: 
252:       @playlist = source.playlist_xml
253: 
254:       ATTRIBUTES.each do |attrib|
255:         eval('@' + attrib.downcase + '= parse_' + attrib.downcase)
256:       end
257:   
258:       ELEMENTS.each do |element|
259:         eval('@' + element.downcase + '= parse_' + element.downcase)
260:       end
261: 
262:       ATTRIBUTE_AND_ELEMENT.each do |ae|
263:         eval('@' + ae.downcase + '_content = parse_' + ae.downcase + '_content')
264:         eval('@' + ae.downcase + '_rel = parse_' + ae.downcase + '_rel')
265:       end
266: 
267:       @tracklist = XSPF::Tracklist.new(self)
268: 
269:     else
270:       raise(TypeError, 'You must pass a XSPF object (parsing mode) or a hash (generator mode) as argument to XSPF::Playlist#new')
271:     end
272:     
273:   end

Public Instance methods

<<(value)

Alias for tracklist=

A human-readable comment on the playlist. This is character data, not HTML, and it may not contain markup. XSPF::Playlist objects elements MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 163
163:     def annotation
164:       @annotation
165:     end

[Source]

     # File xspf-expanded.rb, line 167
167:     def annotation=(value)
168:       @annotation = value
169:     end

An ordered list of URIs. The purpose is to satisfy licenses allowing modification but requiring attribution. If you modify such a playlist, move its XSPF::Playlist#location or XSPF::Playlist#identifier element to the top of the items in the XSPF::Playlist#attribution element. XSPF::Playlist objects MAY contain exactly one attribution element. Please note that currently XSPF for Ruby does not parse the contents of XSPF::Playlist#attribution.

[Source]

     # File xspf-expanded.rb, line 303
303:     def attribution
304:       @attribution
305:     end

[Source]

     # File xspf-expanded.rb, line 307
307:     def attribution=(value)
308:       @attribution = value
309:     end

Human-readable name of the entity (author, authors, group, company, etc) that authored the playlist. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 143
143:     def creator
144:       @creator
145:     end

[Source]

     # File xspf-expanded.rb, line 147
147:     def creator=(value)
148:       @creator = value
149:     end

Creation date (not last-modified date) of the playlist, formatted as a XML schema dateTime. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 263
263:     def date
264:       @date
265:     end

[Source]

     # File xspf-expanded.rb, line 267
267:     def date=(value)
268:       @date = value
269:     end

The extension element allows non-XSPF XML to be included in XSPF documents without breaking XSPF validation. The purpose is to allow nested XML, which the meta and link elements do not. XSPF::Playlist objects MAY contain zero or more extension elements but currently XSPF for Ruby returns only the first one.

[Source]

     # File xspf-expanded.rb, line 323
323:     def extension
324:       @extension
325:     end

[Source]

     # File xspf-expanded.rb, line 327
327:     def extension=(value)
328:       @extension = value
329:     end

Canonical ID for this playlist. Likely to be a hash or other location-independent name. MUST be a legal URN. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 223
223:     def identifier
224:       @identifier
225:     end

[Source]

     # File xspf-expanded.rb, line 227
227:     def identifier=(value)
228:       @identifier = value
229:     end

URL of an image to display if XSPF::Playlist#image return nil. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 243
243:     def image
244:       @image
245:     end

[Source]

     # File xspf-expanded.rb, line 247
247:     def image=(value)
248:       @image = value
249:     end

URL of a web page to find out more about this playlist. Likely to be homepage of the author, and would be used to find out more about the author and to find more playlists by the author. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 183
183:     def info
184:       @info
185:     end

[Source]

     # File xspf-expanded.rb, line 187
187:     def info=(value)
188:       @info = value
189:     end

URL of a resource that describes the license under which this playlist was released. XSPF::Playlist objects MAY contain zero or one license element.

[Source]

     # File xspf-expanded.rb, line 283
283:     def license
284:       @license
285:     end

[Source]

     # File xspf-expanded.rb, line 287
287:     def license=(value)
288:       @license = value
289:     end

The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid link element has a rel attribute and a content element, obtained with XSPF::Playlist#link_rel and XSPF::Playlist#link_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one.

[Source]

     # File xspf-expanded.rb, line 343
343:     def link_content
344:       @link_content
345:     end

[Source]

     # File xspf-expanded.rb, line 347
347:     def link_content=(value)
348:       @link_content = value
349:     end

The link element allows non-XSPF web resources to be included in XSPF documents without breaking XSPF validation. A valid link element has a rel attribute and a content element, obtained with XSPF::Playlist#link_rel and XSPF::Playlist#link_content respectively. XSPF::Playlist objects MAY contain zero or more link elements, but currently XSPF for Ruby returns only the first one.

[Source]

     # File xspf-expanded.rb, line 363
363:     def link_rel
364:       @link_rel
365:     end

[Source]

     # File xspf-expanded.rb, line 367
367:     def link_rel=(value)
368:       @link_rel = value
369:     end

Source URL for this playlist. XSPF::Playlist objects MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 203
203:     def location
204:       @location
205:     end

[Source]

     # File xspf-expanded.rb, line 207
207:     def location=(value)
208:       @location = value
209:     end

The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid meta element has a rel attribute and a content element, obtained with XSPF::Playlist#meta_rel and XSPF::Playlist#meta_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one.

[Source]

     # File xspf-expanded.rb, line 383
383:     def meta_content
384:       @meta_content
385:     end

[Source]

     # File xspf-expanded.rb, line 387
387:     def meta_content=(value)
388:       @meta_content = value
389:     end

The meta element allows non-XSPF metadata to be included in XSPF documents without breaking XSPF validation. A valid meta element has a rel attribute and a content element, obtained with XSPF::Playlist#meta_rel and XSPF::Playlist#meta_content respectively. XSPF::Playlist objects MAY contain zero or more meta elements, but currently XSPF for Ruby returns only the first one.

[Source]

     # File xspf-expanded.rb, line 403
403:     def meta_rel
404:       @meta_rel
405:     end

[Source]

     # File xspf-expanded.rb, line 407
407:     def meta_rel=(value)
408:       @meta_rel = value
409:     end

A human-readable title for the playlist. xspf:playlist elements MAY contain exactly one.

[Source]

     # File xspf-expanded.rb, line 123
123:     def title
124:       @title
125:     end

[Source]

     # File xspf-expanded.rb, line 127
127:     def title=(value)
128:       @title = value
129:     end

Exports the XSPF::Playlist to XML (only the <playlist> section)

[Source]

     # File lib/xspf.rb, line 288
288:   def to_xml
289:   
290:     xml = REXML::Element.new('playlist')
291: 
292:     ATTRIBUTES.each do |attrib|
293:       # TODO Sure there is a nicer way to do evaluate this condition...
294:       unless eval('@' + attrib.downcase + '.nil?')
295:         xml.attributes[attrib] = eval('@' + attrib.downcase)
296:       end 
297:     end
298:     
299:     ELEMENTS.each do |element|
300:       # TODO Sure there is a nicer way to do evaluate this condition...
301:       unless eval('@' + element.downcase + '.nil?')
302:         el = REXML::Element.new(element)
303:         el.add_text( eval('@' + element.downcase) )
304:         xml.add_element(el)
305:       end 
306:     end
307: 
308:     ATTRIBUTE_AND_ELEMENT.each do |ae|
309:       # TODO Sure there is a nicer way to do evaluate this condition...
310:       unless eval('@' + ae.downcase + '_rel.nil? && @'+ ae.downcase + '_content.nil?')
311:         el = REXML::Element.new(ae.downcase)
312:         el.add_attribute('rel', eval('@' + ae.downcase + '_rel') )
313:         el.add_text( eval('@' + ae.downcase + '_content') )
314:         xml.add_element(el)
315:       end 
316:     end
317: 
318:     xml << REXML::Document.new(@tracklist.to_xml)
319:     
320:     xml.to_s
321:   
322:   end

A XSPF::Tracklist object

[Source]

     # File lib/xspf.rb, line 276
276:   def tracklist
277:     @tracklist
278:   end

[Source]

     # File lib/xspf.rb, line 280
280:   def tracklist=(value)
281:     raise(TypeError, 'The tracklist must be an instance of XSPF::Tracklist') unless value.instance_of?(XSPF::Tracklist)
282:     @tracklist = value
283:   end

The XSPF version. It may be 0 or 1, although 1 is strongly advised.

[Source]

     # File xspf-expanded.rb, line 103
103:     def version
104:       @version
105:     end

[Source]

     # File xspf-expanded.rb, line 107
107:     def version=(value)
108:       @version = value
109:     end

The XML namespace. It must be xspf.org/ns/0/ for a valid XSPF document.

[Source]

    # File xspf-expanded.rb, line 83
83:     def xmlns
84:       @xmlns
85:     end

[Source]

    # File xspf-expanded.rb, line 87
87:     def xmlns=(value)
88:       @xmlns = value
89:     end

Protected Instance methods

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

[Source]

     # File lib/xspf.rb, line 326
326:   def tracklist_xml  
327:     @playlist.elements['trackList']
328:   end

[Validate]