metal_archives 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +7 -0
- data/README.md +1 -1
- data/lib/metal_archives.rb +3 -1
- data/lib/metal_archives/models/artist.rb +16 -13
- data/lib/metal_archives/models/band.rb +15 -10
- data/lib/metal_archives/utils/collection.rb +37 -0
- data/lib/metal_archives/{models → utils}/range.rb +0 -0
- data/lib/metal_archives/version.rb +1 -1
- data/test/property/artist_property_test.rb +2 -2
- data/test/query/artist_query_test.rb +10 -7
- data/test/query/band_query_test.rb +26 -25
- data/test/utils/collection_test.rb +51 -0
- data/test/{range_test.rb → utils/range_test.rb} +3 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c629e0d26e84fff55b4c57c2423e8f46c95547
|
4
|
+
data.tar.gz: 200e49292fd001e2b035f105c5f518323f7659e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a2443f5b2f8bcdc4dd5d7f8cc96648b1182225d9ba2e27289fb4782fb5b8cbd283ee8995e3b50cb1dbc1c76e7a67edddffb92d8fda8f5d703d03a4dd4a16426
|
7
|
+
data.tar.gz: b824e554a0deac921487b096c93227989d9d1a440969114b6b2cf5fc35acbe7f831d4b7fbed2a8316d18b8e50d4ab298bd54931df1b21b847eaaec12e0052ef7
|
data/LICENSE
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2016 Florian Dejonckheere
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
data/lib/metal_archives.rb
CHANGED
@@ -2,8 +2,10 @@ require 'metal_archives/version'
|
|
2
2
|
require 'metal_archives/configuration'
|
3
3
|
require 'metal_archives/error'
|
4
4
|
|
5
|
+
require 'metal_archives/utils/range'
|
6
|
+
require 'metal_archives/utils/collection'
|
7
|
+
|
5
8
|
require 'metal_archives/models/base_model'
|
6
|
-
require 'metal_archives/models/range'
|
7
9
|
require 'metal_archives/models/label'
|
8
10
|
require 'metal_archives/models/artist'
|
9
11
|
require 'metal_archives/models/band'
|
@@ -178,38 +178,41 @@ module MetalArchives
|
|
178
178
|
##
|
179
179
|
# Search by name
|
180
180
|
#
|
181
|
-
# Returns
|
181
|
+
# Returns rdoc-ref:Collection of rdoc-ref:Artist
|
182
182
|
#
|
183
183
|
# [+name+]
|
184
184
|
# +String+
|
185
185
|
#
|
186
186
|
def search(name)
|
187
|
-
objects = []
|
188
|
-
|
189
187
|
url = 'http://www.metal-archives.com/search/ajax-artist-search/'
|
190
|
-
query = {
|
191
|
-
|
192
|
-
|
193
|
-
}
|
188
|
+
query = { :name => name }
|
189
|
+
|
190
|
+
params = Parsers::Artist.map_params query
|
194
191
|
|
195
|
-
|
196
|
-
|
192
|
+
l = lambda do
|
193
|
+
@start ||= 0
|
197
194
|
|
198
|
-
|
195
|
+
return [] if instance_variable_defined?('@max_items') and @start >= @max_items
|
196
|
+
|
197
|
+
response = HTTPClient.get url, params.merge(:iDisplayStart => @start)
|
199
198
|
json = JSON.parse response.body
|
200
199
|
|
200
|
+
@max_items = json['iTotalRecords']
|
201
|
+
|
202
|
+
objects = []
|
203
|
+
|
201
204
|
json['aaData'].each do |data|
|
202
205
|
# Create Artist object for every ID in the results list
|
203
206
|
id = Nokogiri::HTML(data.first).xpath('//a/@href').first.value.gsub('\\', '').split('/').last.gsub(/\D/, '').to_i
|
204
207
|
objects << Artist.new(:id => id)
|
205
208
|
end
|
206
209
|
|
207
|
-
|
210
|
+
@start += 200
|
208
211
|
|
209
|
-
|
212
|
+
objects
|
210
213
|
end
|
211
214
|
|
212
|
-
|
215
|
+
MetalArchives::Collection.new l
|
213
216
|
end
|
214
217
|
end
|
215
218
|
end
|
@@ -231,7 +231,7 @@ module MetalArchives
|
|
231
231
|
#
|
232
232
|
# Refer to {MA's FAQ}[http://www.metal-archives.com/content/help?index=3#tab_db] for search tips.
|
233
233
|
#
|
234
|
-
# Returns
|
234
|
+
# Returns rdoc-ref:Collection of rdoc-ref:Band
|
235
235
|
#
|
236
236
|
# [+query+]
|
237
237
|
# Hash containing one or more of the following keys:
|
@@ -248,29 +248,34 @@ module MetalArchives
|
|
248
248
|
# - +:independent+: boolean
|
249
249
|
#
|
250
250
|
def search_by(query)
|
251
|
-
objects = []
|
252
|
-
|
253
251
|
url = 'http://www.metal-archives.com/search/ajax-advanced/searching/bands/'
|
254
|
-
query[:iDisplayStart] = 0
|
255
252
|
|
256
|
-
|
257
|
-
|
253
|
+
params = Parsers::Band.map_params query
|
254
|
+
|
255
|
+
l = lambda do
|
256
|
+
@start ||= 0
|
258
257
|
|
259
|
-
|
258
|
+
return [] if instance_variable_defined?('@max_items') and @start >= @max_items
|
259
|
+
|
260
|
+
response = HTTPClient.get url, params.merge(:iDisplayStart => @start)
|
260
261
|
json = JSON.parse response.body
|
261
262
|
|
263
|
+
@max_items = json['iTotalRecords']
|
264
|
+
|
265
|
+
objects = []
|
266
|
+
|
262
267
|
json['aaData'].each do |data|
|
263
268
|
# Create Band object for every ID in the results list
|
264
269
|
id = Nokogiri::HTML(data.first).xpath('//a/@href').first.value.gsub('\\', '').split('/').last.gsub(/\D/, '').to_i
|
265
270
|
objects << Band.new(:id => id)
|
266
271
|
end
|
267
272
|
|
268
|
-
|
273
|
+
@start += 200
|
269
274
|
|
270
|
-
|
275
|
+
objects
|
271
276
|
end
|
272
277
|
|
273
|
-
|
278
|
+
MetalArchives::Collection.new l
|
274
279
|
end
|
275
280
|
|
276
281
|
##
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MetalArchives
|
2
|
+
##
|
3
|
+
# Enumerable collection over a paginated resource
|
4
|
+
#
|
5
|
+
class Collection
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
##
|
9
|
+
# Construct a new Collection
|
10
|
+
#
|
11
|
+
# [+proc+]
|
12
|
+
# +Proc+ or +lambda+, called repeatedly when iterating. Should return an array of results (stateful),
|
13
|
+
# should return an empty array when there are no results left.
|
14
|
+
#
|
15
|
+
def initialize(proc)
|
16
|
+
@proc = proc
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Calls the given block once for each element, passing that element as a parameter.
|
21
|
+
# If no block is given, an Enumerator is returned.
|
22
|
+
#
|
23
|
+
def each(&block)
|
24
|
+
return to_enum :each unless block_given?
|
25
|
+
|
26
|
+
loop do
|
27
|
+
items = instance_exec(&@proc)
|
28
|
+
|
29
|
+
items.each do |item|
|
30
|
+
yield item
|
31
|
+
end
|
32
|
+
|
33
|
+
break if items.empty?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
@@ -12,7 +12,7 @@ class ArtistPropertyTest < Test::Unit::TestCase
|
|
12
12
|
def test_basic_attributes
|
13
13
|
artist = MetalArchives::Artist.find 60908
|
14
14
|
|
15
|
-
|
15
|
+
assert_instance_of MetalArchives::Artist, artist
|
16
16
|
assert_equal 60908, artist.id
|
17
17
|
assert_equal 'Alberto Rionda', artist.name
|
18
18
|
assert_empty artist.aliases
|
@@ -25,7 +25,7 @@ class ArtistPropertyTest < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
artist = MetalArchives::Artist.find 260
|
27
27
|
|
28
|
-
|
28
|
+
assert_instance_of MetalArchives::Artist, artist
|
29
29
|
assert_equal 'Ian Fraser Kilmister', artist.name
|
30
30
|
assert_equal ['Lemmy Kilmister'], artist.aliases
|
31
31
|
assert_equal Date.new(2015, 12, 28), artist.date_of_death
|
@@ -11,20 +11,20 @@ class ArtistQueryTest < Test::Unit::TestCase
|
|
11
11
|
artist = MetalArchives::Artist.find 60908
|
12
12
|
|
13
13
|
assert_not_nil artist
|
14
|
-
|
14
|
+
assert_instance_of MetalArchives::Artist, artist
|
15
15
|
assert_equal 'Alberto Rionda', artist.name
|
16
16
|
assert_equal ISO3166::Country['ES'], artist.country
|
17
17
|
|
18
18
|
artist = MetalArchives::Artist.find(999999)
|
19
19
|
|
20
|
-
|
20
|
+
assert_instance_of MetalArchives::Artist, artist
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_find_by
|
24
24
|
artist = MetalArchives::Artist.find_by :name => 'Alberto Rionda'
|
25
25
|
|
26
26
|
assert_not_nil artist
|
27
|
-
|
27
|
+
assert_instance_of MetalArchives::Artist, artist
|
28
28
|
assert_equal 'Alberto Rionda', artist.name
|
29
29
|
assert_equal 60908, artist.id
|
30
30
|
assert_equal ISO3166::Country['ES'], artist.country
|
@@ -36,9 +36,12 @@ class ArtistQueryTest < Test::Unit::TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_search
|
39
|
-
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
39
|
+
assert_instance_of MetalArchives::Collection, MetalArchives::Artist.search('Alberto Rionda')
|
40
|
+
assert_equal 1, MetalArchives::Artist.search('Alberto Rionda').count
|
41
|
+
assert_equal 9, MetalArchives::Artist.search('Name').count
|
42
|
+
assert_equal 0, MetalArchives::Artist.search('SomeNonExistantName').count
|
43
|
+
assert_equal 293, MetalArchives::Artist.search('Filip').count
|
44
|
+
|
45
|
+
assert !MetalArchives::Artist.search('SomeNonExistantName').any?
|
43
46
|
end
|
44
47
|
end
|
@@ -11,7 +11,7 @@ class BandQueryTest < Test::Unit::TestCase
|
|
11
11
|
band = MetalArchives::Band.find 3540361100
|
12
12
|
|
13
13
|
assert_not_nil band
|
14
|
-
|
14
|
+
assert_instance_of MetalArchives::Band, band
|
15
15
|
assert_equal 'Alquimia', band.name
|
16
16
|
assert_equal ISO3166::Country['ES'], band.country
|
17
17
|
|
@@ -20,14 +20,14 @@ class BandQueryTest < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
band = MetalArchives::Band.find(2)
|
22
22
|
|
23
|
-
|
23
|
+
assert_instance_of MetalArchives::Band, band
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_find_by
|
27
27
|
band = MetalArchives::Band.find_by :name => 'Falconer'
|
28
28
|
|
29
29
|
assert_not_nil band
|
30
|
-
|
30
|
+
assert_instance_of MetalArchives::Band, band
|
31
31
|
assert_equal 'Falconer', band.name
|
32
32
|
assert_equal 74, band.id
|
33
33
|
assert_equal ISO3166::Country['SE'], band.country
|
@@ -41,44 +41,45 @@ class BandQueryTest < Test::Unit::TestCase
|
|
41
41
|
band = MetalArchives::Band.find_by(:name => 'Alquimia', :country => ISO3166::Country['ES'])
|
42
42
|
|
43
43
|
assert_not_nil band
|
44
|
-
|
44
|
+
assert_instance_of MetalArchives::Band, band
|
45
45
|
assert_equal 3540361100, band.id
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_search_by
|
49
|
-
|
49
|
+
assert_instance_of MetalArchives::Collection, MetalArchives::Band.search_by(:name => 'Alquimia')
|
50
50
|
|
51
|
-
assert_equal
|
52
|
-
assert_equal
|
51
|
+
assert_equal 5, MetalArchives::Band.search_by(:name => 'Alquimia').count
|
52
|
+
assert_equal 3, MetalArchives::Band.search_by(:name => 'Lost Horizon').count
|
53
|
+
assert_equal 2, MetalArchives::Band.search_by(:name => 'Lost Horizon', :exact => true).count
|
54
|
+
assert_equal 2, MetalArchives::Band.search_by(:name => 'Alquimia', :genre => 'Melodic Power').count
|
53
55
|
|
54
|
-
assert_equal 2, MetalArchives::Band.search_by(:name => 'Alquimia', :genre => 'Melodic Power').length
|
55
56
|
|
57
|
+
countries = MetalArchives::Band.search('Alquimia').map { |a| a.country }.sort
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
assert countries.include? ISO3166::Country['ES']
|
62
|
-
assert countries.include? ISO3166::Country['CL']
|
59
|
+
assert_equal 5, countries.size
|
60
|
+
assert countries.include? ISO3166::Country['AR']
|
61
|
+
assert countries.include? ISO3166::Country['ES']
|
62
|
+
assert countries.include? ISO3166::Country['CL']
|
63
63
|
|
64
64
|
assert_equal 5, MetalArchives::Band.search_by(
|
65
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, nil)).
|
65
|
+
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, nil)).count
|
66
66
|
assert_equal 1, MetalArchives::Band.search_by(
|
67
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2013), nil)).
|
67
|
+
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2013), nil)).count
|
68
68
|
assert_equal 1, MetalArchives::Band.search_by(
|
69
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2008))).
|
69
|
+
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2008))).count
|
70
70
|
assert_equal 2, MetalArchives::Band.search_by(
|
71
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2013))).
|
71
|
+
:name => 'Alquimia', :year => MetalArchives::Range.new(Date.new(2008), Date.new(2013))).count
|
72
72
|
assert_equal 5, MetalArchives::Band.search_by(
|
73
|
-
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, Date.new(2013))).
|
73
|
+
:name => 'Alquimia', :year => MetalArchives::Range.new(nil, Date.new(2013))).count
|
74
74
|
|
75
|
-
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['ES']).
|
76
|
-
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).
|
77
|
-
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).
|
78
|
-
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :label => 'Mutus Liber').
|
75
|
+
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['ES']).count
|
76
|
+
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count
|
77
|
+
assert_equal 3, MetalArchives::Band.search_by(:name => 'Alquimia', :country => ISO3166::Country['AR']).count
|
78
|
+
assert_equal 1, MetalArchives::Band.search_by(:name => 'Alquimia', :label => 'Mutus Liber').count
|
79
79
|
|
80
|
-
|
80
|
+
assert_equal 0, MetalArchives::Band.search_by(:name => 'SomeNonExistantName').count
|
81
|
+
assert !MetalArchives::Band.search_by(:name => 'SomeNonExistantName').any?
|
81
82
|
|
82
|
-
assert_equal 274, MetalArchives::Band.search_by(:country => ISO3166::Country['CN']).
|
83
|
+
assert_equal 274, MetalArchives::Band.search_by(:country => ISO3166::Country['CN']).count
|
83
84
|
end
|
84
85
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require 'metal_archives/utils/collection'
|
5
|
+
|
6
|
+
class CollectionTest < Test::Unit::TestCase
|
7
|
+
def test_each
|
8
|
+
l = lambda do
|
9
|
+
@i ||= 0
|
10
|
+
|
11
|
+
return [] if @i >= 100
|
12
|
+
items = (@i .. (@i + 9)).to_a
|
13
|
+
@i += 10
|
14
|
+
|
15
|
+
items
|
16
|
+
end
|
17
|
+
|
18
|
+
c = MetalArchives::Collection.new l
|
19
|
+
|
20
|
+
i = 0
|
21
|
+
c.each do |item|
|
22
|
+
assert_equal i, item
|
23
|
+
i += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal 100, i
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_return
|
30
|
+
l = lambda do
|
31
|
+
@i ||= 0
|
32
|
+
|
33
|
+
raise StandardError if @i >= 100
|
34
|
+
items = (@i .. (@i + 9)).to_a
|
35
|
+
@i += 10
|
36
|
+
|
37
|
+
items
|
38
|
+
end
|
39
|
+
|
40
|
+
c = MetalArchives::Collection.new l
|
41
|
+
|
42
|
+
i = 0
|
43
|
+
c.each do |item|
|
44
|
+
break if i == 99
|
45
|
+
assert_equal i, item
|
46
|
+
i += 1
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_equal 99, i
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metal_archives
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Dejonckheere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -231,11 +231,12 @@ files:
|
|
231
231
|
- lib/metal_archives/models/band.rb
|
232
232
|
- lib/metal_archives/models/base_model.rb
|
233
233
|
- lib/metal_archives/models/label.rb
|
234
|
-
- lib/metal_archives/models/range.rb
|
235
234
|
- lib/metal_archives/parsers/artist.rb
|
236
235
|
- lib/metal_archives/parsers/band.rb
|
237
236
|
- lib/metal_archives/parsers/label.rb
|
238
237
|
- lib/metal_archives/parsers/parser_helper.rb
|
238
|
+
- lib/metal_archives/utils/collection.rb
|
239
|
+
- lib/metal_archives/utils/range.rb
|
239
240
|
- lib/metal_archives/version.rb
|
240
241
|
- metal_archives.gemspec
|
241
242
|
- test/base_model_test.rb
|
@@ -245,8 +246,9 @@ files:
|
|
245
246
|
- test/property/band_property_test.rb
|
246
247
|
- test/query/artist_query_test.rb
|
247
248
|
- test/query/band_query_test.rb
|
248
|
-
- test/range_test.rb
|
249
249
|
- test/test_helper.rb
|
250
|
+
- test/utils/collection_test.rb
|
251
|
+
- test/utils/range_test.rb
|
250
252
|
homepage: http://github.com/floriandejonckheere/metal_archives
|
251
253
|
licenses:
|
252
254
|
- MIT
|