rae 1.1.2 → 1.5.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/LICENSE +1 -1
- data/README.rdoc +3 -2
- data/Rakefile +6 -9
- data/VERSION +1 -0
- data/bin/rae +5 -76
- data/lib/rae.rb +63 -0
- data/rae.gemspec +51 -0
- metadata +26 -44
- data/test/helper.rb +0 -10
- data/test/test_rae.rb +0 -7
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -9,9 +9,10 @@ Description goes here.
|
|
9
9
|
* Add tests for it. This is important so I don't break it in a
|
10
10
|
future version unintentionally.
|
11
11
|
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
13
14
|
* Send me a pull request. Bonus points for topic branches.
|
14
15
|
|
15
16
|
== Copyright
|
16
17
|
|
17
|
-
Copyright (c)
|
18
|
+
Copyright (c) 2009 David A. Cuadrado. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,15 +5,12 @@ 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://github.com/
|
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
|
18
15
|
Jeweler::GemcutterTasks.new
|
19
16
|
rescue LoadError
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.5.0
|
data/bin/rae
CHANGED
@@ -1,81 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
#
|
4
|
-
#=======================================================================================
|
5
|
-
#
|
6
|
-
# FILE: rae.rb
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# DESCRIPTION: Libreríde acceso a la drae (diccionario de la real academia españ)
|
10
|
-
# desde ruby
|
11
|
-
#
|
12
|
-
# OPTIONS: [palabra]
|
13
|
-
# REQUIREMENTS: nokogiri, mechanize
|
14
|
-
# AUTHOR: Koldo Oteo (), koldo.oteo1@gmail.com
|
15
|
-
# WEB: http://koteo.lacoctelera.net
|
16
|
-
# VERSION: 1.1.2
|
17
|
-
# CREATED: 10/03/2010
|
18
|
-
# AGRADECIMIENTOS: A krawek de freenode.
|
19
|
-
#=======================================================================================
|
20
|
-
require 'rubygems'
|
21
|
-
require 'nokogiri'
|
22
|
-
require 'mechanize'
|
23
2
|
|
3
|
+
$:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
+
require 'rae'
|
24
5
|
|
25
|
-
|
6
|
+
definitions = Rae.new.search(ARGV.first)
|
26
7
|
|
27
|
-
|
28
|
-
|
29
|
-
if !@pal
|
30
|
-
puts "Programa para acceder al diccionario de la rae desde ruby."
|
31
|
-
puts
|
32
|
-
puts "Uso: rae [palabra]"
|
33
|
-
puts "La palabra se debe escribir con acentos y con exactitud, para buscar en la rae sin problemas."
|
34
|
-
puts
|
35
|
-
puts "Reportar bugs a <koldo.oteo1@gmail.com>."
|
36
|
-
puts
|
37
|
-
exit
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def asig_proxy
|
42
|
-
if ENV['http_proxy'] != nil then
|
43
|
-
#ENV['http_proxy'].scan(/(^http|https) \:\/\/ (\d+.\d+.\d+.\d+|\w+.|\w+.\.\w+) \: (\d.+)/xi)
|
44
|
-
@host, @port = ENV['http_proxy'].to_s.sub(%r{^\w+://}, "").split(":", 2)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def accede_form
|
49
|
-
@agent = Mechanize.new
|
50
|
-
|
51
|
-
asig_proxy
|
52
|
-
if @host != nil
|
53
|
-
@agent.set_proxy("#{@host}", "#{@port}")
|
54
|
-
end
|
55
|
-
|
56
|
-
@agent.user_agent_alias = 'Mac Safari'
|
57
|
-
@page = @agent.get 'http://buscon.rae.es/draeI/html/cabecera.htm'
|
58
|
-
|
59
|
-
@form = @page.forms.first
|
60
|
-
@form['TIPO_BUS'] = '3'
|
61
|
-
@form['LEMA'] = @pal
|
62
|
-
|
63
|
-
@page = @agent.submit(@form, @form.buttons.first)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def format
|
68
|
-
@read_doc = Nokogiri::HTML(@page.body)
|
69
|
-
@read_doc.css('p').each do |l|
|
70
|
-
puts l.content.to_s.strip
|
71
|
-
end
|
72
|
-
end
|
8
|
+
definitions.each_with_index do |definition, index|
|
9
|
+
puts "#{index+1}. #{definition}"
|
73
10
|
end
|
74
|
-
|
75
|
-
|
76
|
-
ra = Rae.new
|
77
|
-
|
78
|
-
ra.pide_pal
|
79
|
-
ra.accede_form
|
80
|
-
ra.format
|
81
|
-
|
data/lib/rae.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
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
|
63
|
+
end
|
data/rae.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rae}
|
8
|
+
s.version = "1.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David A. Cuadrado", "Koldo Oteo"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.default_executable = %q{rae}
|
14
|
+
s.description = %q{library to access the rae.es}
|
15
|
+
s.email = %q{krawek@gmail.com}
|
16
|
+
s.executables = ["rae"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/rae",
|
29
|
+
"lib/rae.rb",
|
30
|
+
"rae.gemspec"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/dcu/rae}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{library to access the rae.es}
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 1.0.0"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
46
|
+
end
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<mechanize>, [">= 1.0.0"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
metadata
CHANGED
@@ -1,64 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 1.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
13
|
+
- David A. Cuadrado
|
12
14
|
- Koldo Oteo
|
13
15
|
autorequire:
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-
|
19
|
+
date: 2010-08-21 00:00:00 -05:00
|
18
20
|
default_executable: rae
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
23
|
+
name: mechanize
|
22
24
|
prerelease: false
|
23
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 23
|
27
31
|
segments:
|
32
|
+
- 1
|
28
33
|
- 0
|
29
|
-
version: "0"
|
30
|
-
type: :development
|
31
|
-
version_requirements: *id001
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: mechanize
|
34
|
-
prerelease: false
|
35
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
segments:
|
40
34
|
- 0
|
41
|
-
|
42
|
-
- 3
|
43
|
-
version: 0.9.3
|
35
|
+
version: 1.0.0
|
44
36
|
type: :runtime
|
45
|
-
version_requirements: *
|
46
|
-
|
47
|
-
|
48
|
-
prerelease: false
|
49
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 1
|
55
|
-
- 3
|
56
|
-
- 3
|
57
|
-
version: 1.3.3
|
58
|
-
type: :runtime
|
59
|
-
version_requirements: *id003
|
60
|
-
description: CLI to access the rae.es
|
61
|
-
email: koldo.oteo1@gmail.com
|
37
|
+
version_requirements: *id001
|
38
|
+
description: library to access the rae.es
|
39
|
+
email: krawek@gmail.com
|
62
40
|
executables:
|
63
41
|
- rae
|
64
42
|
extensions: []
|
@@ -72,11 +50,12 @@ files:
|
|
72
50
|
- LICENSE
|
73
51
|
- README.rdoc
|
74
52
|
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- bin/rae
|
75
55
|
- lib/rae.rb
|
76
|
-
-
|
77
|
-
- test/test_rae.rb
|
56
|
+
- rae.gemspec
|
78
57
|
has_rdoc: true
|
79
|
-
homepage: http://github.com/
|
58
|
+
homepage: http://github.com/dcu/rae
|
80
59
|
licenses: []
|
81
60
|
|
82
61
|
post_install_message:
|
@@ -85,26 +64,29 @@ rdoc_options:
|
|
85
64
|
require_paths:
|
86
65
|
- lib
|
87
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
88
68
|
requirements:
|
89
69
|
- - ">="
|
90
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
91
72
|
segments:
|
92
73
|
- 0
|
93
74
|
version: "0"
|
94
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
95
77
|
requirements:
|
96
78
|
- - ">="
|
97
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
98
81
|
segments:
|
99
82
|
- 0
|
100
83
|
version: "0"
|
101
84
|
requirements: []
|
102
85
|
|
103
86
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.7
|
105
88
|
signing_key:
|
106
89
|
specification_version: 3
|
107
|
-
summary:
|
108
|
-
test_files:
|
109
|
-
|
110
|
-
- test/test_rae.rb
|
90
|
+
summary: library to access the rae.es
|
91
|
+
test_files: []
|
92
|
+
|
data/test/helper.rb
DELETED