Class: MusicBrainzTrack

Inherits:
Object
  • Object
show all
Defined in:
lib/models/music_brainz_track.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



2
3
4
# File 'lib/models/music_brainz_track.rb', line 2

def length
  @length
end

#positionObject

Returns the value of attribute position.



2
3
4
# File 'lib/models/music_brainz_track.rb', line 2

def position
  @position
end

#recording_idObject

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

#titleObject

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