rae 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +10 -11
- data/VERSION +1 -1
- data/bin/rae +5 -27
- data/lib/rae.rb +62 -1
- data/rae.gemspec +12 -18
- metadata +32 -33
data/Rakefile
CHANGED
@@ -5,23 +5,21 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "rae"
|
8
|
-
gem.summary = %Q{
|
9
|
-
gem.description = %Q{
|
10
|
-
gem.email = "
|
11
|
-
gem.homepage = "http://
|
12
|
-
gem.authors = ["Koldo Oteo"]
|
13
|
-
gem.
|
14
|
-
|
15
|
-
gem.add_dependency('mechanize', '>= 0.9.3')
|
16
|
-
gem.add_dependency('nokogiri', '>= 1.3.3')
|
8
|
+
gem.summary = %Q{library to access the rae.es}
|
9
|
+
gem.description = %Q{library to access the rae.es}
|
10
|
+
gem.email = "krawek@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/dcu/rae"
|
12
|
+
gem.authors = ["David A. Cuadrado", "Koldo Oteo"]
|
13
|
+
gem.add_dependency "mechanize", ">= 1.0.0"
|
17
14
|
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
18
16
|
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with:
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
18
|
end
|
21
19
|
|
22
20
|
require 'rake/testtask'
|
23
21
|
Rake::TestTask.new(:test) do |test|
|
24
|
-
test.libs << 'test'
|
22
|
+
test.libs << 'lib' << 'test'
|
25
23
|
test.pattern = 'test/**/test_*.rb'
|
26
24
|
test.verbose = true
|
27
25
|
end
|
@@ -50,4 +48,5 @@ Rake::RDocTask.new do |rdoc|
|
|
50
48
|
rdoc.rdoc_dir = 'rdoc'
|
51
49
|
rdoc.title = "rae #{version}"
|
52
50
|
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
52
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/rae
CHANGED
@@ -1,32 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# http://koteo.lacoctelera.net
|
3
|
+
$:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
+
require 'rae'
|
6
5
|
|
7
|
-
|
8
|
-
require 'nokogiri'
|
9
|
-
require 'mechanize'
|
6
|
+
definitions = Rae.new.search(ARGV.first)
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
if !palabra
|
14
|
-
puts "Pon la palabra que deseas buscar en la web del rae:"
|
15
|
-
palabra = gets.chomp
|
16
|
-
end
|
17
|
-
|
18
|
-
agent = WWW::Mechanize.new
|
19
|
-
agent.user_agent_alias = 'Mac Safari'
|
20
|
-
page = agent.get 'http://buscon.rae.es/draeI/html/cabecera.htm'
|
21
|
-
|
22
|
-
form = page.forms.first
|
23
|
-
|
24
|
-
form['TIPO_BUS'] = '3'
|
25
|
-
form['LEMA'] = palabra
|
26
|
-
|
27
|
-
page = agent.submit(form, form.buttons.first)
|
28
|
-
|
29
|
-
read_doc = Nokogiri::HTML(page.body)
|
30
|
-
read_doc.css('p').each do |l|
|
31
|
-
puts l.content.to_s.strip
|
8
|
+
definitions.each_with_index do |definition, index|
|
9
|
+
puts "#{index+1}. #{definition}"
|
32
10
|
end
|
data/lib/rae.rb
CHANGED
@@ -1,2 +1,63 @@
|
|
1
|
-
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
if RUBY_VERSION < '1.9'
|
4
|
+
$KCODE = 'u'
|
5
|
+
end
|
6
|
+
|
7
|
+
class Rae
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def search(word, bus = 3)
|
12
|
+
agent = Mechanize.new
|
13
|
+
agent.user_agent_alias = 'Mac Safari'
|
14
|
+
page = agent.get 'http://buscon.rae.es/draeI/html/cabecera.htm'
|
15
|
+
|
16
|
+
form = page.forms.first
|
17
|
+
|
18
|
+
form['TIPO_BUS'] = bus
|
19
|
+
form['LEMA'] = word
|
20
|
+
|
21
|
+
page = agent.submit(form, form.buttons.first)
|
22
|
+
|
23
|
+
parse_page(page, word)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def parse_page(page, word)
|
28
|
+
definitions = []
|
29
|
+
subdefinition = nil
|
30
|
+
page.parser.css('p').each_with_index do |l, index|
|
31
|
+
if l.content.to_s.strip =~ /La palabra #{Regexp.escape(word)} no/
|
32
|
+
links = page.links_with(:href => /\?LEMA\=/)
|
33
|
+
if link = links.first
|
34
|
+
word = link.text.strip
|
35
|
+
page = link.click
|
36
|
+
return parse_page(page, word)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
definition, subdefinition = parse_definition(l, subdefinition, word)
|
40
|
+
definitions << definition if definition
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
definitions
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_definition(l, subdefinition, word)
|
48
|
+
definition = l.content.to_s.strip
|
49
|
+
if definition =~ /\d+\.\s+(.+)/
|
50
|
+
definition = $1
|
51
|
+
if subdefinition
|
52
|
+
definition = "#{subdefinition} -> #{definition}"
|
53
|
+
end
|
54
|
+
elsif definition =~ /\~/
|
55
|
+
subdefinition = definition.sub("~", word).strip
|
56
|
+
definition = nil
|
57
|
+
else
|
58
|
+
definition = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
[definition, subdefinition]
|
62
|
+
end
|
2
63
|
end
|
data/rae.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rae}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Koldo Oteo"]
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = ["David A. Cuadrado", "Koldo Oteo"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
13
|
s.default_executable = %q{rae}
|
14
|
-
s.description = %q{
|
15
|
-
s.email = %q{
|
14
|
+
s.description = %q{library to access the rae.es}
|
15
|
+
s.email = %q{krawek@gmail.com}
|
16
16
|
s.executables = ["rae"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
@@ -29,29 +29,23 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/rae.rb",
|
30
30
|
"rae.gemspec"
|
31
31
|
]
|
32
|
-
s.homepage = %q{http://
|
32
|
+
s.homepage = %q{http://github.com/dcu/rae}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.
|
36
|
-
s.summary = %q{
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{library to access the rae.es}
|
37
37
|
|
38
38
|
if s.respond_to? :specification_version then
|
39
39
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
40
|
s.specification_version = 3
|
41
41
|
|
42
|
-
if Gem::Version.new(Gem::
|
43
|
-
s.
|
44
|
-
s.add_runtime_dependency(%q<mechanize>, [">= 0.9.3"])
|
45
|
-
s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.3"])
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
46
44
|
else
|
47
|
-
s.add_dependency(%q<
|
48
|
-
s.add_dependency(%q<mechanize>, [">= 0.9.3"])
|
49
|
-
s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
|
45
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
50
46
|
end
|
51
47
|
else
|
52
|
-
s.add_dependency(%q<
|
53
|
-
s.add_dependency(%q<mechanize>, [">= 0.9.3"])
|
54
|
-
s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
|
48
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
55
49
|
end
|
56
50
|
end
|
57
51
|
|
metadata
CHANGED
@@ -1,49 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
13
|
+
- David A. Cuadrado
|
7
14
|
- Koldo Oteo
|
8
15
|
autorequire:
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date:
|
19
|
+
date: 2010-08-21 00:00:00 -05:00
|
13
20
|
default_executable: rae
|
14
21
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: thoughtbot-shoulda
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
22
|
- !ruby/object:Gem::Dependency
|
26
23
|
name: mechanize
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
30
27
|
requirements:
|
31
28
|
- - ">="
|
32
29
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
37
36
|
type: :runtime
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 1.3.3
|
44
|
-
version:
|
45
|
-
description: CLI to access the rae.es
|
46
|
-
email: koldo.oteo1@gmail.com
|
37
|
+
version_requirements: *id001
|
38
|
+
description: library to access the rae.es
|
39
|
+
email: krawek@gmail.com
|
47
40
|
executables:
|
48
41
|
- rae
|
49
42
|
extensions: []
|
@@ -62,7 +55,7 @@ files:
|
|
62
55
|
- lib/rae.rb
|
63
56
|
- rae.gemspec
|
64
57
|
has_rdoc: true
|
65
|
-
homepage: http://
|
58
|
+
homepage: http://github.com/dcu/rae
|
66
59
|
licenses: []
|
67
60
|
|
68
61
|
post_install_message:
|
@@ -71,23 +64,29 @@ rdoc_options:
|
|
71
64
|
require_paths:
|
72
65
|
- lib
|
73
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
74
68
|
requirements:
|
75
69
|
- - ">="
|
76
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
77
74
|
version: "0"
|
78
|
-
version:
|
79
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
80
77
|
requirements:
|
81
78
|
- - ">="
|
82
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
83
|
version: "0"
|
84
|
-
version:
|
85
84
|
requirements: []
|
86
85
|
|
87
86
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.7
|
89
88
|
signing_key:
|
90
89
|
specification_version: 3
|
91
|
-
summary:
|
90
|
+
summary: library to access the rae.es
|
92
91
|
test_files: []
|
93
92
|
|