Refactored Release and Track models, fixed tests

This commit is contained in:
Gregory Eremin
2012-07-09 02:22:23 +04:00
parent 7de2a66613
commit b97625597e
11 changed files with 107 additions and 57 deletions
+9 -1
View File
@@ -6,7 +6,7 @@ module MusicBrainz
class << self
def model(xml)
{
:id => safe_get_attr(xml, nil, "id") || safe_get_attr(xml, "release-group", "id"),
:id => safe_get_attr(xml, nil, "id") || safe_get_attr(xml, "release", "id"),
:title => safe_get_value(xml, "title"),
:status => safe_get_value(xml, "status"),
:country => safe_get_value(xml, "country"),
@@ -14,6 +14,14 @@ module MusicBrainz
:date => safe_get_value(xml, "date")
}
end
def tracks(xml)
tracks = []
xml.css("medium-list > medium > track-list > track").each do |r|
tracks << MusicBrainz::Parsers::Track.model(r)
end
tracks
end
end
end
end
+8 -1
View File
@@ -4,7 +4,14 @@ module MusicBrainz
module Parsers
class Track < Base
class << self
def model(xml)
{
:position => safe_get_value(xml, "position"),
:recording_id => safe_get_attr(xml, "recording", "id"),
:title => safe_get_value(xml, "recording > title"),
:length => safe_get_value(xml, "length") || safe_get_value(xml, "recording > length")
}
end
end
end
end