Class: Jabber::UserTune::Tune
- Inherits:
-
XMPPElement
- Object
- REXML::Element
- XMPPElement
- Jabber::UserTune::Tune
- Defined in:
- lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb
Overview
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?
Instance Method Summary collapse
-
#artist ⇒ Object
Get the artist for this tune.
-
#initialize(artist = nil, title = nil, length = nil, track = nil, source = nil, uri = nil, rating = nil) ⇒ Tune
constructor
Construct a new <tune> element.
-
#length ⇒ Object
Get the length of this tune, in seconds.
-
#playing? ⇒ Boolean
Returns true if a tune is currently playing, otherwise false.
-
#rating ⇒ Object
Get the rating for this track.
-
#source ⇒ Object
Get the source of this tune, such as an album.
-
#title ⇒ Object
Get the title of this tune.
-
#track ⇒ Object
Get an identitier for this tune.
-
#uri ⇒ Object
Get a URI that represents this tune.
Methods inherited from XMPPElement
class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=
Methods inherited from REXML::Element
#==, #delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add
Constructor Details
#initialize(artist = nil, title = nil, length = nil, track = nil, source = nil, uri = nil, rating = nil) ⇒ Tune
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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 40 def initialize(artist = nil, title = nil, length = nil, track = nil, source = nil, uri = nil, = nil) super() add_element(REXML::Element.new('artist')).text = artist if artist add_element(REXML::Element.new('title')).text = title if title add_element(REXML::Element.new('length')).text = length.to_s if length add_element(REXML::Element.new('track')).text = track if track add_element(REXML::Element.new('source')).text = source if source add_element(REXML::Element.new('uri')).text = uri if uri if and .kind_of?(Numeric) r = .to_i r = 0 if r < 0 r = 10 if r > 10 add_element(REXML::Element.new('rating')).text = r.to_s end end |
Instance Method Details
#artist ⇒ Object
Get the artist for this tune.
72 73 74 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 72 def artist first_element('artist').text if first_element('artist') end |
#length ⇒ Object
Get the length of this tune, in seconds.
84 85 86 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 84 def length first_element('length').text.to_i if first_element('length') end |
#playing? ⇒ Boolean
Returns true if a tune is currently playing, otherwise false.
66 67 68 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 66 def (elements.size > 0) end |
#rating ⇒ Object
Get the rating for this track
108 109 110 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 108 def first_element('rating').text.to_i if first_element('rating') end |
#source ⇒ Object
Get the source of this tune, such as an album.
96 97 98 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 96 def source first_element('source').text if first_element('source') end |
#title ⇒ Object
Get the title of this tune.
78 79 80 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 78 def title first_element('title').text if first_element('title') end |
#track ⇒ Object
Get an identitier for this tune.
90 91 92 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 90 def track first_element('track').text if first_element('track') end |
#uri ⇒ Object
Get a URI that represents this tune.
102 103 104 |
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb', line 102 def uri first_element('uri').text if first_element('uri') end |