wwwjdic 13.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG +419 -0
- data/COPYING.md +675 -0
- data/Gemfile +21 -0
- data/README.md +303 -0
- data/Rakefile +52 -0
- data/acknowledgements.md +55 -0
- data/authors.md +67 -0
- data/copyright.md +377 -0
- data/examples/basics.rb +117 -0
- data/examples/translate.rb +128 -0
- data/examples/uri.rb +129 -0
- data/html/CHANGELOG.html +597 -0
- data/html/COPYING_md.html +389 -0
- data/html/Gemfile.html +104 -0
- data/html/Object.html +185 -0
- data/html/README_md.html +343 -0
- data/html/Rakefile.html +137 -0
- data/html/WWWJDic/ParsableDuckType.html +159 -0
- data/html/WWWJDic/Parser.html +233 -0
- data/html/WWWJDic/Parsers/Dict.html +191 -0
- data/html/WWWJDic/Parsers/Display.html +184 -0
- data/html/WWWJDic/Parsers/Key.html +221 -0
- data/html/WWWJDic/Parsers/Search.html +214 -0
- data/html/WWWJDic/Parsers/Server.html +182 -0
- data/html/WWWJDic/Parsers.html +96 -0
- data/html/WWWJDic/Splitter.html +378 -0
- data/html/WWWJDic/Utils/Downloader/Downloader.html +227 -0
- data/html/WWWJDic/Utils/Downloader.html +108 -0
- data/html/WWWJDic/Utils/Raisers.html +235 -0
- data/html/WWWJDic/Utils.html +108 -0
- data/html/WWWJDic/WWWJDic.html +715 -0
- data/html/WWWJDic.html +348 -0
- data/html/acknowledgements_md.html +149 -0
- data/html/authors_md.html +181 -0
- data/html/copyright_md.html +422 -0
- data/html/created.rid +59 -0
- data/html/css/fonts.css +167 -0
- data/html/css/rdoc.css +590 -0
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +363 -0
- data/html/js/darkfish.js +161 -0
- data/html/js/jquery.js +4 -0
- data/html/js/navigation.js +141 -0
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +109 -0
- data/html/js/search_index.js +1 -0
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +229 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +541 -0
- data/html/wwwjdic_gemspec.html +161 -0
- data/lib/wwwjdic/application.rb +233 -0
- data/lib/wwwjdic/constants.rb +113 -0
- data/lib/wwwjdic/locales/de.yml +29 -0
- data/lib/wwwjdic/locales/en.yml +29 -0
- data/lib/wwwjdic/locales/es.yml +29 -0
- data/lib/wwwjdic/locales/fr.yml +29 -0
- data/lib/wwwjdic/locales/hu.yml +29 -0
- data/lib/wwwjdic/locales/it.yml +29 -0
- data/lib/wwwjdic/locales/ja.yml +30 -0
- data/lib/wwwjdic/locales/nl.yml +29 -0
- data/lib/wwwjdic/locales/ru.yml +29 -0
- data/lib/wwwjdic/locales/sl.yml +29 -0
- data/lib/wwwjdic/locales/sv.yml +29 -0
- data/lib/wwwjdic/parser.rb +46 -0
- data/lib/wwwjdic/parsers/dict.rb +58 -0
- data/lib/wwwjdic/parsers/display.rb +50 -0
- data/lib/wwwjdic/parsers/key.rb +75 -0
- data/lib/wwwjdic/parsers/search.rb +60 -0
- data/lib/wwwjdic/parsers/server.rb +47 -0
- data/lib/wwwjdic/utils/downloader.rb +135 -0
- data/lib/wwwjdic/utils/raisers.rb +67 -0
- data/lib/wwwjdic/utils/splitter.rb +84 -0
- data/lib/wwwjdic/version.rb +20 -0
- data/lib/wwwjdic.rb +57 -0
- data/test/test_helper.rb +40 -0
- data/test/test_wwwjdic.rb +32 -0
- data/test/wwwjdic/locales/de.yml +22 -0
- data/test/wwwjdic/locales/en.yml +22 -0
- data/test/wwwjdic/locales/es.yml +22 -0
- data/test/wwwjdic/locales/fr.yml +22 -0
- data/test/wwwjdic/locales/hu.yml +22 -0
- data/test/wwwjdic/locales/it.yml +21 -0
- data/test/wwwjdic/locales/ja.yml +23 -0
- data/test/wwwjdic/locales/nl.yml +22 -0
- data/test/wwwjdic/locales/ru.yml +22 -0
- data/test/wwwjdic/locales/sl.yml +22 -0
- data/test/wwwjdic/locales/sv.yml +22 -0
- data/test/wwwjdic/locales/test_locales.rb +65 -0
- data/test/wwwjdic/parsers/test_dict.rb +73 -0
- data/test/wwwjdic/parsers/test_display.rb +51 -0
- data/test/wwwjdic/parsers/test_key.rb +52 -0
- data/test/wwwjdic/parsers/test_server.rb +51 -0
- data/test/wwwjdic/test_application.rb +219 -0
- data/test/wwwjdic/test_parsable_duck_type.rb +37 -0
- data/test/wwwjdic/utils/test_downloader.rb +41 -0
- data/test/wwwjdic/utils/test_raisers.rb +59 -0
- data/wwwjdic.gemspec +74 -0
- metadata +309 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::WWWJDic do
|
24
|
+
describe 'when using a parser' do
|
25
|
+
include WWWJDic::ParsableDuckType
|
26
|
+
|
27
|
+
before do
|
28
|
+
@parser = subject
|
29
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/wwwjdic/locales/', '*.yml')]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject {WWWJDic::Parsers::Dict.new}
|
33
|
+
|
34
|
+
describe 'when provided and invalid parameter' do
|
35
|
+
[nil, '', 42].each do |param|
|
36
|
+
it "shall raise and error for parameter '#{param}'" do
|
37
|
+
assert_raises ArgumentError do
|
38
|
+
subject.parse param
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'shall raise an error when wrong dictionary name' do
|
44
|
+
assert_raises ArgumentError do
|
45
|
+
subject.parse 'test'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'shall raise an error when wrong dictionary code' do
|
50
|
+
assert_raises ArgumentError do
|
51
|
+
subject.parse 'Z'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'when using the dictionary code/number' do
|
57
|
+
WWWJDic::DICTIONARY_CODES.each do |value|
|
58
|
+
it "shall return '#{value}' when parameter is '#{value}'" do
|
59
|
+
subject.parse(value).must_equal value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'when using the dictionary name' do
|
65
|
+
WWWJDic::DICTIONARY_NAMES.each do |value|
|
66
|
+
translated = WWWJDic::DICTS_BY_NAMES[value]
|
67
|
+
it "shall return '#{translated}' when parameter is '#{value}'" do
|
68
|
+
subject.parse(value).must_equal translated
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::WWWJDic do
|
24
|
+
describe 'when using a parser' do
|
25
|
+
include WWWJDic::ParsableDuckType
|
26
|
+
|
27
|
+
before do
|
28
|
+
@parser = subject
|
29
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/wwwjdic/locales/', '*.yml')]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject {WWWJDic::Parsers::Display.new}
|
33
|
+
|
34
|
+
describe 'when a valid display mode is selected' do
|
35
|
+
WWWJDic::DISPLAY.each do |key, value|
|
36
|
+
it "shall return '#{value}' when parameter is '#{key}'" do
|
37
|
+
subject.parse(key).must_equal key
|
38
|
+
WWWJDic::DISPLAY[subject.parse(key)].must_equal value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when an invalid display mode is selected' do
|
44
|
+
it 'shall raise an error' do
|
45
|
+
assert_raises ArgumentError do
|
46
|
+
subject.parse :xx
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::WWWJDic do
|
24
|
+
describe 'when using a parser' do
|
25
|
+
include WWWJDic::ParsableDuckType
|
26
|
+
|
27
|
+
before do
|
28
|
+
@parser = subject
|
29
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/wwwjdic/locales/', '*.yml')]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject {WWWJDic::Parsers::Key.new}
|
33
|
+
|
34
|
+
describe 'when provided and invalid parameter' do
|
35
|
+
[nil, '', 42].each do |param|
|
36
|
+
it "shall raise and error for parameter '#{param}'" do
|
37
|
+
assert_raises ArgumentError do
|
38
|
+
subject.parse param
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'when provided a key' do
|
45
|
+
WWWJDic::KEYS.each do |key, value|
|
46
|
+
it "shall return #{value} when parameter is #{key}" do
|
47
|
+
WWWJDic::KEYS[subject.parse(key)].must_equal value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::WWWJDic do
|
24
|
+
describe 'when using a parser' do
|
25
|
+
include WWWJDic::ParsableDuckType
|
26
|
+
|
27
|
+
before do
|
28
|
+
@parser = subject
|
29
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/wwwjdic/locales/', '*.yml')]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject {WWWJDic::Parsers::Server.new}
|
33
|
+
|
34
|
+
describe 'when a valid server is selected' do
|
35
|
+
WWWJDic::URIS.each do |key, value|
|
36
|
+
it "shall return '#{value}' when parameter is '#{key}'" do
|
37
|
+
subject.parse(key).must_equal key
|
38
|
+
WWWJDic::URIS[subject.parse(key)].must_equal value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when an invalid server is selected' do
|
44
|
+
it 'shall raise an error' do
|
45
|
+
assert_raises ArgumentError do
|
46
|
+
subject.parse :xx
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::WWWJDic do
|
24
|
+
describe 'when created' do
|
25
|
+
|
26
|
+
subject {WWWJDic::WWWJDic.new(WWWJDic::parser)}
|
27
|
+
|
28
|
+
# Basic checks for instance and default results
|
29
|
+
it 'shall return a valid object' do
|
30
|
+
subject.wont_be_nil
|
31
|
+
subject.must_be_instance_of WWWJDic::WWWJDic
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'shall return the URI with basic language' do
|
35
|
+
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
36
|
+
end
|
37
|
+
|
38
|
+
# Tests for server selection
|
39
|
+
describe 'when selecting a server' do
|
40
|
+
describe 'when an invalid server is selected' do
|
41
|
+
['', nil, :invalid].each do |a_server|
|
42
|
+
it 'shall raise an error' do
|
43
|
+
assert_raises ArgumentError do
|
44
|
+
subject.server = a_server
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'shall return the reference URI' do
|
49
|
+
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
WWWJDic::URIS.each do |name, uri|
|
55
|
+
describe "when server '#{name}' is selected" do
|
56
|
+
it "shall return the proper '#{uri}'" do
|
57
|
+
subject.server = name
|
58
|
+
subject.server.must_equal uri
|
59
|
+
subject.to_s.must_include uri
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Tests for dictionary selection
|
66
|
+
describe 'when selecting a dictionary' do
|
67
|
+
['', nil].each do |a_dict|
|
68
|
+
describe "when an invalid dictionary '#{a_dict}' is selected" do
|
69
|
+
it 'shall raise an error' do
|
70
|
+
assert_raises ArgumentError do
|
71
|
+
subject.dictionary = a_dict
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'shall return the reference URI' do
|
76
|
+
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
WWWJDic::DICTIONARY_CODES.each do |dict_number|
|
82
|
+
describe "when dictionary '#{dict_number}' is selected" do
|
83
|
+
it "shall return the proper number '#{dict_number}'" do
|
84
|
+
subject.dictionary = dict_number
|
85
|
+
subject.dictionary.must_equal WWWJDic::DICTS_BY_CODES[dict_number]
|
86
|
+
subject.to_s.must_equal WWWJDic::URI_DEFAULT + dict_number + WWWJDic::DISPLAY[:regular]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'shall return the URI with basic dictionary when reset' do
|
92
|
+
subject.dictionary = 'R'
|
93
|
+
subject.reset
|
94
|
+
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
95
|
+
subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
|
96
|
+
end
|
97
|
+
|
98
|
+
WWWJDic::DICTIONARY_NAMES.each do |dict_name|
|
99
|
+
describe "when dictionary '#{dict_name}' is selected" do
|
100
|
+
it "shall return the proper name '#{dict_name}'" do
|
101
|
+
subject.dictionary = dict_name
|
102
|
+
subject.dictionary.must_equal dict_name
|
103
|
+
subject.to_s.must_equal WWWJDic::URI_DEFAULT + WWWJDic::DICTS_BY_NAMES[dict_name] + WWWJDic::DISPLAY[:regular]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'shall return the URI with basic dictionary when reset' do
|
109
|
+
subject.dictionary = 'Japanese-Italian'
|
110
|
+
subject.reset
|
111
|
+
subject.to_s.must_equal WWWJDic::TEST_REFERENCE_URI
|
112
|
+
subject.dictionary.must_equal WWWJDic::DICTIONARY_NAMES[0]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Tests for translations
|
117
|
+
describe 'when asking for a translation' do
|
118
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../lib/wwwjdic/locales/', '*.yml')]
|
119
|
+
|
120
|
+
# Tests for translation URIs
|
121
|
+
describe 'when asking for URI' do
|
122
|
+
['', nil].each do |a_word|
|
123
|
+
describe "when providing an invalid parameter '#{a_word}'" do
|
124
|
+
[:uri, :raw_uri, :json_uri].each do |a_method|
|
125
|
+
it "shall raise an error for #{a_method} request" do
|
126
|
+
assert_raises ArgumentError do
|
127
|
+
subject.send a_method
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'when considering multiple languages' do
|
135
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
136
|
+
I18n.locale = dict.to_s
|
137
|
+
a_word = I18n.t('test.kotoba')
|
138
|
+
|
139
|
+
[:uri, :raw_uri, :json_uri].each do |a_method|
|
140
|
+
it "shall return URI containing '#{number}' for a '#{dict}' word for '#{a_method}' request" do
|
141
|
+
subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include number
|
142
|
+
end
|
143
|
+
|
144
|
+
it "shall return URI containing '#{a_word}' for a '#{dict}' word for '#{a_method}' request" do
|
145
|
+
subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict]).must_include CGI::escape(a_word).to_s
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'shall override user-custom display parameter for raw display' do
|
150
|
+
subject.raw_uri(a_word, display: :regular, dict: WWWJDic::AVAIL_LANGS[dict]).must_include WWWJDic::DISPLAY[:raw]
|
151
|
+
end
|
152
|
+
|
153
|
+
it "shall return correct JSON data containing '#{a_word}' and the proper URI" do
|
154
|
+
json = subject.json_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
155
|
+
an_uri = subject.uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
156
|
+
|
157
|
+
JSON.parse(json).keys.must_include a_word
|
158
|
+
JSON.parse(json)[a_word].must_equal an_uri
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Tests for translation URIs
|
166
|
+
describe 'when asking to retrieve a translation' do
|
167
|
+
[:translate, :json_translate].each do |a_method|
|
168
|
+
describe "when the translation is '#{a_method}'" do
|
169
|
+
['', nil].each do |a_word|
|
170
|
+
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed" do
|
171
|
+
assert_raises ArgumentError do
|
172
|
+
subject.send(a_method, a_word)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it "shall raise ArgumentError when an invalid word '#{a_word}' is proposed, for raw display" do
|
177
|
+
assert_raises ArgumentError do
|
178
|
+
subject.send(a_method, a_word)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'when considering multiple languages' do
|
184
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../lib/wwwjdic/locales/', '*.yml')]
|
185
|
+
|
186
|
+
WWWJDic::AVAIL_LANGS.each_pair do |dict, number|
|
187
|
+
I18n.locale = dict.to_s
|
188
|
+
a_word = I18n.t('test.kotoba')
|
189
|
+
|
190
|
+
it 'shall create a saved file with the proper filename' do
|
191
|
+
filename = "File_#{a_word}"
|
192
|
+
subject.send(a_method, a_word, nil, filename)
|
193
|
+
File.exist?(filename).must_equal true
|
194
|
+
File.delete filename
|
195
|
+
end
|
196
|
+
|
197
|
+
it "shall return the translated word '#{a_word}'" do
|
198
|
+
translation = subject.send(a_method, a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
199
|
+
translation.wont_be_nil
|
200
|
+
translation.wont_be_empty
|
201
|
+
|
202
|
+
if a_method == :json_translate
|
203
|
+
JSON.parse(translation).wont_include '<TITLE>'
|
204
|
+
JSON.parse(translation).wont_include '<pre>'
|
205
|
+
JSON.parse(translation).keys.must_include a_word
|
206
|
+
|
207
|
+
an_uri = subject.raw_uri(a_word, dict: WWWJDic::AVAIL_LANGS[dict])
|
208
|
+
an_uri.must_include number
|
209
|
+
|
210
|
+
JSON.parse(translation)[a_word].must_equal an_uri
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
module WWWJDic
|
22
|
+
|
23
|
+
# This module represents the parsable duck type element for testing
|
24
|
+
# purposes.
|
25
|
+
#
|
26
|
+
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
27
|
+
# Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
28
|
+
# License:: GNU General Public License version 3
|
29
|
+
module ParsableDuckType
|
30
|
+
|
31
|
+
# The method that tests the parsable duck type interface and its
|
32
|
+
# +parse+ method.
|
33
|
+
def test_parsable_duck_type
|
34
|
+
subject.must_respond_to :parse unless subject.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe WWWJDic::Utils::Downloader do
|
24
|
+
describe 'when passed a nil uri' do
|
25
|
+
it 'must raise a RuntimeError' do
|
26
|
+
assert_raises RuntimeError do
|
27
|
+
I18n.enforce_available_locales = false
|
28
|
+
WWWJDic::Utils::Downloader::Downloader.download_file nil, 'filename'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'when passed an invalid uri' do
|
34
|
+
it 'must raise a InvalidURIError' do
|
35
|
+
assert_raises URI::InvalidURIError do
|
36
|
+
I18n.enforce_available_locales = false
|
37
|
+
WWWJDic::Utils::Downloader::Downloader.download_file 'http://example.com/%uABCD', 'filename'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#--
|
2
|
+
# wwwjdic
|
3
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of wwwjdic.
|
6
|
+
#
|
7
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
|
24
|
+
describe WWWJDic::Utils::Raisers do
|
25
|
+
include WWWJDic::Utils::Raisers
|
26
|
+
|
27
|
+
before do
|
28
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/../../../lib/wwwjdic/locales/', '*.yml')]
|
29
|
+
I18n.locale = 'it'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when running any raiser method' do
|
33
|
+
it 'does not raise an ArgumentError when value is nil or in the array' do
|
34
|
+
all_methods = Hash.new
|
35
|
+
all_methods[:raiser_downcase] = [[nil, nil], ['value', ['value']]]
|
36
|
+
all_methods[:raiser_to_i] = [[nil, nil], ['42', [42]]]
|
37
|
+
|
38
|
+
all_methods.each_key do |method_name|
|
39
|
+
a_method = self.method method_name
|
40
|
+
all_methods[method_name.to_sym].each do |params|
|
41
|
+
a_method.call 'error.value', params[0], params[1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'raises ArgumentError when value is not nil and not in the array' do
|
47
|
+
all_methods = Hash.new
|
48
|
+
all_methods[:raiser_downcase] = ['value', ['no value']]
|
49
|
+
all_methods[:raiser_to_i] = ['42', [47]]
|
50
|
+
|
51
|
+
all_methods.each_key do |method_name|
|
52
|
+
a_method = self.method method_name
|
53
|
+
assert_raises ArgumentError do
|
54
|
+
a_method.call 'error.value', all_methods[method_name.to_sym][0], all_methods[method_name.to_sym][1]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/wwwjdic.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# wwwjdic
|
2
|
+
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
3
|
+
#
|
4
|
+
# This file is part of wwwjdic.
|
5
|
+
#
|
6
|
+
# wwwjdic is free software: you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU General Public License as published by the
|
8
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
9
|
+
# option) any later version.
|
10
|
+
#
|
11
|
+
# wwwjdic is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
+
# for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require_relative 'lib/wwwjdic/version'
|
20
|
+
|
21
|
+
SUMMARY = 'This gem uses WWWJDic Backdoor Entry/API as described by
|
22
|
+
http://www.edrdg.org/wwwjdic/wwwjdicinf.html#backdoor_tag to to
|
23
|
+
interact with WWWJDic and translate to and from Japanese language.'
|
24
|
+
|
25
|
+
Gem::Specification.new do |a_gem|
|
26
|
+
a_gem.name = 'wwwjdic'
|
27
|
+
a_gem.version = WWWJDic::VERSION
|
28
|
+
a_gem.license = 'GPL-3.0'
|
29
|
+
a_gem.licenses = %w(GPL-3.0 BSD-3-Clause)
|
30
|
+
a_gem.author = 'Marco Bresciani'
|
31
|
+
a_gem.authors = ['Marco Bresciani', '新部裕', 'Jon Maken']
|
32
|
+
a_gem.email = 'marcobresciani_1974@libero.it'
|
33
|
+
a_gem.homepage = 'https://savannah.nongnu.org/projects/wwwjdic/'
|
34
|
+
a_gem.summary = SUMMARY
|
35
|
+
a_gem.description = "#{SUMMARY} WWWJDic is an online Japanese
|
36
|
+
translation server made by Jim Breen and available at
|
37
|
+
http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C. GNU GPLv3 license;
|
38
|
+
source code available through anonymous checkout: `hg clone
|
39
|
+
http://hg.savannah.nongnu.org/hgweb/wwwjdic/` or write me and I'll send
|
40
|
+
it. You can even decide to contribute to this little free software
|
41
|
+
project by registering to Savannah and ask to be part of the 'wwwjdic'
|
42
|
+
project!"
|
43
|
+
|
44
|
+
COMMON_FILES = %w(acknowledgements.md authors.md CHANGELOG COPYING.md
|
45
|
+
copyright.md Gemfile wwwjdic.gemspec Rakefile README.md) #ISSUES.md
|
46
|
+
|
47
|
+
a_gem.files = Dir.glob('{examples,html,lib,test}/**/*') + COMMON_FILES
|
48
|
+
a_gem.test_files = Dir.glob('test/**/test_*.rb')
|
49
|
+
a_gem.require_path = 'lib'
|
50
|
+
a_gem.require_paths = %w(lib)
|
51
|
+
a_gem.extra_rdoc_files = COMMON_FILES
|
52
|
+
|
53
|
+
a_gem.required_ruby_version = '~> 2.6'
|
54
|
+
a_gem.rubygems_version = '~> 3.0'
|
55
|
+
|
56
|
+
a_gem.add_runtime_dependency 'i18n', '~>1.6'
|
57
|
+
a_gem.add_runtime_dependency 'json', '~>2.2'
|
58
|
+
|
59
|
+
a_gem.add_development_dependency 'bundler', '~>2.0'
|
60
|
+
a_gem.add_development_dependency 'minitest', '~>5.11'
|
61
|
+
a_gem.add_development_dependency 'rake', '~>12.3'
|
62
|
+
a_gem.add_development_dependency 'rdoc', '~>6.1'
|
63
|
+
a_gem.add_development_dependency 'simplecov', '~>0.16'
|
64
|
+
|
65
|
+
a_gem.requirements = a_gem.required_ruby_version.to_s, a_gem.dependencies.to_s
|
66
|
+
|
67
|
+
begin
|
68
|
+
require 'changelog'
|
69
|
+
rescue LoadError
|
70
|
+
a_gem.post_install_message = "Thank you for using #{a_gem.name} version #{a_gem.version}."
|
71
|
+
else
|
72
|
+
a_gem.post_install_message = CHANGELOG.new.version_changes
|
73
|
+
end
|
74
|
+
end
|