lyrics_finder 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f70dded864457e2a80c33935c7b326d6b32ceea5
4
- data.tar.gz: 150db6b0129ba6fd9be49e6b7d4110c11ecdbb92
3
+ metadata.gz: 1fd7f1561cd6aab7ec434dce2d19a19793e9d6b5
4
+ data.tar.gz: b9c349442db37814b8e827089eb1a8e842852ec3
5
5
  SHA512:
6
- metadata.gz: 4a198fd83d1c9a18de001fd5344f120f930ae999ad04a06617e9be7637dd33c82651d2ece946a67af9097db6e56314a36cc9f8dbb40fafb3d6495fa25a0e38a4
7
- data.tar.gz: 44dd8c307da980447bd685fe6e2a08e21e6973b9d4c84ac41ab3bea54b390acf01c76847c37921ec585b690ced5e848f51460d6de6d1841d5d45f09c010c7c28
6
+ metadata.gz: 01636770bfde8f4d80a00520dde2bd392f0936f4a12c86ff40c670031199b4904a5b5b74be3a7e8df581f0e9c35fb3a354a21965d88618ad8ea577d0b30bf895
7
+ data.tar.gz: e07ebd64b84a8c6fa0692b350960d3ebd8d1dff124c64af08c58c3028c6c9ef13750be5cbd95fcbb6a9dd895fe95a6f4f136703a31fc131d9722f25f661aaf16
data/README.md CHANGED
@@ -18,48 +18,21 @@ Or install it yourself as:
18
18
 
19
19
  ## Hello World!
20
20
 
21
- Create an instance of `Lyrics::Finder`:
21
+ Search passing the author and the song title as parameters to `LyricsFinder.search`:
22
22
 
23
23
  ```ruby
24
- finder = Lyrics::Finder.new
25
- ```
26
-
27
- And search passing the author and the song title as parameters to `Lyrics::Finder#search`:
28
-
29
- ```ruby
30
- finder.search 'idina menzel', 'let it go'
24
+ LyricsFinder.search 'idina menzel', 'let it go'
31
25
  ```
32
26
  Which will return and array with all the verses of the song as strings, or `nil` if the song cannot be found.
33
27
 
34
- ### Customizing the search
35
-
36
- You can specify which websites do you want to get the lyrics from (all by default):
37
-
38
- ```ruby
39
- finder = Lyrics::Finder.new(:song_lyrics, :azlyrics)
40
- ```
41
-
42
- You can choose among the following:
43
-
44
- - LyricsWikia (`:lyrics_wikia`)
45
- - SongLyrics (`:song_lyrics`)
46
- - AZLyrics (`:azlyrics`)
47
- - LyricsMania (`:lyrics_mania`)
48
-
49
- You can see the websites you are using as lyrics providers with:
50
-
51
- ```ruby
52
- Finder.selected_providers
53
- ```
54
-
55
28
  ## Example
56
29
 
57
30
  In your ruby apps:
58
31
  ```ruby
59
32
  require 'lyrics_finder'
60
33
 
61
- finder = Lyrics::Finder.new
62
- @song = finder.search 'idina menzel', 'let it go'
34
+ @song = LyricsFinder.search 'idina menzel', 'let it go'
35
+
63
36
  puts @song
64
37
  ```
65
38
 
@@ -69,34 +42,10 @@ LyricsFinder is also available as a command-line tool.
69
42
 
70
43
  $ lyricsfinder search -a 'idina menzel' -t 'let it go'
71
44
 
