rbrainz 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +13 -1
- data/examples/getlabel.rb +53 -0
- data/examples/getrelease.rb +50 -0
- data/examples/gettrack.rb +51 -0
- data/examples/searchlabels.rb +35 -0
- data/examples/searchreleases.rb +35 -0
- data/examples/searchtracks.rb +35 -0
- data/lib/rbrainz/core_ext/range.rb +4 -17
- data/lib/rbrainz/core_ext/range/equality.rb +1 -8
- data/lib/rbrainz/model/incomplete_date.rb +45 -9
- data/lib/rbrainz/model/individual.rb +3 -3
- data/lib/rbrainz/model/relation.rb +3 -3
- data/lib/rbrainz/model/release_event.rb +3 -3
- data/lib/rbrainz/version.rb +2 -2
- data/lib/rbrainz/webservice/mbxml.rb +23 -25
- data/test/test_incomplete_date.rb +28 -7
- data/test/test_mbxml.rb +8 -8
- data/test/test_range_equality.rb +10 -11
- metadata +8 -2
data/CHANGES
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
|
+
== 0.2.1 (2007-07-24)
|
4
|
+
* Erroneous date strings in the XML are ignored. No error is raised and nil
|
5
|
+
is set for the date.
|
6
|
+
* MBXML#get_entity_list now returns an ScoredCollection even if no list-element
|
7
|
+
is present in the XML. This is due to the fact that musicbrainz.org always
|
8
|
+
returns an empty result <metadata/> if no matching entities were found.
|
9
|
+
* Removed custom eql? and include? methods from Range and added them to
|
10
|
+
IncompleteDate. Those methods changed the behaviour of Range which might lead
|
11
|
+
to unexcpected results in programs using RBrainz.
|
12
|
+
* Changed IncompleteDate to include its end value.
|
13
|
+
* Added additional examples
|
14
|
+
|
3
15
|
== 0.2.0 (2007-07-19)
|
4
16
|
* Querying of collections implemented
|
5
17
|
* Collection class to store search results (with support for search score and offset)
|
@@ -28,4 +40,4 @@
|
|
28
40
|
== 0.1.0 (2007-05-23)
|
29
41
|
* Initial release
|
30
42
|
|
31
|
-
$Id: CHANGES
|
43
|
+
$Id: CHANGES 156 2007-07-24 17:47:07Z phw $
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which queries the database for an
|
4
|
+
# label and displays the label's data.
|
5
|
+
#
|
6
|
+
# $Id: getlabel.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# The label's MusicBrainz ID.
|
17
|
+
# Either read it from the command line as the first
|
18
|
+
# parameter or use a default one for demonstration.
|
19
|
+
id = $*[0] ? $*[0] : '727ad90b-7ef4-48d2-8f16-c34016544822'
|
20
|
+
|
21
|
+
# Generate a new label MBID object from the ID:
|
22
|
+
mbid = Model::MBID.parse(id, :label)
|
23
|
+
|
24
|
+
# Define what information about the label
|
25
|
+
# should be included in the result.
|
26
|
+
# In this case the label's aliases will be
|
27
|
+
# fetched as well.
|
28
|
+
label_includes = Webservice::LabelIncludes.new(
|
29
|
+
:aliases => true
|
30
|
+
)
|
31
|
+
|
32
|
+
# Create a new Query object which will provide
|
33
|
+
# us an interface to the MusicBrainz web service.
|
34
|
+
query = Webservice::Query.new
|
35
|
+
|
36
|
+
# Now query the MusicBrainz database for the label
|
37
|
+
# with the MBID defined above.
|
38
|
+
# We could as well use the ID string directly instead
|
39
|
+
# of the MBID object.
|
40
|
+
label = query.get_label_by_id(mbid, label_includes)
|
41
|
+
|
42
|
+
# Display the fetched label data together with all
|
43
|
+
# unique release titles.
|
44
|
+
print <<EOF
|
45
|
+
ID : #{label.id.uuid}
|
46
|
+
Name : #{label.name}
|
47
|
+
Sort name : #{label.sort_name}
|
48
|
+
Disambiguation: #{label.disambiguation}
|
49
|
+
Type : #{label.type}
|
50
|
+
Begin date : #{label.begin_date}
|
51
|
+
End date : #{label.end_date}
|
52
|
+
Aliases : #{label.aliases.to_a.join('; ')}
|
53
|
+
EOF
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which queries the database for an
|
4
|
+
# release and displays the release's data.
|
5
|
+
#
|
6
|
+
# $Id: getrelease.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# The release's MusicBrainz ID.
|
17
|
+
# Either read it from the command line as the first
|
18
|
+
# parameter or use a default one for demonstration.
|
19
|
+
id = $*[0] ? $*[0] : '6785cad0-159c-40ec-9ee4-30d8745dd7f9'
|
20
|
+
|
21
|
+
# Generate a new release MBID object from the ID:
|
22
|
+
mbid = Model::MBID.parse(id, :release)
|
23
|
+
|
24
|
+
# Define what information about the release
|
25
|
+
# should be included in the result.
|
26
|
+
# In this case the release artist and the tracks
|
27
|
+
# on the release will be fetched as well.
|
28
|
+
release_includes = Webservice::ReleaseIncludes.new(
|
29
|
+
:artist => true,
|
30
|
+
:tracks => true
|
31
|
+
)
|
32
|
+
|
33
|
+
# Create a new Query object which will provide
|
34
|
+
# us an interface to the MusicBrainz web service.
|
35
|
+
query = Webservice::Query.new
|
36
|
+
|
37
|
+
# Now query the MusicBrainz database for the release
|
38
|
+
# with the MBID defined above.
|
39
|
+
# We could as well use the ID string directly instead
|
40
|
+
# of the MBID object.
|
41
|
+
release = query.get_release_by_id(mbid, release_includes)
|
42
|
+
|
43
|
+
# Display the fetched release data together with all
|
44
|
+
# unique release titles.
|
45
|
+
print <<EOF
|
46
|
+
ID : #{release.id.uuid}
|
47
|
+
Title : #{release.title}
|
48
|
+
Artist : #{release.artist.unique_name}
|
49
|
+
Tracks : #{release.tracks.to_a.join("\r\n ")}
|
50
|
+
EOF
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which queries the database for an
|
4
|
+
# track and displays the track's data.
|
5
|
+
#
|
6
|
+
# $Id: gettrack.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# The track's MusicBrainz ID.
|
17
|
+
# Either read it from the command line as the first
|
18
|
+
# parameter or use a default one for demonstration.
|
19
|
+
id = $*[0] ? $*[0] : 'c29715ad-9a28-4f2b-9b64-4b899b06ac2a'
|
20
|
+
|
21
|
+
# Generate a new track MBID object from the ID:
|
22
|
+
mbid = Model::MBID.parse(id, :track)
|
23
|
+
|
24
|
+
# Define what information about the track
|
25
|
+
# should be included in the result.
|
26
|
+
# In this case the track artist and the releases
|
27
|
+
# the track appears on will be fetched as well.
|
28
|
+
track_includes = Webservice::TrackIncludes.new(
|
29
|
+
:artist => true,
|
30
|
+
:releases => true
|
31
|
+
)
|
32
|
+
|
33
|
+
# Create a new Query object which will provide
|
34
|
+
# us an interface to the MusicBrainz web service.
|
35
|
+
query = Webservice::Query.new
|
36
|
+
|
37
|
+
# Now query the MusicBrainz database for the track
|
38
|
+
# with the MBID defined above.
|
39
|
+
# We could as well use the ID string directly instead
|
40
|
+
# of the MBID object.
|
41
|
+
track = query.get_track_by_id(mbid, track_includes)
|
42
|
+
|
43
|
+
# Display the fetched track data together with all
|
44
|
+
# unique track titles.
|
45
|
+
print <<EOF
|
46
|
+
ID : #{track.id.uuid}
|
47
|
+
Title : #{track.title}
|
48
|
+
Duration : #{track.duration/1000} seconds
|
49
|
+
Artist : #{track.artist.unique_name}
|
50
|
+
Release : #{track.releases.to_a.join("\r\n ")}
|
51
|
+
EOF
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which searches the database for
|
4
|
+
# labels and displays the label's data.
|
5
|
+
#
|
6
|
+
# $Id: searchlabels.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# Define the search parameters: Search for labels with the
|
17
|
+
# name "Paradise Lost" and return a maximum of 10 labels.
|
18
|
+
label_filter = Webservice::LabelFilter.new(
|
19
|
+
:name => 'Century',
|
20
|
+
:limit => 10
|
21
|
+
)
|
22
|
+
|
23
|
+
# Create a new Query object which will provide
|
24
|
+
# us an interface to the MusicBrainz web service.
|
25
|
+
query = Webservice::Query.new
|
26
|
+
|
27
|
+
# Now query the MusicBrainz database for labels
|
28
|
+
# with the search parameters defined above.
|
29
|
+
labels = query.get_labels(label_filter)
|
30
|
+
|
31
|
+
# Display the fetched label's names and the score, which
|
32
|
+
# indicates how good the label matches the search parameters.
|
33
|
+
labels.each do |entry|
|
34
|
+
print "%s (%i%%)\r\n" % [entry.entity.unique_name, entry.score]
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which searches the database for
|
4
|
+
# releases and displays the release data.
|
5
|
+
#
|
6
|
+
# $Id: searchreleases.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# Define the search parameters: Search for releases with the
|
17
|
+
# title "Paradise Lost" and return a maximum of 10 releases.
|
18
|
+
release_filter = Webservice::ReleaseFilter.new(
|
19
|
+
:title => 'Draconian Times',
|
20
|
+
:limit => 10
|
21
|
+
)
|
22
|
+
|
23
|
+
# Create a new Query object which will provide
|
24
|
+
# us an interface to the MusicBrainz web service.
|
25
|
+
query = Webservice::Query.new
|
26
|
+
|
27
|
+
# Now query the MusicBrainz database for releases
|
28
|
+
# with the search parameters defined above.
|
29
|
+
releases = query.get_releases(release_filter)
|
30
|
+
|
31
|
+
# Display the fetched release titles and the score, which
|
32
|
+
# indicates how good the release matches the search parameters.
|
33
|
+
releases.each do |entry|
|
34
|
+
print "%s (%i%%)\r\n" % [entry.entity.title, entry.score]
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script which searches the database for
|
4
|
+
# tracks and displays the track data.
|
5
|
+
#
|
6
|
+
# $Id: searchtracks.rb 150 2007-07-24 08:16:16Z phw $
|
7
|
+
|
8
|
+
# Just make sure we can run this example from the command
|
9
|
+
# line even if RBrainz is not yet installed properly.
|
10
|
+
$: << 'lib/' << '../lib/'
|
11
|
+
|
12
|
+
# Load RBrainz and include the MusicBrainz namespace.
|
13
|
+
require 'rbrainz'
|
14
|
+
include MusicBrainz
|
15
|
+
|
16
|
+
# Define the search parameters: Search for releases with the
|
17
|
+
# title "Paradise Lost" and return a maximum of 10 releases.
|
18
|
+
track_filter = Webservice::TrackFilter.new(
|
19
|
+
:title => 'Shadowkings',
|
20
|
+
:limit => 10
|
21
|
+
)
|
22
|
+
|
23
|
+
# Create a new Query object which will provide
|
24
|
+
# us an interface to the MusicBrainz web service.
|
25
|
+
query = Webservice::Query.new
|
26
|
+
|
27
|
+
# Now query the MusicBrainz database for tracks
|
28
|
+
# with the search parameters defined above.
|
29
|
+
tracks = query.get_tracks(track_filter)
|
30
|
+
|
31
|
+
# Display the fetched track titles and the score, which
|
32
|
+
# indicates how good the track matches the search parameters.
|
33
|
+
tracks.each do |entry|
|
34
|
+
print "%s: \"%s\" (%i%%)\r\n" % [entry.entity.artist, entry.entity.title, entry.score]
|
35
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: range.rb
|
1
|
+
# $Id: range.rb 154 2007-07-24 12:39:02Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -8,21 +8,8 @@
|
|
8
8
|
require File.dirname(__FILE__) + '/range/equality'
|
9
9
|
|
10
10
|
class Range #:nodoc:
|
11
|
-
include MusicBrainz::CoreExtensions::Range::Equality
|
12
|
-
|
13
|
-
alias :old_eql? :eql?
|
14
|
-
def eql?(b)
|
15
|
-
if b.kind_of? ::Range
|
16
|
-
self.begin == b.begin && self.open_end == b.open_end
|
17
|
-
else
|
18
|
-
self.begin == b && self.open_end == b.succ
|
19
|
-
end
|
20
|
-
end
|
21
|
-
remove_method :==
|
22
|
-
alias :== :eql?
|
23
11
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
12
|
+
# Extend Range with additional comparison operations.
|
13
|
+
include MusicBrainz::CoreExtensions::Range::Equality
|
14
|
+
|
28
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: equality.rb
|
1
|
+
# $Id: equality.rb 154 2007-07-24 12:39:02Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -211,13 +211,6 @@ Allready exists in Range so we can't define it in the module
|
|
211
211
|
self.starts?(b) || self.during?(b) || self.finishes?(b)
|
212
212
|
end
|
213
213
|
|
214
|
-
=begin comment
|
215
|
-
Allready exists in Range so we can't define it in the module
|
216
|
-
def include?(b)
|
217
|
-
self.started_by?(b) || self.contains?(b) || self.eql?(b) || self.finished_by?(b)
|
218
|
-
end
|
219
|
-
=end
|
220
|
-
|
221
214
|
protected
|
222
215
|
def open_end # :nodoc:
|
223
216
|
if self.exclude_end?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: incomplete_date.rb
|
1
|
+
# $Id: incomplete_date.rb 154 2007-07-24 12:39:02Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -10,10 +10,16 @@ require 'date'
|
|
10
10
|
module MusicBrainz
|
11
11
|
module Model
|
12
12
|
|
13
|
-
# Represents an incomplete date. An incomplete date is
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
13
|
+
# Represents an incomplete date. An incomplete date is a date which can be
|
14
|
+
# defined without day or without month and day. It can be written as
|
15
|
+
# <em>YYYY</em>, <em>YYYY-MM</em> or <em>YYYY-MM-DD</em>.
|
16
|
+
#
|
17
|
+
# An IncompleteDate is a Range of Date objects. The incomplete date
|
18
|
+
# <em>1969-01</em> for example results in a range beginning on 1969-01-01
|
19
|
+
# and ending on 1969-01-31, including the end.
|
20
|
+
#
|
21
|
+
# RBrainz extends the Ruby Range class with additional comparison methods.
|
22
|
+
# See CoreExtensions::Range::Equality for a description of those methods.
|
17
23
|
class IncompleteDate < ::Range
|
18
24
|
attr_reader :year, :month, :day
|
19
25
|
|
@@ -28,16 +34,16 @@ module MusicBrainz
|
|
28
34
|
if @month
|
29
35
|
if @day
|
30
36
|
start_d = Date.civil( @year, @month, @day)
|
31
|
-
end_d = start_d
|
37
|
+
end_d = start_d
|
32
38
|
else
|
33
39
|
start_d = Date.civil( @year, @month)
|
34
|
-
end_d = Date.civil( @year, @month
|
40
|
+
end_d = Date.civil( @year, @month, -1)
|
35
41
|
end
|
36
42
|
else
|
37
43
|
start_d = Date.civil( @year)
|
38
|
-
end_d = Date.civil( @year
|
44
|
+
end_d = Date.civil( @year, -1, -1)
|
39
45
|
end
|
40
|
-
super( start_d, end_d
|
46
|
+
super( start_d, end_d)
|
41
47
|
else
|
42
48
|
raise ArgumentError, "Invalid incomplete date #{date}"
|
43
49
|
end
|
@@ -54,6 +60,36 @@ module MusicBrainz
|
|
54
60
|
}
|
55
61
|
return date
|
56
62
|
end
|
63
|
+
|
64
|
+
# Compare two IncompleteDate objects for equality.
|
65
|
+
#
|
66
|
+
# You can compare an IncompleteDate with another IncompleteDate, with
|
67
|
+
# a Range of Date objects or directly with a Date. The following examples
|
68
|
+
# all return true:
|
69
|
+
#
|
70
|
+
# IncompleteDate.new('1969-01-05').eql?( IncompleteDate.new('1969-01-05') )
|
71
|
+
# IncompleteDate.new('1969-01-05').eql?( Date.civil(1969, 1, 5) )
|
72
|
+
# IncompleteDate.new('1969-01').eql?( Date.civil(1969, 1)..Date.civil(1969, 1, 31) )
|
73
|
+
# IncompleteDate.new('1969-01').eql?( Date.civil(1969, 1)...Date.civil(1969, 2, 1) )
|
74
|
+
#
|
75
|
+
# Please note that comparing an IncompleteDate with something else than a
|
76
|
+
# IncompleteDate is normally not symmetric.
|
77
|
+
def eql?(b)
|
78
|
+
if b.kind_of? ::Range
|
79
|
+
self.begin == b.begin && self.open_end == b.open_end
|
80
|
+
else
|
81
|
+
self.begin == b && self.open_end == b.succ
|
82
|
+
end
|
83
|
+
end
|
84
|
+
alias :== :eql?
|
85
|
+
|
86
|
+
# Returns true if b is completely included in this IncompleteDate. Unlike
|
87
|
+
# CoreExtensions::Range::Equality#contains? include? allows equality for
|
88
|
+
# begin and end.
|
89
|
+
def include?(b)
|
90
|
+
self.started_by?(b) || self.contains?(b) || self.eql?(b) || self.finished_by?(b)
|
91
|
+
end
|
92
|
+
|
57
93
|
end
|
58
94
|
|
59
95
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: individual.rb
|
1
|
+
# $Id: individual.rb 151 2007-07-24 08:36:27Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -65,7 +65,7 @@ module MusicBrainz
|
|
65
65
|
# Should be an IncompleteDate object or a date string, which will
|
66
66
|
# get converted into an IncompleteDate.
|
67
67
|
def begin_date=(date)
|
68
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
68
|
+
date = IncompleteDate.new date unless date.is_a? IncompleteDate or date.nil?
|
69
69
|
@begin_date = date
|
70
70
|
end
|
71
71
|
|
@@ -74,7 +74,7 @@ module MusicBrainz
|
|
74
74
|
# Should be an IncompleteDate object or a date string, which will
|
75
75
|
# get converted into an IncompleteDate.
|
76
76
|
def end_date=(date)
|
77
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
77
|
+
date = IncompleteDate.new date unless date.is_a? IncompleteDate or date.nil?
|
78
78
|
@end_date = date
|
79
79
|
end
|
80
80
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: relation.rb
|
1
|
+
# $Id: relation.rb 151 2007-07-24 08:36:27Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -128,7 +128,7 @@ module MusicBrainz
|
|
128
128
|
# a date string, which will get converted
|
129
129
|
# into an IncompleteDate.
|
130
130
|
def begin_date=(date)
|
131
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
131
|
+
date = IncompleteDate.new date unless date.is_a? IncompleteDate or date.nil?
|
132
132
|
@begin_date = date
|
133
133
|
end
|
134
134
|
|
@@ -138,7 +138,7 @@ module MusicBrainz
|
|
138
138
|
# a date string, which will get converted
|
139
139
|
# into an IncompleteDate.
|
140
140
|
def end_date=(date)
|
141
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
141
|
+
date = IncompleteDate.new date unless date.is_a? IncompleteDate or date.nil?
|
142
142
|
@end_date = date
|
143
143
|
end
|
144
144
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: release_event.rb
|
1
|
+
# $Id: release_event.rb 151 2007-07-24 08:36:27Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -44,7 +44,7 @@ module MusicBrainz
|
|
44
44
|
|
45
45
|
def initialize(country=nil, date=nil)
|
46
46
|
self.country = country
|
47
|
-
self.date = date
|
47
|
+
self.date = date
|
48
48
|
end
|
49
49
|
|
50
50
|
# Set the date the release took place.
|
@@ -53,7 +53,7 @@ module MusicBrainz
|
|
53
53
|
# a date string, which will get converted
|
54
54
|
# into an IncompleteDate.
|
55
55
|
def date=(date)
|
56
|
-
date = IncompleteDate.new date unless date.is_a? IncompleteDate
|
56
|
+
date = IncompleteDate.new date unless date.is_a? IncompleteDate or date.nil?
|
57
57
|
@date = date
|
58
58
|
end
|
59
59
|
|
data/lib/rbrainz/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: version.rb
|
1
|
+
# $Id: version.rb 153 2007-07-24 09:04:25Z phw $
|
2
2
|
#
|
3
3
|
# Version information.
|
4
4
|
#
|
@@ -10,6 +10,6 @@
|
|
10
10
|
module MusicBrainz
|
11
11
|
|
12
12
|
# The version of the RBrainz library.
|
13
|
-
RBRAINZ_VERSION = '0.2.
|
13
|
+
RBRAINZ_VERSION = '0.2.1'
|
14
14
|
|
15
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: mbxml.rb
|
1
|
+
# $Id: mbxml.rb 152 2007-07-24 08:47:28Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -75,10 +75,8 @@ module MusicBrainz
|
|
75
75
|
# entity type. There must be an entity-list element as a child of the
|
76
76
|
# +metadata+ element in the document.
|
77
77
|
#
|
78
|
-
# Returns an empty
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# Raises:: MBXML::ParseError
|
78
|
+
# Returns an empty ScoredCollection if the list is empty or if no
|
79
|
+
# entity-list element can be found.
|
82
80
|
def get_entity_list(entity_type, ns=Model::NS_MMD_1)
|
83
81
|
# Search for the first occuring node of type entity which is a child node
|
84
82
|
# of the metadata element.
|
@@ -97,9 +95,8 @@ module MusicBrainz
|
|
97
95
|
|
98
96
|
return collection
|
99
97
|
else
|
100
|
-
|
98
|
+
return Model::ScoredCollection.new
|
101
99
|
end
|
102
|
-
return nil
|
103
100
|
end
|
104
101
|
|
105
102
|
private # ----------------------------------------------------------------
|
@@ -133,12 +130,8 @@ module MusicBrainz
|
|
133
130
|
artist.disambiguation = node.elements['disambiguation'].text if node.elements['disambiguation']
|
134
131
|
|
135
132
|
if life_span = node.elements['life-span']
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
if life_span.attributes['end']
|
140
|
-
artist.end_date = Model::IncompleteDate.new life_span.attributes['end']
|
141
|
-
end
|
133
|
+
artist.begin_date = read_date_attribute(life_span, 'begin')
|
134
|
+
artist.end_date = read_date_attribute(life_span, 'end')
|
142
135
|
end
|
143
136
|
|
144
137
|
# Read the alias list
|
@@ -306,12 +299,8 @@ module MusicBrainz
|
|
306
299
|
label.country = node.elements['country'].text if node.elements['country']
|
307
300
|
|
308
301
|
if life_span = node.elements['life-span']
|
309
|
-
|
310
|
-
|
311
|
-
end
|
312
|
-
if life_span.attributes['end']
|
313
|
-
label.end_date = Model::IncompleteDate.new life_span.attributes['end']
|
314
|
-
end
|
302
|
+
label.begin_date = read_date_attribute(life_span, 'begin')
|
303
|
+
label.end_date = read_date_attribute(life_span, 'end')
|
315
304
|
end
|
316
305
|
|
317
306
|
# Read the alias list
|
@@ -386,9 +375,7 @@ module MusicBrainz
|
|
386
375
|
event = @factory.new_release_event
|
387
376
|
|
388
377
|
# Read all defined data fields
|
389
|
-
|
390
|
-
event.date = Model::IncompleteDate.new node.attributes['date']
|
391
|
-
end
|
378
|
+
event.date = read_date_attribute(node, 'date')
|
392
379
|
event.country = node.attributes['country']
|
393
380
|
event.catalog_number = node.attributes['catalog-number']
|
394
381
|
event.barcode = node.attributes['barcode']
|
@@ -451,9 +438,7 @@ module MusicBrainz
|
|
451
438
|
relation.type = MBXML.add_namespace(node.attributes['type'], Model::NS_REL_1)
|
452
439
|
end
|
453
440
|
|
454
|
-
|
455
|
-
relation.begin_date = Model::IncompleteDate.new node.attributes['begin']
|
456
|
-
end
|
441
|
+
relation.begin_date = read_date_attribute(node, 'begin')
|
457
442
|
|
458
443
|
if node.attributes['end']
|
459
444
|
relation.begin_end = Model::IncompleteDate.new node.attributes['end']
|
@@ -565,6 +550,19 @@ module MusicBrainz
|
|
565
550
|
def self.each_element(node, local_name, ns, &block)
|
566
551
|
node.elements.each("*[local-name() = '#{local_name}' and namespace-uri()='#{ns}']", &block)
|
567
552
|
end
|
553
|
+
|
554
|
+
# Read a date attribute from node. Returns an IncompleteDate or nil
|
555
|
+
# if the attribute was not set or contained an invalid date.
|
556
|
+
def read_date_attribute(node, attr_name)
|
557
|
+
if node.attributes[attr_name]
|
558
|
+
begin
|
559
|
+
Model::IncompleteDate.new node.attributes[attr_name]
|
560
|
+
rescue ArgumentError
|
561
|
+
nil
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
568
566
|
end
|
569
567
|
|
570
568
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_incomplete_date.rb
|
1
|
+
# $Id: test_incomplete_date.rb 154 2007-07-24 12:39:02Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
@@ -53,15 +53,36 @@ class TestIncompleteDate < Test::Unit::TestCase
|
|
53
53
|
|
54
54
|
def test_range
|
55
55
|
assert_equal Date.civil(1980,8,22), @date_year_month_day.begin
|
56
|
-
assert_equal Date.civil(1980,8,
|
57
|
-
assert
|
56
|
+
assert_equal Date.civil(1980,8,22), @date_year_month_day.end
|
57
|
+
assert !@date_year_month_day.exclude_end?
|
58
58
|
|
59
59
|
assert_equal Date.civil(1980, 8, 1), @date_year_month.begin
|
60
|
-
assert_equal Date.civil(1980,
|
61
|
-
assert
|
60
|
+
assert_equal Date.civil(1980, 8, 31), @date_year_month.end
|
61
|
+
assert !@date_year_month.exclude_end?
|
62
62
|
|
63
63
|
assert_equal Date.civil(1980, 1, 1), @date_year.begin
|
64
|
-
assert_equal Date.civil(
|
65
|
-
assert
|
64
|
+
assert_equal Date.civil(1980, 12, 31), @date_year.end, @date_year.end.to_s
|
65
|
+
assert !@date_year.exclude_end?
|
66
66
|
end
|
67
|
+
|
68
|
+
def test_eql
|
69
|
+
assert @date_year.eql?(@date_year)
|
70
|
+
assert @date_year_month.eql?(Date.civil(1980, 8, 1)..Date.civil(1980, 8, 31))
|
71
|
+
assert @date_year_month_day.eql?(Date.civil(1980, 8, 22))
|
72
|
+
assert !@date_year.eql?(@date_year_month_day)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_include
|
76
|
+
assert @date_year.include?(@date_year)
|
77
|
+
assert @date_year.include?(@date_year_month)
|
78
|
+
assert @date_year.include?(@date_year_month_day)
|
79
|
+
assert @date_year_month.include?(Date.civil(1980, 8, 1))
|
80
|
+
assert @date_year_month.include?(Date.civil(1980, 8, 22))
|
81
|
+
assert @date_year_month.include?(Date.civil(1980, 8, 31))
|
82
|
+
assert @date_year_month.include?(Date.civil(1980, 8, 1)..Date.civil(1980, 8, 31))
|
83
|
+
assert !@date_year_month.include?(Date.civil(1980, 8, 1)..Date.civil(1980, 9, 1))
|
84
|
+
assert !@date_year_month.include?(Date.civil(1980, 7, 30))
|
85
|
+
assert !@date_year_month.include?(Date.civil(1980, 9, 1))
|
86
|
+
end
|
87
|
+
|
67
88
|
end
|
data/test/test_mbxml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_mbxml.rb
|
1
|
+
# $Id: test_mbxml.rb 152 2007-07-24 08:47:28Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -31,10 +31,10 @@ class TestMBXML < Test::Unit::TestCase
|
|
31
31
|
assert_equal nil, mbxml.get_entity(:release)
|
32
32
|
assert_equal nil, mbxml.get_entity(:track)
|
33
33
|
assert_equal nil, mbxml.get_entity(:label)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
assert mbxml.get_entity_list(:artist).empty?
|
35
|
+
assert mbxml.get_entity_list(:release).empty?
|
36
|
+
assert mbxml.get_entity_list(:track).empty?
|
37
|
+
assert mbxml.get_entity_list(:label).empty?
|
38
38
|
|
39
39
|
# The second contains an empty artist list
|
40
40
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/empty_2.xml')
|
@@ -43,9 +43,9 @@ class TestMBXML < Test::Unit::TestCase
|
|
43
43
|
assert_equal nil, mbxml.get_entity(:track)
|
44
44
|
assert_equal nil, mbxml.get_entity(:label)
|
45
45
|
assert mbxml.get_entity_list(:artist).empty?
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
assert mbxml.get_entity_list(:release).empty?
|
47
|
+
assert mbxml.get_entity_list(:track).empty?
|
48
|
+
assert mbxml.get_entity_list(:label).empty?
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_artist_search
|
data/test/test_range_equality.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_range_equality.rb
|
1
|
+
# $Id: test_range_equality.rb 154 2007-07-24 12:39:02Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Nigel Graham (mailto:nigel_graham@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -70,7 +70,6 @@ class TestRangeEquality < Test::Unit::TestCase
|
|
70
70
|
OPERATIONS = [
|
71
71
|
:before?,
|
72
72
|
:after?,
|
73
|
-
:eql?,
|
74
73
|
:meets_beginning_of?,
|
75
74
|
:meets_end_of?,
|
76
75
|
:overlaps_beginning_of?,
|
@@ -132,13 +131,13 @@ class TestRangeEquality < Test::Unit::TestCase
|
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
def test_include
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
134
|
+
#def test_include
|
135
|
+
# TESTSET.each do |a,b,op|
|
136
|
+
# if op == :started_by? || op == :contains? || op == :eql? || op == :finished_by?
|
137
|
+
# assert a.include?(b), a.inspect + ".include? " + b.inspect
|
138
|
+
# else
|
139
|
+
# assert !a.include?(b), '!' + a.inspect + ".include? " + b.inspect + ''
|
140
|
+
# end
|
141
|
+
# end
|
142
|
+
#end
|
144
143
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbrainz
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.2.1
|
7
|
+
date: 2007-07-24 00:00:00 +02:00
|
8
8
|
summary: Ruby library for the MusicBrainz XML web service.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -39,6 +39,12 @@ files:
|
|
39
39
|
- examples/getuser.rb
|
40
40
|
- examples/searchartists.rb
|
41
41
|
- examples/getartist.rb
|
42
|
+
- examples/searchtracks.rb
|
43
|
+
- examples/getlabel.rb
|
44
|
+
- examples/getrelease.rb
|
45
|
+
- examples/gettrack.rb
|
46
|
+
- examples/searchlabels.rb
|
47
|
+
- examples/searchreleases.rb
|
42
48
|
- lib/rbrainz.rb
|
43
49
|
- lib/rbrainz/webservice.rb
|
44
50
|
- lib/rbrainz/model.rb
|