lib/musicbrainz/track.rb in musicbrainz-0.6.0 vs lib/musicbrainz/track.rb in musicbrainz-0.7.0

- old
+ new

@@ -1,21 +1,23 @@ # -*- encoding: utf-8 -*- + module MusicBrainz - class Track < MusicBrainz::Base - attr_accessor :position, :recording_id, :title, :length + class Track < Base - def self.find mbid - xml = Nokogiri::XML(self.load(:recording, :id => mbid)) - self.parse_xml(xml) unless xml.nil? - end + field :position, Integer + field :recording_id, String + field :title, String + field :length, Integer - def self.parse_xml xml - @track = MusicBrainz::Track.new - @track.position = self.safe_get_value(xml, 'position').to_i - @track.recording_id = self.safe_get_attr(xml, 'recording', 'id') - @track.title = self.safe_get_value(xml, 'recording > title') - @track.length = self.safe_get_value(xml, 'length').to_i - @track.length = self.safe_get_value(xml, 'recording > length').to_i - @track + class << self + def find(mbid) + load({ + :parser => :track_model, + :create_model => MusicBrainz::Track + }, { + :resource => :recording, + :id => mbid + }) + end end end end