metallum 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/CHANGELOG +15 -0
- data/Gemfile +16 -0
- data/Guardfile +6 -0
- data/Rakefile +24 -0
- data/lib/metallum/album.rb +54 -0
- data/lib/metallum/band.rb +62 -0
- data/lib/metallum/metallum.rb +27 -0
- data/lib/metallum/version.rb +3 -0
- data/lib/metallum.rb +7 -0
- data/metallum.gemspec +20 -0
- data/spec/metallum/album_spec.rb +45 -0
- data/spec/metallum/band_spec.rb +64 -0
- data/spec/metallum/metallum_spec.rb +7 -0
- data/spec/spec_helper.rb +13 -0
- metadata +73 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format nested
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2
|
data/CHANGELOG
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
09.09.2011
|
2
|
+
----------
|
3
|
+
Peco Danajlovski <vortexmk@gmail.com>
|
4
|
+
* Started this CHANGELOG
|
5
|
+
* Introduced guard for automatic testing
|
6
|
+
* Implemented fetching basic band info
|
7
|
+
* Version bump to 0.1.0
|
8
|
+
|
9
|
+
10.09.2011
|
10
|
+
----------
|
11
|
+
Peco Danajlovski <vortexmk@gmail.com>
|
12
|
+
* Implemented fetching of all album urls from band's discography
|
13
|
+
* Refactored the classes into separate files
|
14
|
+
* Implemented fetching basic info for albums
|
15
|
+
* Version bump to 0.2.0
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'mechanize'
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem "rspec", "~> 2.6.0"
|
7
|
+
gem "bundler"
|
8
|
+
gem "jeweler"
|
9
|
+
gem "guard"
|
10
|
+
gem "guard-rspec"
|
11
|
+
gem "rb-inotify"
|
12
|
+
gem "libnotify"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Specify your gem's dependencies in metallum.gemspec
|
16
|
+
gemspec
|
data/Guardfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
10
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
11
|
+
spec.rcov = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
15
|
+
|
16
|
+
require 'rdoc/task'
|
17
|
+
Rake::RDocTask.new do |rdoc|
|
18
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
19
|
+
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = "metal-archives #{version}"
|
22
|
+
rdoc.rdoc_files.include('README*')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Album
|
2
|
+
|
3
|
+
def initialize(album_page)
|
4
|
+
@page = album_page
|
5
|
+
end
|
6
|
+
|
7
|
+
def title
|
8
|
+
element = @page.search("//h1[@class='album_name']")
|
9
|
+
element.text
|
10
|
+
end
|
11
|
+
|
12
|
+
def band_name
|
13
|
+
element = @page.search("//h2[@class='band_name']")
|
14
|
+
element.text
|
15
|
+
end
|
16
|
+
|
17
|
+
def album_type
|
18
|
+
element = @page.search("//div[@id='album_info']//dl[1]//dd[1]")
|
19
|
+
element.text
|
20
|
+
end
|
21
|
+
|
22
|
+
def release_date
|
23
|
+
element = @page.search("//div[@id='album_info']//dl[1]//dd[2]")
|
24
|
+
element.text
|
25
|
+
end
|
26
|
+
|
27
|
+
def record_label
|
28
|
+
element = @page.search("//div[@id='album_info']//dl[2]//dd[1]")
|
29
|
+
element.text
|
30
|
+
end
|
31
|
+
|
32
|
+
def track_list
|
33
|
+
tracks = []
|
34
|
+
elements = @page.search("//div[@id='album_tabs_tracklist']//table//tbody//tr[@class='odd' or @class='even']")
|
35
|
+
elements.each do |element|
|
36
|
+
track = Track.new
|
37
|
+
track.title = element.children[2].text.strip
|
38
|
+
track.duration = element.children[4].text.strip
|
39
|
+
tracks << track
|
40
|
+
end
|
41
|
+
return tracks
|
42
|
+
end
|
43
|
+
|
44
|
+
class Track
|
45
|
+
|
46
|
+
attr_accessor :title, :duration
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
@duration = "0:00"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Band
|
2
|
+
|
3
|
+
def initialize(band_page, discography_page)
|
4
|
+
@page = band_page
|
5
|
+
@discography = discography_page
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
element = @page.search("h1[@class='band_name']")
|
10
|
+
element.text.strip!
|
11
|
+
end
|
12
|
+
|
13
|
+
def country
|
14
|
+
element = @page.search("//div[@id='band_info']//dl//dd[1]//a")
|
15
|
+
element.children[0].text
|
16
|
+
end
|
17
|
+
|
18
|
+
def location
|
19
|
+
element = @page.search("//div[@id='band_info']//dl[1]//dd[2]")
|
20
|
+
element.text
|
21
|
+
end
|
22
|
+
|
23
|
+
def status
|
24
|
+
element = @page.search("//div[@id='band_info']//dl[1]//dd[3]")
|
25
|
+
element.text
|
26
|
+
end
|
27
|
+
|
28
|
+
def year_formed
|
29
|
+
element = @page.search("//div[@id='band_info']//dl//dd[4]")
|
30
|
+
element.text
|
31
|
+
end
|
32
|
+
|
33
|
+
def genre
|
34
|
+
element = @page.search("//div[@id='band_info']//dl[2]//dd[1]")
|
35
|
+
element.text
|
36
|
+
end
|
37
|
+
|
38
|
+
def lyrical_themes
|
39
|
+
element = @page.search("//div[@id='band_info']//dl[2]//dd[2]")
|
40
|
+
element.text
|
41
|
+
end
|
42
|
+
|
43
|
+
def record_label
|
44
|
+
element = @page.search("//div[@id='band_info']//dl[2]//dd[3]")
|
45
|
+
element.text
|
46
|
+
end
|
47
|
+
|
48
|
+
def photo_url
|
49
|
+
element = @page.search("//a[@id='photo']//img")
|
50
|
+
element.attribute("src").text
|
51
|
+
end
|
52
|
+
|
53
|
+
def logo_url
|
54
|
+
element = @page.search("//a[@id='logo']//img")
|
55
|
+
element.attribute("src").text
|
56
|
+
end
|
57
|
+
|
58
|
+
def album_urls
|
59
|
+
elements = @discography.search("//tbody//tr//td[1]/a").map { |el| el.attribute("href").text }
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Metallum
|
2
|
+
|
3
|
+
# DISCOGRAPHY_URL = "http://www.metal-archives.com/band/discography/id/3/tab/all"
|
4
|
+
|
5
|
+
class Agent
|
6
|
+
|
7
|
+
def initialize(url)
|
8
|
+
@agent = Mechanize.new
|
9
|
+
@page = @agent.get(url)
|
10
|
+
@discography = @agent.get("http://www.metal-archives.com/band/discography/id/#{extract_band_id}/tab/all")
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch_band
|
14
|
+
band = Band.new(@page, @discography)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_album
|
18
|
+
album = Album.new(@page)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extract_band_id
|
22
|
+
@page.uri.to_s.match(/\/(\d+)/)[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/metallum.rb
ADDED
data/metallum.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "metallum/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "metallum"
|
7
|
+
s.version = Metallum::VERSION
|
8
|
+
s.authors = ["Peco Danajlovski"]
|
9
|
+
s.email = ["vortexmk@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Metallum is a simple gem that fetches various data from metal-archives.com}
|
12
|
+
s.description = %q{Metallum is a simple gem that fetches various data from metal-archives.com}
|
13
|
+
|
14
|
+
s.rubyforge_project = "metallum"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Album" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@album_url = "http://www.metal-archives.com/albums/Dream_Theater/A_Dramatic_Turn_of_Events/309671"
|
7
|
+
@agent = Metallum::Agent.new(@album_url)
|
8
|
+
@album = @agent.fetch_album
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should fetch the title of the album" do
|
12
|
+
@album.title.should == "A Dramatic Turn of Events"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should fetch the name of the band" do
|
16
|
+
@album.band_name.should == "Dream Theater"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should fetch the type of the album" do
|
20
|
+
@album.album_type.should == "Full-length"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fetch the release date" do
|
24
|
+
@album.release_date.should == "September 13th, 2011"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fetch the record label" do
|
28
|
+
@album.record_label.should == "Roadrunner Records"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should fetch track list" do
|
32
|
+
@album.track_list.size == 9
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fetch track titles" do
|
36
|
+
@album.track_list[0].title.should == "On the Backs of Angels"
|
37
|
+
@album.track_list[8].title.should == "Beneath the Surface"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should fetch the track length" do
|
41
|
+
@album.track_list[3].duration.should == "06:57"
|
42
|
+
@album.track_list[6].duration.should == "03:56"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Band" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@band_url = 'http://www.metal-archives.com/bands/Blind_Guardian/3'
|
7
|
+
@agent = Metallum::Agent.new(@band_url)
|
8
|
+
@band = @agent.fetch_band
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should fetch a band's name from url for band 'Hell'" do
|
12
|
+
@band_url = 'http://www.metal-archives.com/bands/Hell/5849'
|
13
|
+
@agent = Metallum::Agent.new(@band_url)
|
14
|
+
band = @agent.fetch_band
|
15
|
+
band.name.should == "Hell"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should fetch the band's name from url for band 'Blind Guardian'" do
|
19
|
+
@band.name.should == "Blind Guardian"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should fetch the band's country of origin" do
|
23
|
+
@band.country.should == "Germany"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fetch the band's location" do
|
27
|
+
@band.location.should == "Krefeld, North Rhine-Westphalia"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should fetch band's status" do
|
31
|
+
@band.status.should == "Active"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should fetch the band's year of creation" do
|
35
|
+
@band.year_formed.should == "1986"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fetch the band's genre" do
|
39
|
+
@band.genre.should == "Speed Metal (early), Power Metal (Later)"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should fetch band's lyrical themes" do
|
43
|
+
@band.lyrical_themes.should == "Epic Tales, Legends, Fantasy, Tolkien, Literature"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should fetch band's record label" do
|
47
|
+
@band.record_label.should == "Nuclear Blast Records"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should fetch band's photo url" do
|
51
|
+
@band.photo_url.should == "http://www.metal-archives.com/images/3/3_photo.jpg"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should fetch band's logo url" do
|
55
|
+
@band.logo_url.should == "http://www.metal-archives.com/images/3/3_logo.gif"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should fetch array of album urls" do
|
59
|
+
@band.album_urls[0] = "http://www.metal-archives.com/albums/Blind_Guardian/Battalions_of_Fear/9"
|
60
|
+
@band.album_urls[3] = "http://www.metal-archives.com/albums/Blind_Guardian/Follow_the_Blind/10"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'metallum'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
# require 'spec_helper'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metallum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peco Danajlovski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-10 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Metallum is a simple gem that fetches various data from metal-archives.com
|
18
|
+
email:
|
19
|
+
- vortexmk@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- .rspec
|
29
|
+
- .rvmrc
|
30
|
+
- CHANGELOG
|
31
|
+
- Gemfile
|
32
|
+
- Guardfile
|
33
|
+
- Rakefile
|
34
|
+
- lib/metallum.rb
|
35
|
+
- lib/metallum/album.rb
|
36
|
+
- lib/metallum/band.rb
|
37
|
+
- lib/metallum/metallum.rb
|
38
|
+
- lib/metallum/version.rb
|
39
|
+
- metallum.gemspec
|
40
|
+
- spec/metallum/album_spec.rb
|
41
|
+
- spec/metallum/band_spec.rb
|
42
|
+
- spec/metallum/metallum_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: ""
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: metallum
|
68
|
+
rubygems_version: 1.6.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Metallum is a simple gem that fetches various data from metal-archives.com
|
72
|
+
test_files: []
|
73
|
+
|