72
- ## Changelog
73
-
74
- v 0.0.4
75
-
76
- - Added lyrics mania as a valid website to get your lyrics from.
77
-
78
- v 0.0.3
79
-
80
- - Wrapped everything into a `Lyrics` module.
81
-
82
- v 0.0.2
83
-
84
- - Changed the app interface `LyricsFinder::Fetcher` is now `Finder`.
85
- - Now using [Contracts](https://github.com/egonSchiele/contracts.ruby).
86
- - Simplified providers code.
87
-
88
- v 0.0.1
89
-
90
- - Initial release.
91
-
92
45
  ## Contributing
93
46
 
94
47
  1. Fork it ( https://github.com/[my-github-username]/lyrics_finder/fork )
95
48
  2. Create your feature branch (`git checkout -b my-new-feature`)
96
49
  3. Commit your changes (`git commit -am 'Add some feature'`)
97
50
  4. Push to the branch (`git push origin my-new-feature`)
98
- 5. Create a new Pull Request
99
-
100
- ## Credits
101
-
102
- Inspired by [Lyricfy](https://github.com/javichito/Lyricfy).
51
+ 5. Create a new Pull Request
data/lib/lyrics_finder.rb CHANGED
@@ -1,45 +1,29 @@
1
1
  require_relative 'lyrics_finder/dependencies'
2
2
 
3
- module Lyrics
4
- class Finder
5
- include Contracts
3
+ module LyricsFinder
4
+ include Contracts
6
5
 
7
- def initialize(*args)
8
- @providers = Providers.filter_providers(args)
9
- end
10
-
11
- def selected_providers
12
- @providers
13
- end
14
-
15
- Contract String, String => Or[Array, nil]
16
- def search(author, title)
17
- song = set_song(author, title)
18
- song_lyric = catch(:song_lyric) {
19
- @providers.each do |provider|
20
- klass = Providers.build_klass(provider)
21
- url = klass.format_url(song)
22
- data = perform_request(url)
23
- result = klass.extract_lyric(data) if data
24
- throw :song_lyric, result unless result.nil?
25
- end
26
- throw :song_lyric, nil # because song cannot be found.
27
- }
28
- end
29
-
30
- private
31
-
32
- Contract String, String => Lyrics::Song
33
- def set_song(author, title)
34
- Song.new(author, title)
35
- end
36
-
37
- def perform_request(url)
38
- begin
39
- open(url)
40
- rescue Exception => ex
41
- # puts "ERROR: " + ex.message
6
+ Contract String, String => Or[Array, nil]
7
+ def self.search(author, title)
8
+ song = Song.new(author, title)
9
+ song_lyric = catch(:song_lyric) {
10
+ Providers.list.each do |provider|
11
+ klass = Providers.build_klass(provider)
12
+ url = klass.format_url(song)
13
+ data = perform_request(url)
14
+ result = klass.extract_lyric(data) if data
15
+ throw :song_lyric, result unless result.nil?
42
16
  end
17
+ throw :song_lyric, nil # because song cannot be found.
18
+ }
19
+ end
20
+
21
+ def self.perform_request(url)
22
+ begin
23
+ open(url)
24
+ rescue Exception => ex
25
+ # puts "ERROR: " + ex.message
43
26
  end
44
27
  end
28
+
45
29
  end
@@ -7,8 +7,7 @@ module Lyrics
7
7
  method_option 'author', :aliases => '-a', :type => :string
8
8
  method_option 'title', :aliases => '-t', :type => :string
9
9
  def search
10
- finder = Lyrics::Finder.new
11
- puts finder.search(options[:author], options[:title])
10
+ puts LyricsFinder.search(options[:author], options[:title])
12
11
  end
13
12
  end
14
13
  end
@@ -6,8 +6,5 @@ I18n.enforce_available_locales = false
6
6
  require 'contracts'
7
7
 
8
8
  require_relative 'version'
9
- require_relative 'providers'
10
- require_relative 'providers/lyrics_wikia'
11
- require_relative 'providers/azlyrics'
12
- require_relative 'providers/song_lyrics'
13
- require_relative 'providers/lyrics_mania'
9
+ require_relative 'song'
10
+ require_relative 'providers'
@@ -1,32 +1,71 @@
1
- require_relative 'song'
1
+ module LyricsFinder::Providers
2
+ include Contracts
2
3
 
3
- module Lyrics
4
- module Providers
5
- include Contracts
4
+ def self.list
5
+ [:lyrics_wikia, :lyrics_mania, :song_lyrics, :azlyrics]
6
+ end
7
+
8
+ Contract Symbol => Module
9
+ def self.build_klass(provider)
10
+ klass = "LyricsFinder::Providers::" + provider.to_s.camelize
11
+ klass.constantize
12
+ end
13
+
14
+ Contract String, Tempfile => Or[Array, nil]
15
+ def self.extract_lyrics_at_css_from_data(css_element, data)
16
+ html = Nokogiri::HTML(data)
17
+ lyrics_container = html.css(css_element).first
18
+ unless lyrics_container.nil?
19
+ elements = lyrics_container.children.to_a
20
+ phrases = elements.select { |el| el.text? && el.text != "\n" && !el.blank? }
21
+ phrases.map! { |element| element.text.strip }
22
+ end
23
+ end
24
+
25
+ # Providers Modules
6
26
 
7
- def self.providers_list
8
- [:lyrics_wikia, :lyrics_mania, :song_lyrics, :azlyrics]
27
+ module LyricsWikia
28
+ def self.format_url(song)
29
+ song.format_attributes_with_separator!("_")
30
+ "http://lyrics.wikia.com/#{song.author}:#{song.title}"
9
31
  end
10
32
 
11
- def self.filter_providers(providers)
12
- valid_providers = providers.select { |p| providers_list.include?(p) }
13
- valid_providers.any? ? valid_providers : providers_list
33
+ def self.extract_lyric(data)
34
+ LyricsFinder::Providers.extract_lyrics_at_css_from_data('.lyricbox', data)
14
35
  end
36
+ end
15
37
 
16
- Contract Symbol => Module
17
- def self.build_klass(provider)
18
- klass = "Lyrics::Providers::" + provider.to_s.camelize
19
- klass.constantize
38
+ module LyricsMania
39
+ def self.format_url(song)
40
+ song.format_attributes_with_separator!("_")
41
+ "http://www.lyricsmania.com/#{song.title}_lyrics_#{song.author}.html"
20
42
  end
21
43
 
22
- def self.extract_lyrics_at_css_from_data(css_element, data)
23
- html = Nokogiri::HTML(data)
24
- lyrics_container = html.css(css_element).first
25
- unless lyrics_container.nil?
26
- elements = lyrics_container.children.to_a
27
- phrases = elements.select { |el| el.text? && el.text != "\n" && !el.blank? }
28
- phrases.map! { |element| element.text.strip }
29
- end
44
+ def self.extract_lyric(data)
45
+ LyricsFinder::Providers.extract_lyrics_at_css_from_data('.lyrics-body', data)
30
46
  end
31
47
  end
48
+
49
+ module SongLyrics
50
+ def self.format_url(song)
51
+ song.format_attributes_with_separator!("-")
52
+ "http://www.songlyrics.com/#{song.author}/#{song.title}-lyrics/"
53
+ end
54
+
55
+ def self.extract_lyric(data)
56
+ LyricsFinder::Providers.extract_lyrics_at_css_from_data('#songLyricsDiv', data)
57
+ end
58
+ end
59
+
60
+ module Azlyrics
61
+ def self.format_url(song)
62
+ song.format_attributes_with_separator!("")
63
+ "http://www.azlyrics.com/lyrics/#{song.author}/#{song.title}.html"
64
+ end
65
+
66
+ def self.extract_lyric(data)
67
+ LyricsFinder::Providers.extract_lyrics_at_css_from_data('div:nth-child(7)', data)
68
+ end
69
+ end
70
+
32
71
  end
@@ -1,23 +1,13 @@
1
- module Lyrics
2
- class Song
3
- attr_accessor :author, :title
1
+ class Song
2
+ attr_accessor :author, :title
4
3
 
5
- def initialize(author, title)
6
- @author = author
7
- @title = title
8
- end
9
-
10
- def self.valid?(val)
11
- val.is_a?(Song) && !val.author.blank? && !val.title.blank?
12
- end
13
-
14
- def self.to_s
15
- "a valid author and song title please"
16
- end
4
+ def initialize(author, title)
5
+ @author = author
6
+ @title = title
7
+ end
17
8
 
18
- def format_attributes_with_separator!(separator)
19
- self.author = I18n.transliterate(@author.strip.gsub(" ", separator))
20
- self.title = I18n.transliterate(@title.strip.gsub(" ", separator))
21
- end
9
+ def format_attributes_with_separator!(separator)
10
+ self.author = I18n.transliterate(@author.strip.gsub(" ", separator))
11
+ self.title = I18n.transliterate(@title.strip.gsub(" ", separator))
22
12
  end
23
13
  end
@@ -1,3 +1,3 @@
1
1
  module LyricsFinder
2
- VERSION = "0.0.6"
3
- end
2
+ VERSION = "0.1.0"
3
+ end
@@ -20,12 +20,14 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake'
23
-
24
23
  spec.add_development_dependency 'rspec', '~> 2.14.0'
25
24
  spec.add_development_dependency 'rspec-nc', '~> 0.1.0'
26
25
  spec.add_development_dependency 'vcr', '~> 2.9.2'
27
26
  spec.add_development_dependency 'webmock', '~> 1.18.0'
28
27
  spec.add_development_dependency 'coveralls', '~> 0.7.0'
28
+ spec.add_development_dependency 'pry', '~> 0.9'
29
+ spec.add_development_dependency 'pry-byebug', '1.3.2'
30
+ spec.add_development_dependency 'awesome_print', '~> 1.2.0'
29
31
 
30
32
  spec.add_dependency 'nokogiri', '~> 1.6.1'
31
33
  spec.add_dependency 'activesupport', '~> 4.1.0'
@@ -1,71 +1,11 @@
1
- describe Lyrics::Finder do
2
- describe 'sets @providers properly on initialization' do
3
- context 'without specifying providers' do
4
- let(:finder) { Lyrics::Finder.new }
5
-
6
- it 'sets @providers to default PROVIDERS_LIST' do
7
- expect(finder.selected_providers).to eq Lyrics::Providers.providers_list
8
- end
9
- end
10
-
11
- context 'specifying providers' do
12
- context 'some providers are invalid' do
13
- let(:finder) { Lyrics::Finder.new(:lyrics_wikia, :bad_songs) }
14
-
15
- it 'filters invalid providers' do
16
- expect(finder.selected_providers).to match_array [:lyrics_wikia]
17
- end
18
- end
19
-
20
- context 'all providers are invalid' do
21
- let(:finder) { Lyrics::Finder.new(:bad_songs, :invalid_songs) }
22
-
23
- it 'sets @providers to default PROVIDERS_LIST' do
24
- expect(finder.selected_providers).to eq Lyrics::Providers.providers_list
25
- end
26
- end
27
- end
28
- end # 'initialization'
1
+ describe LyricsFinder do
29
2
 
30
3
  describe '#search' do
31
- describe 'using LyricsWikia as the provider' do
32
- context 'with a song that can be found' do
33
- before :each do
34
- @finder = Lyrics::Finder.new(:lyrics_wikia)
35
- VCR.use_cassette 'LyricsWikia 200 search' do
36
- @song = @finder.search("american authors", "best day of my life")
37
- end
38
- end
39
-
40
- it 'returns an instance of Array' do
41
- expect(@song.class).to eq Array
42
- end
43
-
44
- it 'returns the desired song' do
45
- expect(@song).to eq LyricsWikiaSampleSongs::BEST_DAY_OF_MY_LIFE
46
- end
47
- end
48
-
49
- # Searching for a song that exist but it's not yet on this website.
50
- context 'with a song that cannot be found' do
51
- before :each do
52
- @finder = Lyrics::Finder.new(:lyrics_wikia)
53
- VCR.use_cassette 'LyricsWikia Song does not exist search' do
54
- @song = @finder.search("arctic monkeys", "do i wanna know")
55
- end
56
- end
57
-
58
- it 'returns nil' do
59
- expect(@song).to be nil
60
- end
61
- end
62
- end
63
4
 
64
- describe 'using Azlyrics as the provider' do
5
+ context 'with a song that can be found' do
65
6
  before :each do
66
- @finder = Lyrics::Finder.new(:azlyrics)
67
- VCR.use_cassette 'Azlyrics 200 search' do
68
- @song = @finder.search("american authors", "best day of my life")
7
+ VCR.use_cassette 'LyricsWikia 200 search' do
8
+ @song = LyricsFinder.search("american authors", "best day of my life")
69
9
  end
70
10
  end
71
11
 
@@ -74,66 +14,16 @@ describe Lyrics::Finder do
74
14
  end
75
15
 
76
16
  it 'returns the desired song' do
77
- expect(@song).to eq AzlyricsSampleSongs::BEST_DAY_OF_MY_LIFE
17
+ expect(@song).to eq LyricsWikiaSampleSongs::BEST_DAY_OF_MY_LIFE
78
18
  end
79
19
  end
80
20
 
81
- describe 'using SongLyrics as the provider' do
82
- before :each do
83
- @finder = Lyrics::Finder.new(:song_lyrics)
84
- VCR.use_cassette 'SongLyrics 200 search' do
85
- @song = @finder.search("american authors", "best day of my life")
86
- end
87
- end
88
-
89
- it 'returns an instance of Array' do
90
- expect(@song.class).to eq Array
91
- end
92
-
93
- it 'returns the desired song' do
94
- expect(@song).to eq SongLyricsSampleSongs::BEST_DAY_OF_MY_LIFE
95
- end
96
- end
97
-
98
- describe 'using LyricsMania as the provider' do
99
- before :each do
100
- @finder = Lyrics::Finder.new(:lyrics_mania)
101
- VCR.use_cassette 'LyricsMania 200 search' do
102
- @song = @finder.search("american authors", "best day of my life")
103
- end
104
- end
105
-
106
- it 'returns an instance of Array' do
107
- expect(@song.class).to eq Array
108
- end
109
-
110
- it 'returns the desired song' do
111
- expect(@song).to eq LyricsManiaSampleSongs::BEST_DAY_OF_MY_LIFE
112
- end
113
- end
114
-
115
- describe 'with a song that cannot be found' do
116
- before :each do
117
- @finder = Lyrics::Finder.new
118
- VCR.use_cassette 'Nonexistent Song 404 search' do
119
- @song = @finder.search("the foobar band", "rubynation")
120
- end
121
- end
122
-
123
- it 'returns nil' do
124
- expect(@song).to be nil
125
- end
126
- end
127
-
128
- describe 'with invalid parameters' do
129
- let(:finder) { Lyrics::Finder.new }
130
-
21
+ context 'with invalid parameters' do
131
22
  it 'fails with ContractError' do
132
- expect{
133
- finder.search("","")
134
- }.to raise_error ContractError
23
+ expect(LyricsFinder.search("","")).to eq nil
135
24
  end
136
25
  end
26
+
137
27
  end # '#search'
138
28
 
139
- end
29
+ end
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
- describe Lyrics::Providers::Azlyrics do
2
+ describe LyricsFinder::Providers::Azlyrics do
3
+
3
4
  describe '.format_url' do
4
5
  context 'with valid author and title' do
5
- let(:klass) { Lyrics::Providers::Azlyrics }
6
- let(:song) { Lyrics::Song.new("amêricàn authors", "best day of my life") }
6
+ let(:klass) { LyricsFinder::Providers::Azlyrics }
7
+ let(:song) { Song.new("amêricàn authors", "best day of my life") }
7
8
  let(:valid_url) { "http://www.azlyrics.com/lyrics/americanauthors/bestdayofmylife.html" }
8
9
 
9
10
  it 'returns a properly formatted url' do
@@ -15,7 +16,7 @@ describe Lyrics::Providers::Azlyrics do
15
16
  describe '.extract_lyric' do
16
17
  # with valid data it's already tested in lyrics_finder_spec.rb
17
18
  context 'with invalid data' do
18
- let(:klass) { Lyrics::Providers::Azlyrics }
19
+ let(:klass) { LyricsFinder::Providers::Azlyrics }
19
20
 
20
21
  it 'raises a ContractError Exception' do
21
22
  expect{
@@ -24,4 +25,5 @@ describe Lyrics::Providers::Azlyrics do
24
25
  end
25
26
  end
26
27
  end
28
+
27
29
  end
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
- describe Lyrics::Providers::LyricsMania do
2
+ describe LyricsFinder::Providers::LyricsMania do
3
+
3
4
  describe '.format_url' do
4
5
  context 'with valid author and title' do
5
- let(:klass) { Lyrics::Providers::LyricsMania }
6
- let(:song) { Lyrics::Song.new("amêricàn authors", "best day of my life") }
6
+ let(:klass) { LyricsFinder::Providers::LyricsMania }
7
+ let(:song) { Song.new("amêricàn authors", "best day of my life") }
7
8
  let(:valid_url) { "http://www.lyricsmania.com/best_day_of_my_life_lyrics_american_authors.html" }
8
9
 
9
10
  it 'returns a properly formatted url' do
@@ -15,7 +16,7 @@ describe Lyrics::Providers::LyricsMania do
15
16
  describe '.extract_lyric' do
16
17
  # with valid data it's already tested in lyrics_finder_spec.rb
17
18
  context 'with invalid data' do
18
- let(:klass) { Lyrics::Providers::LyricsMania }
19
+ let(:klass) { LyricsFinder::Providers::LyricsMania }
19
20
 
20
21
  it 'raises a ContractError Exception' do
21
22
  expect{
@@ -24,4 +25,5 @@ describe Lyrics::Providers::LyricsMania do
24
25
  end
25
26
  end
26
27
  end
28
+
27
29
  end
@@ -1,37 +1,22 @@
1
1
  # encoding: UTF-8
2
- describe Lyrics::Providers::LyricsWikia do
2
+ describe LyricsFinder::Providers::LyricsWikia do
3
+
3
4
  describe '.format_url' do
4
5
  context 'with valid author and title' do
5
- let(:klass) { Lyrics::Providers::LyricsWikia }
6
- let(:song) { Lyrics::Song.new("amëricán authòrs", "best day of my life") }
6
+ let(:klass) { LyricsFinder::Providers::LyricsWikia }
7
+ let(:song) { Song.new("amëricán authòrs", "best day of my life") }
7
8
  let(:valid_url) { "http://lyrics.wikia.com/american_authors:best_day_of_my_life" }
8
9
 
9
10
  it 'returns a properly formatted url' do
10
11
  expect(klass.format_url(song)).to eq valid_url
11
12
  end
12
13
  end
13
-
14
- context 'with invalid author or title' do
15
- let(:klass) { Lyrics::Providers::LyricsWikia }
16
-
17
- it 'with non-string arguments raises a ContractError Exception' do
18
- expect{
19
- klass.format_url(2)
20
- }.to raise_error ContractError
21
- end
22
-
23
- it 'with empty strings arguments raises a ContractError Exception' do
24
- expect{
25
- klass.format_url("")
26
- }.to raise_error ContractError
27
- end
28
- end
29
14
  end
30
15
 
31
16
  describe '.extract_lyric' do
32
17
  # with valid data it's already tested in lyrics_finder_spec.rb
33
18
  context 'with invalid data' do
34
- let(:klass) { Lyrics::Providers::LyricsWikia }
19
+ let(:klass) { LyricsFinder::Providers::LyricsWikia }
35
20
 
36
21
  it 'raises a ContractError Exception' do
37
22
  expect{
@@ -40,4 +25,5 @@ describe Lyrics::Providers::LyricsWikia do
40
25
  end
41
26
  end
42
27
  end
28
+
43
29
  end
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
- describe Lyrics::Providers::SongLyrics do
2
+ describe LyricsFinder::Providers::SongLyrics do
3
+
3
4
  describe '.format_url' do
4
5
  context 'with valid author and title' do
5
- let(:klass) { Lyrics::Providers::SongLyrics}
6
- let(:song) { Lyrics::Song.new("amêricàn authors", "best day of my life") }
6
+ let(:klass) { LyricsFinder::Providers::SongLyrics}
7
+ let(:song) { Song.new("amêricàn authors", "best day of my life") }
7
8
  let(:valid_url) { "http://www.songlyrics.com/american-authors/best-day-of-my-life-lyrics/" }
8
9
 
9
10
  it 'returns a properly formatted url' do
@@ -15,7 +16,7 @@ describe Lyrics::Providers::SongLyrics do
15
16
  describe '.extract_lyric' do
16
17
  # with valid data it's already tested in lyrics_finder_spec.rb
17
18
  context 'with invalid data' do
18
- let(:klass) { Lyrics::Providers::SongLyrics }
19
+ let(:klass) { LyricsFinder::Providers::SongLyrics }
19
20
 
20
21
  it 'raises a ContractError Exception' do
21
22
  expect{
@@ -24,4 +25,5 @@ describe Lyrics::Providers::SongLyrics do
24
25
  end
25
26
  end
26
27
  end
28
+
27
29
  end
@@ -1,19 +1,23 @@
1
- describe Lyrics::Providers do
1
+ describe LyricsFinder::Providers do
2
+
2
3
  describe '.build_klass' do
4
+
3
5
  context 'with valid arguments' do
4
- let(:klass) { Lyrics::Providers::LyricsWikia }
6
+ let(:klass) { LyricsFinder::Providers::LyricsWikia }
5
7
 
6
8
  it 'builds the correct class' do
7
- expect(Lyrics::Providers.build_klass(:lyrics_wikia)).to eq klass
9
+ expect(LyricsFinder::Providers.build_klass(:lyrics_wikia)).to eq klass
8
10
  end
9
11
  end
10
12
 
11
13
  context 'with invalid arguments' do
12
14
  it 'raises a ContractError Exception' do
13
15
  expect{
14
- Lyrics::Providers.build_klass("klass")
16
+ LyricsFinder::Providers.build_klass("klass")
15
17
  }.to raise_error ContractError
16
18
  end
17
19
  end
20
+
18
21
  end
22
+
19
23
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
- require 'vcr'
5
4
  require 'lyrics_finder'
5
+ require 'vcr'
6
6
 
7
7
  require_relative 'support/vcr_setup'
8
- require_relative 'support/lyrics_wikia_sample_songs'
9
- require_relative 'support/azlyrics_sample_songs'
10
- require_relative 'support/song_lyrics_sample_songs'
11
- require_relative 'support/lyrics_mania_sample_songs'
8
+ require_relative 'support/lyrics_wikia_sample_songs'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyrics_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Romero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,48 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.2.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.2.0
111
153
  - !ruby/object:Gem::Dependency
112
154
  name: nokogiri
113
155
  requirement: !ruby/object:Gem::Requirement
@@ -200,10 +242,6 @@ files:
200
242
  - lib/lyrics_finder/cli.rb
201
243
  - lib/lyrics_finder/dependencies.rb
202
244
  - lib/lyrics_finder/providers.rb
203
- - lib/lyrics_finder/providers/azlyrics.rb
204
- - lib/lyrics_finder/providers/lyrics_mania.rb
205
- - lib/lyrics_finder/providers/lyrics_wikia.rb
206
- - lib/lyrics_finder/providers/song_lyrics.rb
207
245
  - lib/lyrics_finder/song.rb
208
246
  - lib/lyrics_finder/version.rb
209
247
  - lyrics_finder.gemspec
@@ -214,10 +252,7 @@ files:
214
252
  - spec/lyrics_finder/providers/song_lyrics_spec.rb
215
253
  - spec/lyrics_finder/providers_spec.rb
216
254
  - spec/spec_helper.rb
217
- - spec/support/azlyrics_sample_songs.rb
218
- - spec/support/lyrics_mania_sample_songs.rb
219
255
  - spec/support/lyrics_wikia_sample_songs.rb
220
- - spec/support/song_lyrics_sample_songs.rb
221
256
  - spec/support/vcr_setup.rb
222
257
  homepage: https://github.com/dnlR/lyrics_finder
223
258
  licenses:
@@ -251,8 +286,5 @@ test_files:
251
286
  - spec/lyrics_finder/providers/song_lyrics_spec.rb
252
287
  - spec/lyrics_finder/providers_spec.rb
253
288
  - spec/spec_helper.rb
254
- - spec/support/azlyrics_sample_songs.rb
255
- - spec/support/lyrics_mania_sample_songs.rb
256
289
  - spec/support/lyrics_wikia_sample_songs.rb
257
- - spec/support/song_lyrics_sample_songs.rb
258
290
  - spec/support/vcr_setup.rb
@@ -1,16 +0,0 @@
1
- module Lyrics
2
- module Providers::Azlyrics
3
- include Contracts
4
-
5
- Contract Lyrics::Song => String
6
- def self.format_url(song)
7
- song.format_attributes_with_separator!("")
8
- "http://www.azlyrics.com/lyrics/#{song.author}/#{song.title}.html"
9
- end
10
-
11
- Contract Tempfile => Or[Array, nil]
12
- def self.extract_lyric(data)
13
- Lyrics::Providers.extract_lyrics_at_css_from_data('div:nth-child(7)', data)
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module Lyrics
2
- module Providers::LyricsMania
3
- include Contracts
4
-
5
- Contract Lyrics::Song => String
6
- def self.format_url(song)
7
- song.format_attributes_with_separator!("_")
8
- "http://www.lyricsmania.com/#{song.title}_lyrics_#{song.author}.html"
9
- end
10
-
11
- Contract Tempfile => Or[Array, nil]
12
- def self.extract_lyric(data)
13
- Lyrics::Providers.extract_lyrics_at_css_from_data('.lyrics-body', data)
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module Lyrics
2
- module Providers::LyricsWikia
3
- include Contracts
4
-
5
- Contract Lyrics::Song => String
6
- def self.format_url(song)
7
- song.format_attributes_with_separator!("_")
8
- "http://lyrics.wikia.com/#{song.author}:#{song.title}"
9
- end
10
-
11
- Contract Tempfile => Or[Array, nil]
12
- def self.extract_lyric(data)
13
- Lyrics::Providers.extract_lyrics_at_css_from_data('.lyricbox', data)
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module Lyrics
2
- module Providers::SongLyrics
3
- include Contracts
4
-
5
- Contract Lyrics::Song => String
6
- def self.format_url(song)
7
- song.format_attributes_with_separator!("-")
8
- "http://www.songlyrics.com/#{song.author}/#{song.title}-lyrics/"
9
- end
10
-
11
- Contract Tempfile => Or[Array, nil]
12
- def self.extract_lyric(data)
13
- Lyrics::Providers.extract_lyrics_at_css_from_data('#songLyricsDiv', data)
14
- end
15
- end
16
- end
@@ -1,47 +0,0 @@
1
- module AzlyricsSampleSongs
2
- BEST_DAY_OF_MY_LIFE = ["I had a dream so big and loud",
3
- "I jumped so high I touched the clouds",
4
- "Wo-o-o-o-o-oh",
5
- "I stretched my hands out to the sky",
6
- "We danced with monsters through the night",
7
- "Wo-o-o-o-o-oh",
8
- "I'm never gonna look back",
9
- "Whoa, I'm never gonna give it up",
10
- "No, please don't wake me now",
11
- "Oo-o-o-o-oo",
12
- "This is gonna be the best day of my life",
13
- "My life",
14
- "Oo-o-o-o-oo",
15
- "This is gonna be the best day of my life",
16
- "My life",
17
- "I howled at the moon with friends",
18
- "And then the sun came crashing in",
19
- "Wo-o-o-o-o-oh",
20
- "But all the possibilities",
21
- "No limits just epiphanies",
22
- "Wo-o-o-o-o-oh",
23
- "I'm never gonna look back",
24
- "Whoa, I'm never gonna give it up",
25
- "No, just don't wake me now",
26
- "Oo-o-o-o-oo",
27
- "This is gonna be the best day of my life",
28
- "My life",
29
- "Oo-o-o-o-oo",
30
- "This is gonna be the best day of my life",
31
- "My life",
32
- "I hear it calling outside my window",
33
- "I feel it in my soul (soul)",
34
- "The stars were burning so bright",
35
- "The sun was out 'til midnight",
36
- "I say we lose control (control)",
37
- "This is gonna be the best day of my life",
38
- "My life",
39
- "Oo-o-o-o-o",
40
- "This is gonna be the best day of my life",
41
- "My life",
42
- "This is gonna be, this is gonna be, this is gonna be",
43
- "The best day of my life",
44
- "Everything is looking up, everybody up now",
45
- "This is gonna be the best day of my life",
46
- "My life"]
47
- end
@@ -1,52 +0,0 @@
1
- module LyricsManiaSampleSongs
2
- BEST_DAY_OF_MY_LIFE = ["Wo-o-o-o-o-oh Wooh",
3
- "I had a dream so big and loud",
4
- "I jumped so high I touched the clouds",
5
- "Wo-o-o-o-o-oh",
6
- "Wo-o-o-o-o-oh",
7
- "I stretched my hands out to the sky",
8
- "We danced with monsters through the night",
9
- "Wo-o-o-o-o-oh",
10
- "Wo-o-o-o-o-oh",
11
- "I'm never gonna look back",
12
- "Woah, I'm never gonna give it up",
13
- "No, please don't wake me now",
14
- "Oo-o-o-o-oo",
15
- "This is gonna be the best day of my life",
16
- "My li-i-i-i-i-ife",
17
- "Oo-o-o-o-oo",
18
- "This is gonna be the best day of my life",
19
- "My li-i-i-i-i-ife",
20
- "I howled at the moon with friends",
21
- "And then the sun came crashing in",
22
- "Wo-o-o-o-o-oh",
23
- "Wo-o-o-o-o-oh",
24
- "But all the possibilities",
25
- "No limits just epiphanies",
26
- "Wo-o-o-o-o-oh",
27
- "Wo-o-o-o-o-oh",
28
- "I'm never gonna look back",
29
- "Woah, I'm never gonna give it up",
30
- "No, just don't wake me now",
31
- "Oo-o-o-o-oo",
32
- "This is gonna be the best day of my life",
33
- "My li-i-i-i-i-ife",
34
- "Oo-o-o-o-oo",
35
- "This is gonna be the best day of my life",
36
- "My li-i-i-i-i-ife",
37
- "I hear it calling outside my window",
38
- "I feel it in my soul (soul)",
39
- "The stars were burning so bright",
40
- "The sun was out 'til midnight",
41
- "I say we lose control (control)",
42
- "This is gonna be the best day of my life",
43
- "My li-i-i-i-i-ife",
44
- "Oo-o-o-o-o",
45
- "This is gonna be the best day of my life",
46
- "My li-i-i-i-i-ife",
47
- "This is gonna be, this is gonna be, this is gonna be",
48
- "The best day of my life",
49
- "Everything is looking up, everybody up now",
50
- "This is gonna be the best day of my life",
51
- "My li-i-i-i-i-ife"]
52
- end
@@ -1,47 +0,0 @@
1
- module SongLyricsSampleSongs
2
- BEST_DAY_OF_MY_LIFE = ["I had a dream so big and loud",
3
- "I jumped so high I touched the clouds",
4
- "Wo-o-o-o-o-oh [x2]",
5
- "I stretched my hands out to the sky",
6
- "We danced with monsters through the night",
7
- "Wo-o-o-o-o-oh [x2]",
8
- "I'm never gonna look back",
9
- "Woah, never gonna give it up",
10
- "No, please don't wake me now",
11
- "Oo-o-o-o-oo",
12
- "This is gonna be the best day of my li-ife",
13
- "My li-i-i-i-i-ife",
14
- "Oo-o-o-o-oo",
15
- "This is gonna be the best day of my li-ife",
16
- "My li-i-i-i-i-ife",
17
- "I howled at the moon with friends",
18
- "And then the sun came crashing in",
19
- "Wo-o-o-o-o-oh [x2]",
20
- "But all the possibilities",
21
- "No limits just epiphanies",
22
- "Wo-o-o-o-o-oh [x2]",
23
- "I'm never gonna look back",
24
- "Woah, never gonna give it up",
25
- "No, just don't wake me now",
26
- "Oo-o-o-o-oo",
27
- "This is gonna be the best day of my li-ife",
28
- "My li-i-i-i-i-ife",
29
- "Oo-o-o-o-oo",
30
- "This is gonna be the best day of my li-ife",
31
- "My li-i-i-i-i-ife",
32
- "I hear it calling outside my window",
33
- "I feel it in my soul (soul)",
34
- "The stars were burning so bright",
35
- "The sun was out 'til midnight",
36
- "I say we lose control (control)",
37
- "This is gonna be the best day of my li-ife",
38
- "My li-i-i-i-i-ife",
39
- "Oo-o-o-o-o",
40
- "This is gonna be the best day of my li-ife",
41
- "My li-i-i-i-i-ife",
42
- "This is gonna be, this is gonna be, this is gonna be",
43
- "The best day of my life",
44
- "Everything is looking up, everybody up now",
45
- "This is gonna be the best day of my li-ife",
46
- "My li-i-i-i-i-ife"]
47
- end