lyricfy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Song Lyrics for your Ruby apps.
4
4
 
5
+ [![Build Status](https://travis-ci.org/javichito/Lyricfy.png?branch=master)](https://travis-ci.org/javichito/Lyricfy)
6
+ [![Code Climate](https://codeclimate.com/github/javichito/Lyricfy.png)](https://codeclimate.com/github/javichito/Lyricfy)
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -22,7 +25,7 @@ You need to create an instance of the <code>Lyricfy::Fetcher</code> class and se
22
25
 
23
26
  fetcher = Lyricfy::Fetcher.new
24
27
  lyric = fetcher.search 'Coldplay', 'Viva la vida'
25
- puts lyric.body.join('\n')
28
+ lyric.body.each { |line| puts line }
26
29
 
27
30
  The <code>Lyricfy::Fetcher#search</code> method returns an OpenStruct object with the following methods:
28
31
 
@@ -43,7 +46,7 @@ By default this gem will recursively search for the lyric on each of the provide
43
46
 
44
47
  fetcher = Lyricfy::Fetcher.new(:metro_lyrics)
45
48
  lyric = fetcher.search 'Coldplay', 'Viva la vida'
46
- puts lyric.body.join('\n')
49
+ lyric.body.each { |line| puts line }
47
50
 
48
51
  In this case Lyricfy will look for the lyric only on [MetroLyrics](http://www.metrolyrics.com/).
49
52
 
@@ -11,14 +11,12 @@ module Lyricfy
11
11
  def search
12
12
  if data = super
13
13
  html = Nokogiri::HTML(data)
14
- container = html.css('p.lyricsbody').first || html.css('p.gnlyricsbody').first
15
- elements = container.children.to_a
16
- paragraphs = elements.select { |ele| ele.text? }
17
- paragraphs.map! { |paragraph| paragraph.text.strip.chomp if paragraph.text != "\n" }.reject! { |ele| ele.empty? }
14
+ html_to_array(html)
18
15
  end
19
16
  end
20
17
 
21
18
  private
19
+
22
20
  def prepare_parameter(parameter)
23
21
  parameter.downcase.split(' ').map { |w| w.gsub(/\W/, '') }.join('-')
24
22
  end
@@ -28,5 +26,12 @@ module Lyricfy
28
26
  song_name = prepare_parameter(self.parameters[:song_name])
29
27
  "#{song_name}-lyrics-#{artist_name}"
30
28
  end
29
+
30
+ def html_to_array(html)
31
+ container = html.css('p.lyricsbody').first || html.css('p.gnlyricsbody').first
32
+ elements = container.children.to_a
33
+ paragraphs = elements.select { |ele| ele.text? }
34
+ paragraphs.map! { |paragraph| paragraph.text.strip.chomp if paragraph.text != "\n" }.reject! { |ele| ele.empty? }
35
+ end
31
36
  end
32
37
  end
@@ -11,18 +11,23 @@ module Lyricfy
11
11
  def search
12
12
  if data = super
13
13
  html = Nokogiri::HTML(data)
14
- container = html.css('div.lyricbox').first
15
- elements = container.children.to_a
16
- paragraphs = elements.select { |ele| ele.text? }
17
- paragraphs.map! { |paragraph| paragraph.text.strip.chomp if paragraph.text != "\n" }.reject! { |ele| ele.nil? }
14
+ html_to_array(html)
18
15
  end
19
16
  end
20
17
 
21
18
  private
19
+
22
20
  def format_parameters
23
21
  artist_name = tilde_to_vocal(self.parameters[:artist_name]).gsub(" ", "_")
24
22
  song_name = tilde_to_vocal(self.parameters[:song_name]).gsub(" ", "_")
25
23
  "#{artist_name}:#{song_name}"
26
24
  end
25
+
26
+ def html_to_array(html)
27
+ container = html.css('div.lyricbox').first
28
+ elements = container.children.to_a
29
+ paragraphs = elements.select { |ele| ele.text? }
30
+ paragraphs.map! { |paragraph| paragraph.text.strip.chomp if paragraph.text != "\n" }.reject! { |ele| ele.nil? }
31
+ end
27
32
  end
28
33
  end
@@ -1,3 +1,3 @@
1
1
  module Lyricfy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/lyricfy.rb CHANGED
@@ -20,7 +20,7 @@ module Lyricfy
20
20
  if !args.empty?
21
21
  passed_providers = {}
22
22
  args.each do |provider|
23
- raise Exception if !@providers.has_key?(provider)
23
+ raise Exception unless @providers.has_key?(provider)
24
24
  passed_providers[provider] = @providers[provider]
25
25
  end
26
26
  @providers = passed_providers
@@ -34,6 +34,7 @@ module Lyricfy
34
34
 
35
35
  if lyric_body = fetcher.search
36
36
  result = OpenStruct.new(artist: artist, song: song, body: lyric_body)
37
+ break
37
38
  end
38
39
  end
39
40
  result
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyricfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-19 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -83,6 +83,7 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
+ - .travis.yml
86
87
  - Gemfile
87
88
  - LICENSE.txt
88
89
  - README.md
@@ -116,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
117
  version: '0'
117
118
  segments:
118
119
  - 0
119
- hash: -3632876031990532312
120
+ hash: 3084054243031445109
120
121
  required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  none: false
122
123
  requirements:
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  version: '0'
126
127
  segments:
127
128
  - 0
128
- hash: -3632876031990532312
129
+ hash: 3084054243031445109
129
130
  requirements: []
130
131
  rubyforge_project:
131
132
  rubygems_version: 1.8.25