Class | Jabber::UserTune::Tune |
In: |
lib/xmpp4r/tune/tune.rb
|
Parent: | XMPPElement |
The <tune> XMPP element, as defined in XEP-0118 User Tune
See www.xmpp.org/extensions/xep-0118.html - this element encapsulates metadata (artist, track etc) about a tune the user is currently playing. These are expressed as child elements such as <artist>, <title> etc which are also managed by this class.
If the element has no children then it indicates that the user has stopped playing a tune. Use the Tune#playing? method to discover this?
Construct a new <tune> element.
Supply no arguments to make an empty element to indicate that tune playing has stopped.
artist: | [String] the artist or performer of the song or piece |
title: | [String] the title of the song or piece |
length: | [Fixnum] the duration of the song or piece in seconds |
track: | [String] a unique identifier for the tune; e.g., the track number within a collection or the specific URI for the object (e.g., a stream or audio file) |
source: | [String] the collection (e.g., album) or other source (e.g., a band website that hosts streams or audio files) |
uri: | [String] a URI or URL pointing to information about the song, collection, or artist |
rating: | [Numeric] a number indicating how much you like this song - will be clamped into an integer 0 <= x <= 10 |
# File lib/xmpp4r/tune/tune.rb, line 40 40: def initialize(artist = nil, title = nil, length = nil, track = nil, source = nil, uri = nil, rating = nil) 41: super() 42: 43: add_element(REXML::Element.new('artist')).text = artist if artist 44: 45: add_element(REXML::Element.new('title')).text = title if title 46: 47: add_element(REXML::Element.new('length')).text = length.to_s if length 48: 49: add_element(REXML::Element.new('track')).text = track if track 50: 51: add_element(REXML::Element.new('source')).text = source if source 52: 53: add_element(REXML::Element.new('uri')).text = uri if uri 54: 55: if rating and rating.kind_of?(Numeric) 56: r = rating.to_i 57: r = 0 if r < 0 58: r = 10 if r > 10 59: add_element(REXML::Element.new('rating')).text = r.to_s 60: end 61: end
Returns true if a tune is currently playing, otherwise false.
# File lib/xmpp4r/tune/tune.rb, line 66 66: def playing? 67: (elements.size > 0) 68: end