-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Medium model and binding * Add medium tracks * Updated GitHub Actions workflow
- Loading branch information
1 parent
45ca1f7
commit a77b788
Showing
11 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module MusicBrainz | ||
module Bindings | ||
module Medium | ||
def parse(xml) | ||
{ | ||
position: (xml.xpath('./position').text rescue nil), | ||
format: (xml.xpath('./format').text rescue nil), | ||
tracks: xml.xpath('./track-list/track').map do |track_xml| | ||
MusicBrainz::Bindings::Track.parse(track_xml) | ||
end | ||
} | ||
end | ||
|
||
extend self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module MusicBrainz | ||
module Bindings | ||
module ReleaseMediums | ||
def parse(xml) | ||
xml.xpath('./release/medium-list/medium').map do |xml| | ||
MusicBrainz::Bindings::Medium.parse(xml) | ||
end | ||
end | ||
|
||
extend self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module MusicBrainz | ||
class Medium < BaseModel | ||
field :position, Integer | ||
field :format, String | ||
field :tracks, Array | ||
|
||
def tracks=(tracks_data) | ||
@tracks = tracks_data.map { |track_data| Track.new(track_data) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "spec_helper" | ||
|
||
describe MusicBrainz::Bindings::Medium do | ||
describe '.parse' do | ||
subject(:parse) { described_class.parse(xml) } | ||
|
||
let(:xml) { Nokogiri::XML(<<~XML).at_xpath('medium') } | ||
<medium> | ||
<position>1</position> | ||
<format id="9712d52a-4509-3d4b-a1a2-67c88c643e31">CD</format> | ||
<track-list> | ||
<track id="0501cf38-48b7-3026-80d2-717d574b3d6a"> | ||
<position>1</position> | ||
<number>1</number> | ||
<length>233013</length> | ||
<recording id="b3015bab-1540-4d4e-9f30-14872a1525f7"> | ||
<title>Empire</title> | ||
<length>233013</length> | ||
<first-release-date>2006-08-25</first-release-date> | ||
</recording> | ||
</track> | ||
</track-list> | ||
</medium> | ||
XML | ||
|
||
it 'contains medium attributes' do | ||
expect(parse).to include(position: '1', format: 'CD') | ||
end | ||
|
||
it 'contains track attributes' do | ||
expect(parse[:tracks].first).to include( | ||
id: '0501cf38-48b7-3026-80d2-717d574b3d6a', position: '1', length: '233013', | ||
recording_id: 'b3015bab-1540-4d4e-9f30-14872a1525f7', title: 'Empire' | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "spec_helper" | ||
|
||
describe MusicBrainz::Medium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters