rae 0.1.0 → 1.1.2
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 +2 -3
- data/Rakefile +9 -6
- data/bin/rae +76 -5
- data/lib/rae.rb +0 -63
- data/test/helper.rb +10 -0
- data/test/test_rae.rb +7 -0
- metadata +44 -26
- data/VERSION +0 -1
- data/rae.gemspec +0 -51
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -9,10 +9,9 @@ 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
|
13
|
-
bump version in a commit by itself I can ignore when I pull)
|
12
|
+
(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)
|
14
13
|
* Send me a pull request. Bonus points for topic branches.
|
15
14
|
|
16
15
|
== Copyright
|
17
16
|
|
18
|
-
Copyright (c)
|
17
|
+
Copyright (c) 2010 Koldo Oteo. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,12 +5,15 @@ 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 = ["
|
13
|
-
gem.
|
8
|
+
gem.summary = %Q{CLI to access the rae.es}
|
9
|
+
gem.description = %Q{CLI to access the rae.es}
|
10
|
+
gem.email = "koldo.oteo1@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/koteo/rae"
|
12
|
+
gem.authors = ["Koldo Oteo"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
|
15
|
+
gem.add_dependency('mechanize', '>= 0.9.3')
|
16
|
+
gem.add_dependency('nokogiri', '>= 1.3.3')
|
14
17
|
end
|
15
18
|
Jeweler::GemcutterTasks.new
|
16
19
|
rescue LoadError
|
data/bin/rae
CHANGED
@@ -1,10 +1,81 @@
|
|
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'
|
2
23
|
|
3
|
-
$:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
-
require 'rae'
|
5
24
|
|
6
|
-
|
25
|
+
class Rae
|
7
26
|
|
8
|
-
|
9
|
-
|
27
|
+
def pide_pal
|
28
|
+
@pal = ARGV.first
|
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
|
10
73
|
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
@@ -1,63 +0,0 @@
|
|
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/test/helper.rb
ADDED
data/test/test_rae.rb
ADDED
metadata
CHANGED
@@ -1,42 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
|
-
- 0
|
8
6
|
- 1
|
9
|
-
-
|
10
|
-
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 1.1.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
|
-
- David A. Cuadrado
|
14
12
|
- Koldo Oteo
|
15
13
|
autorequire:
|
16
14
|
bindir: bin
|
17
15
|
cert_chain: []
|
18
16
|
|
19
|
-
date: 2010-
|
17
|
+
date: 2010-03-12 00:00:00 +01:00
|
20
18
|
default_executable: rae
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
23
|
-
name:
|
21
|
+
name: thoughtbot-shoulda
|
24
22
|
prerelease: false
|
25
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 23
|
31
27
|
segments:
|
32
|
-
- 1
|
33
28
|
- 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:
|
34
40
|
- 0
|
35
|
-
|
41
|
+
- 9
|
42
|
+
- 3
|
43
|
+
version: 0.9.3
|
36
44
|
type: :runtime
|
37
|
-
version_requirements: *
|
38
|
-
|
39
|
-
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
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
|
40
62
|
executables:
|
41
63
|
- rae
|
42
64
|
extensions: []
|
@@ -50,12 +72,11 @@ files:
|
|
50
72
|
- LICENSE
|
51
73
|
- README.rdoc
|
52
74
|
- Rakefile
|
53
|
-
- VERSION
|
54
|
-
- bin/rae
|
55
75
|
- lib/rae.rb
|
56
|
-
-
|
76
|
+
- test/helper.rb
|
77
|
+
- test/test_rae.rb
|
57
78
|
has_rdoc: true
|
58
|
-
homepage: http://github.com/
|
79
|
+
homepage: http://github.com/koteo/rae
|
59
80
|
licenses: []
|
60
81
|
|
61
82
|
post_install_message:
|
@@ -64,29 +85,26 @@ rdoc_options:
|
|
64
85
|
require_paths:
|
65
86
|
- lib
|
66
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
88
|
requirements:
|
69
89
|
- - ">="
|
70
90
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
91
|
segments:
|
73
92
|
- 0
|
74
93
|
version: "0"
|
75
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
95
|
requirements:
|
78
96
|
- - ">="
|
79
97
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
98
|
segments:
|
82
99
|
- 0
|
83
100
|
version: "0"
|
84
101
|
requirements: []
|
85
102
|
|
86
103
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.6
|
88
105
|
signing_key:
|
89
106
|
specification_version: 3
|
90
|
-
summary:
|
91
|
-
test_files:
|
92
|
-
|
107
|
+
summary: CLI to access the rae.es
|
108
|
+
test_files:
|
109
|
+
- test/helper.rb
|
110
|
+
- test/test_rae.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|
data/rae.gemspec
DELETED
@@ -1,51 +0,0 @@
|
|
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 = "0.1.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
|
-
|