Class: MusicBrainzTrack
- Inherits:
-
Object
- Object
- MusicBrainzTrack
- Defined in:
- lib/models/music_brainz_track.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
-
#position ⇒ Object
Returns the value of attribute position.
-
#recording_id ⇒ Object
Returns the value of attribute recording_id.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
2 3 4 |
# File 'lib/models/music_brainz_track.rb', line 2 def length @length end |
#position ⇒ Object
Returns the value of attribute position.
2 3 4 |
# File 'lib/models/music_brainz_track.rb', line 2 def position @position end |
#recording_id ⇒ Object
Returns the value of attribute recording_id.
2 3 4 |
# File 'lib/models/music_brainz_track.rb', line 2 def recording_id @recording_id end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/models/music_brainz_track.rb', line 2 def title @title end |
Class Method Details
.find(mbid) ⇒ Object
4 5 6 7 |
# File 'lib/models/music_brainz_track.rb', line 4 def self.find mbid xml = Nokogiri::XML(open('http://musicbrainz.org/ws/2/recording/' + mbid)) self.parse_xml(xml) unless xml.nil? end |
.parse_xml(xml) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/models/music_brainz_track.rb', line 9 def self.parse_xml xml @track = MusicBrainzTrack.new @track.position = xml.css('position').text.to_i || nil @track.recording_id = xml.css('recording').attr('id').value @track.title = xml.css('recording > title').text @track.length = xml.css('length').first.text.to_i || 0 @track end |