elvallenato 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: face9e2c5e1d24fadb250ffe5aca8050c25e787c
4
+ data.tar.gz: c8d9fd37c89086591c64cb7378fe1fdfd910d1e1
5
+ SHA512:
6
+ metadata.gz: e7aa19f89a71036673df7711262c9376c85cef38429ae25e67f5e41df06de6182645d084ad94fb5671c1e7bf366ad6d66ac10995e5f31e98bd13a29ad1a5367e
7
+ data.tar.gz: 2a3e3a81c206e6227998bafea7eeb4c23e8a922bc5fb05ef178831c1e3a50acd58f2a8352ab0bffa91e70cbded4b643b34b42cd38797524490d87cf355d58e77
data/.bundle/config ADDED
@@ -0,0 +1 @@
1
+ --- {}
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in elvallenato.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elvallenato (0.0.5)
5
+ RedCloth
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ RedCloth (4.2.9)
12
+ awesome_print (1.1.0)
13
+ coderay (1.1.0)
14
+ diff-lcs (1.2.5)
15
+ formatador (0.2.4)
16
+ guard (1.7.0)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 0.6.0)
19
+ lumberjack (>= 1.0.2)
20
+ pry (>= 0.9.10)
21
+ thor (>= 0.14.6)
22
+ guard-bundler (1.0.0)
23
+ bundler (~> 1.0)
24
+ guard (~> 1.1)
25
+ guard-rspec (1.2.1)
26
+ guard (>= 1.1)
27
+ listen (0.7.3)
28
+ lumberjack (1.0.5)
29
+ method_source (0.8.2)
30
+ nokogiri (1.5.5)
31
+ pry (0.9.12.6)
32
+ coderay (~> 1.0)
33
+ method_source (~> 0.8)
34
+ slop (~> 3.4)
35
+ rb-fsevent (0.9.4)
36
+ rspec (2.14.1)
37
+ rspec-core (~> 2.14.0)
38
+ rspec-expectations (~> 2.14.0)
39
+ rspec-mocks (~> 2.14.0)
40
+ rspec-core (2.14.8)
41
+ rspec-expectations (2.14.5)
42
+ diff-lcs (>= 1.1.3, < 2.0)
43
+ rspec-mocks (2.14.6)
44
+ slop (3.5.0)
45
+ thor (0.19.1)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ awesome_print
52
+ elvallenato!
53
+ guard
54
+ guard-bundler
55
+ guard-rspec
56
+ rb-fsevent
57
+ rspec
data/Guardfile ADDED
@@ -0,0 +1,30 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard 'rspec', :version => 2 do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+
15
+ # Rails example
16
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
17
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
18
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
19
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
20
+ watch('config/routes.rb') { "spec/routing" }
21
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
22
+
23
+ # Capybara request specs
24
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
25
+
26
+ # Turnip features and steps
27
+ watch(%r{^spec/acceptance/(.+)\.feature$})
28
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
29
+ end
30
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Maya
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = elvallenato
2
+
3
+ This application is designed to scrap data from el vallenato.com
4
+
5
+ = Examples
6
+
7
+ require 'rubygems'
8
+ require 'elvallenato'
9
+ #Optional if you want to import the namespace
10
+ include ElVallenato
11
+ s = Search.new('canta', "Jorge")
12
+ s.fetch_content
13
+ letras = s.collect_lirics
14
+ puts letras[0].title
15
+ puts letras[0].body
16
+ puts letras[0].artist
17
+ puts letras[0].composer
18
+
19
+ #if you want to go to the next page fetch the contents again
20
+ s.fetch_content
21
+
22
+
23
+ == Note on Patches/Pull Requests
24
+
25
+ * Fork the project.
26
+ * Make your feature addition or bug fix.
27
+ * Add tests for it. This is important so I don't break it in a
28
+ future version unintentionally.
29
+ * Commit, do not mess with rakefile, version, or history.
30
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2009 John Maya. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,9 @@
1
+ require 'autotest/growl'
2
+ require 'autotest/fsevent'
3
+ Autotest.add_discovery { "rspec2" }
4
+
5
+ Autotest.add_hook :initialize do |autotest|
6
+ %w{webrat.log .git .svn .hg .DS_Store tmp log doc}.each do |exception|
7
+ autotest.add_exception(exception)
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "elvallenato/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "elvallenato"
7
+ s.version = Elvallenato::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["John Maya"]
10
+ s.email = ["jcmaya@hotmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{This gem will interface with http://www.elvallenato.com}
13
+ s.description = %q{This gem will interface with http://www.elvallenato.com}
14
+
15
+ s.rubyforge_project = "elvallenato"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.add_development_dependency('rspec')
22
+ s.add_development_dependency('guard')
23
+ s.add_development_dependency('guard-rspec')
24
+ s.add_development_dependency('guard-bundler')
25
+ s.add_development_dependency('rb-fsevent')
26
+ s.add_development_dependency('awesome_print')
27
+ s.add_dependency('RedCloth')
28
+ s.add_dependency('nokogiri')
29
+ end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module ElVallenato
4
+ class Letra
5
+
6
+ attr_reader :content
7
+
8
+ def initialize(content)
9
+ @content = content
10
+ @doc = Nokogiri::HTML(@content)
11
+ end
12
+
13
+ def title
14
+ @title ||= @doc.at(".text_title").text
15
+ end
16
+
17
+ def body
18
+ @body ||= @doc.search("td .text_std")[6].inner_html
19
+ end
20
+
21
+ def composer
22
+ @composer ||= @doc.search("td .text_std")[9].text
23
+ end
24
+
25
+ def artist
26
+ @artist ||= @doc.search("td .text_std")[8].text
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'cgi'
2
+ require 'open-uri'
3
+ require 'URI'
4
+
5
+ module ElVallenato
6
+
7
+ class Search
8
+ attr_reader :mode,:term,:url
9
+
10
+ def initialize(mode,term)
11
+ @current_link = 0
12
+ @mode = CGI.escape(mode)
13
+ @term = CGI.escape(term)
14
+ @url = "http://www.elvallenato.com/letras/busqueda.php?x=#{@term}&busca=#{@mode}&image.x=12&image.y=11"
15
+ @base = "http://" + URI.parse(@url).host
16
+ end
17
+
18
+ def content
19
+ @content ||= OpenURI.open_uri(@url).read
20
+ end
21
+
22
+ def next_url
23
+ return nil if @current_link == pages
24
+ if @current_link > 0
25
+ link = @all_links[@current_link]["href"]
26
+ @current_link += 1
27
+ return [@base,link].join("/")
28
+ else
29
+ @all_links ||= Nokogiri::HTML.parse(content).css("span.class5 a")
30
+ link = @all_links[0]["href"]
31
+ @current_link += 1
32
+ return [@base,link].join("/")
33
+ end
34
+
35
+ end
36
+ def pages
37
+ links.size
38
+ end
39
+
40
+ def links
41
+ @page_links ||= Nokogiri::HTML.parse(content).css("span.class5 a").collect do |e|
42
+ e["href"] if e["href"] =~ /pg=\d+$/
43
+ end.compact.sort.uniq
44
+ end
45
+
46
+ def liric_links
47
+ @liric_links ||= Nokogiri::HTML.parse(content).css('.class10 a').collect do |e|
48
+ clean_url(e["href"])
49
+ end.compact.sort.uniq
50
+ end
51
+
52
+ def clean_url(url)
53
+ url =~ /letras\/letras\/(\d+)\/(.+?)$/
54
+ id = $1
55
+ song_name = CGI.escape($2)
56
+ [@base,"letras","letras",id,song_name].join("/")
57
+ end
58
+
59
+ def letras
60
+ liric_links.collect do |link|
61
+ Letra.new(OpenURI.open_uri(link).read)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module Elvallenato
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'redcloth'
4
+
5
+ module ElVallenato
6
+
7
+ end
8
+
9
+ Dir.glob(File.expand_path(File.dirname(__FILE__) + '/elvallenato') + "/*.rb").each do |rb|
10
+ require rb
11
+ end
12
+
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Elvallenato" do
4
+
5
+ end