nebrija 0.0.0 → 0.0.1
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 +12 -3
- data/lib/nebrija/parser.rb +20 -8
- data/test/test_basic.rb +14 -14
- metadata +4 -4
data/Rakefile
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
|
3
3
|
Rake::TestTask.new do |t|
|
4
|
-
|
5
|
-
|
4
|
+
t.libs << 'test'
|
5
|
+
t.test_files = FileList['test/test*.rb']
|
6
6
|
end
|
7
7
|
|
8
|
-
desc
|
8
|
+
desc 'Run tests'
|
9
9
|
task :default => :test
|
10
|
+
|
11
|
+
desc 'Publish gem'
|
12
|
+
task :publish do
|
13
|
+
puts 'Building gem...'
|
14
|
+
puts `gem build nebrija.gemspec`
|
15
|
+
puts
|
16
|
+
puts 'Uploading gem...'
|
17
|
+
puts `gem push nebrija-0.0.0.gem`
|
18
|
+
end
|
data/lib/nebrija/parser.rb
CHANGED
@@ -13,13 +13,9 @@ class Parser
|
|
13
13
|
|
14
14
|
def parse
|
15
15
|
|
16
|
-
return {:error => 'Word does not exist. Sorry.'} if !valid?
|
16
|
+
return {:status => 'error', :message => 'Word does not exist. Sorry.'} if !valid?
|
17
|
+
perform
|
17
18
|
|
18
|
-
if single?
|
19
|
-
parse_single
|
20
|
-
else
|
21
|
-
parse_multiple
|
22
|
-
end
|
23
19
|
end
|
24
20
|
|
25
21
|
def single?
|
@@ -63,7 +59,7 @@ class Parser
|
|
63
59
|
@doc.css('body > ul > li > a').each do |word|
|
64
60
|
multiple_result << {
|
65
61
|
:word => word.css('span').first.inner_text,
|
66
|
-
:
|
62
|
+
:id => word['href'].gsub(/search\?id=/, '')
|
67
63
|
}
|
68
64
|
end
|
69
65
|
multiple_result
|
@@ -72,4 +68,20 @@ class Parser
|
|
72
68
|
def valid?
|
73
69
|
(@doc.css('title').inner_text =~/error/).nil?
|
74
70
|
end
|
75
|
-
|
71
|
+
|
72
|
+
def perform
|
73
|
+
response = nil
|
74
|
+
type = 'single'
|
75
|
+
if single?
|
76
|
+
response = parse_single
|
77
|
+
else
|
78
|
+
response = parse_multiple
|
79
|
+
type = 'multiple'
|
80
|
+
end
|
81
|
+
{
|
82
|
+
:status => 'success',
|
83
|
+
:type => type,
|
84
|
+
:response => response
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
data/test/test_basic.rb
CHANGED
@@ -6,27 +6,27 @@ MOCKS_DIR = "#{Dir.pwd}/test/mocks"
|
|
6
6
|
class TestMockedParserBasic < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def test_error_basic
|
9
|
-
|
9
|
+
assert_equal FileRae.new.search("#{MOCKS_DIR}/error.html")[:status]
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_single_basic
|
13
|
-
assert_not_nil FileRae.new.search("#{MOCKS_DIR}/single.html")[:data]
|
13
|
+
assert_not_nil FileRae.new.search("#{MOCKS_DIR}/single.html")[:response][:data]
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_multiple_basic
|
17
|
-
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html").length == 2
|
17
|
+
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html")[:reponse].length == 2
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
class TestMockedParserContent < Test::Unit::TestCase
|
22
22
|
|
23
23
|
def test_single_basic
|
24
|
-
assert FileRae.new.search("#{MOCKS_DIR}/single.html")[:data].length > 20
|
24
|
+
assert FileRae.new.search("#{MOCKS_DIR}/single.html")[:response][:data].length > 20
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_multiple_basic
|
28
|
-
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html")[0][:word] == 'bancar'
|
29
|
-
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html")[1][:word] == 'banco'
|
28
|
+
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html")[:response][0][:word] == 'bancar'
|
29
|
+
assert FileRae.new.search("#{MOCKS_DIR}/multiple.html")[:response][1][:word] == 'banco'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,30 +34,30 @@ end
|
|
34
34
|
class TestMockedParserBasic < Test::Unit::TestCase
|
35
35
|
|
36
36
|
def test_single_basic_id
|
37
|
-
assert_not_nil HTTPRae.new.search('MHpGWYJ6YDXX2bw9Ghwm')[:data]
|
37
|
+
assert_not_nil HTTPRae.new.search('MHpGWYJ6YDXX2bw9Ghwm')[:response][:data]
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_error_basic
|
41
|
-
|
41
|
+
assert HTTPRae.new.search('jddhfgsd')[:status] == 'error'
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_single_basic
|
45
|
-
assert_not_nil HTTPRae.new.search('a')[:data]
|
45
|
+
assert_not_nil HTTPRae.new.search('a')[:response][:data]
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_multiple_basic
|
49
|
-
assert HTTPRae.new.search('banco').length == 2
|
49
|
+
assert HTTPRae.new.search('banco')[:response].length == 2
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
class TestParserContent < Test::Unit::TestCase
|
54
54
|
|
55
55
|
def test_single_basic
|
56
|
-
assert HTTPRae.new.search('a')[:data].length > 4
|
56
|
+
assert HTTPRae.new.search('a')[:response][:data].length > 4
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_multiple_basic
|
60
|
-
assert HTTPRae.new.search('banco')[0][:word] == 'bancar'
|
61
|
-
assert HTTPRae.new.search('banco')[1][:word] == 'banco'
|
60
|
+
assert HTTPRae.new.search('banco')[:response][0][:word] == 'bancar'
|
61
|
+
assert HTTPRae.new.search('banco')[:response][1][:word] == 'banco'
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nebrija
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
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: 2014-07-
|
12
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
description: A gem to access the rae dictionary
|
63
|
-
email:
|
63
|
+
email: javierhonduco@gmail.com
|
64
64
|
executables:
|
65
65
|
- nebrija
|
66
66
|
extensions: []
|
@@ -95,6 +95,6 @@ rubyforge_project:
|
|
95
95
|
rubygems_version: 1.8.23
|
96
96
|
signing_key:
|
97
97
|
specification_version: 3
|
98
|
-
summary:
|
98
|
+
summary: This gem provides access to the rae webpage
|
99
99
|
test_files:
|
100
100
|
- test/test_basic.rb
|