1
0
Fork 0
musicbrainz/lib/models/music_brainz/track.rb

20 lines
604 B
Ruby

module MusicBrainz
class Track
attr_accessor :position, :recording_id, :title, :length
def self.find mbid
xml = Nokogiri::XML(MusicBrainz.load('http://musicbrainz.org/ws/2/recording/' + mbid))
self.parse_xml(xml) unless xml.nil?
end
def self.parse_xml xml
@track = MusicBrainz::Track.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
end
end