wwwjdic 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +19 -0
- data/Gemfile +5 -1
- data/README.md +461 -192
- data/Rakefile +7 -2
- data/copyright.md +17 -29
- data/examples/basics.rb +51 -45
- data/examples/translate.rb +135 -86
- data/examples/uri.rb +34 -78
- data/html/CHANGELOG.html +48 -31
- data/html/COPYING_md.html +31 -35
- data/html/Gemfile.html +28 -32
- data/html/Object.html +71 -71
- data/html/README_md.html +326 -159
- data/html/Rakefile.html +29 -33
- data/html/WWWJDic.html +137 -98
- data/html/WWWJDic/ParsableDuckType.html +55 -55
- data/html/WWWJDic/Parser.html +88 -88
- data/html/WWWJDic/Parsers.html +33 -33
- data/html/WWWJDic/Parsers/Dict.html +71 -73
- data/html/WWWJDic/Parsers/Display.html +66 -66
- data/html/WWWJDic/Parsers/Key.html +67 -67
- data/html/WWWJDic/Parsers/Search.html +59 -58
- data/html/WWWJDic/Parsers/Server.html +66 -66
- data/html/WWWJDic/Splitter.html +173 -172
- data/html/WWWJDic/Utils.html +34 -34
- data/html/WWWJDic/Utils/Downloader.html +33 -33
- data/html/WWWJDic/Utils/Downloader/Downloader.html +91 -89
- data/html/WWWJDic/Utils/Raisers.html +95 -95
- data/html/WWWJDic/WWWJDic.html +343 -345
- data/html/copyright_md.html +37 -51
- data/html/created.rid +55 -57
- data/html/index.html +334 -164
- data/html/js/darkfish.js +84 -84
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +110 -110
- data/html/js/search_index.js +1 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +229 -229
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +44 -75
- data/lib/wwwjdic.rb +7 -11
- data/lib/wwwjdic/application.rb +13 -7
- data/lib/wwwjdic/constants.rb +16 -8
- data/lib/wwwjdic/locales/de.yml +5 -4
- data/lib/wwwjdic/locales/en.yml +5 -4
- data/lib/wwwjdic/locales/es.yml +5 -4
- data/lib/wwwjdic/locales/fr.yml +6 -4
- data/lib/wwwjdic/locales/hu.yml +6 -4
- data/lib/wwwjdic/locales/it.yml +6 -4
- data/lib/wwwjdic/locales/ja.yml +8 -4
- data/lib/wwwjdic/locales/nl.yml +5 -4
- data/lib/wwwjdic/locales/ru.yml +5 -4
- data/lib/wwwjdic/locales/sl.yml +5 -4
- data/lib/wwwjdic/locales/sv.yml +5 -4
- data/lib/wwwjdic/parser.rb +8 -4
- data/lib/wwwjdic/parsers/dict.rb +9 -7
- data/lib/wwwjdic/parsers/display.rb +6 -2
- data/lib/wwwjdic/parsers/key.rb +8 -3
- data/lib/wwwjdic/parsers/search.rb +8 -3
- data/lib/wwwjdic/parsers/server.rb +6 -2
- data/lib/wwwjdic/utils/downloader.rb +21 -23
- data/lib/wwwjdic/utils/raisers.rb +7 -3
- data/lib/wwwjdic/utils/splitter.rb +20 -14
- data/lib/wwwjdic/version.rb +2 -6
- data/test/test_helper.rb +5 -1
- data/test/test_wwwjdic.rb +6 -2
- data/test/wwwjdic/locales/de.yml +7 -1
- data/test/wwwjdic/locales/en.yml +7 -1
- data/test/wwwjdic/locales/es.yml +7 -1
- data/test/wwwjdic/locales/fr.yml +7 -1
- data/test/wwwjdic/locales/hu.yml +7 -1
- data/test/wwwjdic/locales/it.yml +10 -3
- data/test/wwwjdic/locales/ja.yml +9 -2
- data/test/wwwjdic/locales/nl.yml +7 -1
- data/test/wwwjdic/locales/ru.yml +7 -1
- data/test/wwwjdic/locales/sl.yml +7 -1
- data/test/wwwjdic/locales/sv.yml +7 -1
- data/test/wwwjdic/locales/test_locales.rb +12 -9
- data/test/wwwjdic/parsers/test_dict.rb +6 -2
- data/test/wwwjdic/parsers/test_display.rb +6 -2
- data/test/wwwjdic/parsers/test_key.rb +6 -2
- data/test/wwwjdic/parsers/test_server.rb +6 -2
- data/test/wwwjdic/test_application.rb +12 -8
- data/test/wwwjdic/test_parsable_duck_type.rb +6 -2
- data/test/wwwjdic/utils/test_downloader.rb +5 -1
- data/test/wwwjdic/utils/test_raisers.rb +10 -6
- data/wwwjdic.gemspec +30 -14
- metadata +50 -22
- data/acknowledgements.md +0 -55
- data/authors.md +0 -67
- data/html/acknowledgements_md.html +0 -150
- data/html/authors_md.html +0 -182
data/lib/wwwjdic/locales/fr.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,7 +16,12 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
24
|
+
|
20
25
|
fr:
|
21
26
|
error:
|
22
27
|
nil: paramètre nul pas autorisé.
|
@@ -25,6 +30,3 @@ fr:
|
|
25
30
|
value: "Valeur %{value} n'est pas dans la plage autorisée."
|
26
31
|
warn:
|
27
32
|
deprecated: Cette méthode a été déconseillée.
|
28
|
-
test:
|
29
|
-
kotoba: mot
|
30
|
-
test: test data
|
data/lib/wwwjdic/locales/hu.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,7 +16,12 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
24
|
+
|
20
25
|
hu:
|
21
26
|
error:
|
22
27
|
nil: nulla paraméter nem megengedett.
|
@@ -25,6 +30,3 @@ hu:
|
|
25
30
|
value: "Érték %{value} nem a megengedett tartományban."
|
26
31
|
warn:
|
27
32
|
deprecated: Ez a módszer már elavult.
|
28
|
-
test:
|
29
|
-
kotoba: hír
|
30
|
-
test: test data
|
data/lib/wwwjdic/locales/it.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,7 +16,12 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
24
|
+
|
20
25
|
it:
|
21
26
|
error:
|
22
27
|
nil: Parametro nil non consentito.
|
@@ -25,6 +30,3 @@ it:
|
|
25
30
|
value: "Il valore %{value} non è nell'intervallo previsto."
|
26
31
|
warn:
|
27
32
|
deprecated: Questo metodo è obsoleto.
|
28
|
-
test:
|
29
|
-
kotoba: parola
|
30
|
-
test: dato di prova
|
data/lib/wwwjdic/locales/ja.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# (C) 2013 新部裕
|
4
|
+
# © 2014 Marco Bresciani
|
4
5
|
#
|
5
6
|
# This file is part of wwwjdic.
|
6
7
|
#
|
@@ -16,7 +17,13 @@
|
|
16
17
|
#
|
17
18
|
# You should have received a copy of the GNU General Public License
|
18
19
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
#
|
21
|
+
# SPDX-FileCopyrightText: 2013 新部裕
|
22
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
23
|
+
#
|
24
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
25
|
#++
|
26
|
+
|
20
27
|
ja:
|
21
28
|
error:
|
22
29
|
nil: nil パラメータは許されません。
|
@@ -25,6 +32,3 @@ ja:
|
|
25
32
|
value: "値 %{value} が範囲外です。"
|
26
33
|
warn:
|
27
34
|
deprecated: このメソッドはすでに廃止され、推奨されていません。
|
28
|
-
test:
|
29
|
-
kotoba: 言葉
|
30
|
-
test: 試験データ
|
data/lib/wwwjdic/locales/nl.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
nl:
|
@@ -26,6 +30,3 @@ nl:
|
|
26
30
|
value: "Waarde %{value} is niet in toegestane bereik."
|
27
31
|
warn:
|
28
32
|
deprecated: Deze methode is verouderd.
|
29
|
-
test:
|
30
|
-
kotoba: taal
|
31
|
-
test: test data
|
data/lib/wwwjdic/locales/ru.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
ru:
|
@@ -26,6 +30,3 @@ ru:
|
|
26
30
|
value: "Значение %{value} не в допустимом диапазоне."
|
27
31
|
warn:
|
28
32
|
deprecated: Этот метод является устаревшим.
|
29
|
-
test:
|
30
|
-
kotoba: слово
|
31
|
-
test: test data
|
data/lib/wwwjdic/locales/sl.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
sl:
|
@@ -26,6 +30,3 @@ sl:
|
|
26
30
|
value: "Vrednost %{value} ni v dovoljenem obsegu."
|
27
31
|
warn:
|
28
32
|
deprecated: Ta metoda je bila opuščena.
|
29
|
-
test:
|
30
|
-
kotoba: beseda
|
31
|
-
test: test data
|
data/lib/wwwjdic/locales/sv.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
sv:
|
@@ -26,6 +30,3 @@ sv:
|
|
26
30
|
value: "Värde %{value} är inte tillåtet intervall."
|
27
31
|
warn:
|
28
32
|
deprecated: Denna metod har föråldrad.
|
29
|
-
test:
|
30
|
-
kotoba: ord
|
31
|
-
test: test data
|
data/lib/wwwjdic/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
require_relative 'constants'
|
@@ -26,13 +30,13 @@ module WWWJDic
|
|
26
30
|
# parameters for wwwjdic.
|
27
31
|
#
|
28
32
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
29
|
-
# Copyright::
|
33
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
30
34
|
# License:: GNU General Public License version 3
|
31
35
|
class Parser
|
32
36
|
attr_reader :parsers
|
33
37
|
|
34
38
|
def initialize(args = {})
|
35
|
-
@parsers =
|
39
|
+
@parsers = {}
|
36
40
|
ALL_PARAMS.each { |param| parsers[param] = args[param] } unless args.nil?
|
37
41
|
end
|
38
42
|
|
@@ -40,7 +44,7 @@ module WWWJDic
|
|
40
44
|
def parse(method = nil, value = nil)
|
41
45
|
a_parser = nil
|
42
46
|
a_parser = parsers[method.to_sym] unless method.nil? or parsers.nil?
|
43
|
-
a_parser
|
47
|
+
a_parser&.parse value
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
data/lib/wwwjdic/parsers/dict.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
require_relative '../constants'
|
@@ -32,7 +36,7 @@ module WWWJDic
|
|
32
36
|
# source of one of the pages to get the full list of codes.)
|
33
37
|
#
|
34
38
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
35
|
-
# Copyright::
|
39
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
36
40
|
# License:: GNU General Public License version 3
|
37
41
|
class Dict
|
38
42
|
include Utils::Raisers
|
@@ -46,11 +50,9 @@ module WWWJDic
|
|
46
50
|
if value.length == 1
|
47
51
|
raiser_array('error.param', value, DICTIONARY_CODES)
|
48
52
|
value
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
DICTS_BY_NAMES[value]
|
53
|
-
end
|
53
|
+
elsif value.length > 1
|
54
|
+
raiser_array('error.param', value, DICTIONARY_NAMES)
|
55
|
+
DICTS_BY_NAMES[value]
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
require_relative '../constants'
|
@@ -31,7 +35,7 @@ module WWWJDic
|
|
31
35
|
# dictionary display)
|
32
36
|
#
|
33
37
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
34
|
-
# Copyright::
|
38
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
35
39
|
# License:: GNU General Public License version 3
|
36
40
|
class Display
|
37
41
|
include Utils::Raisers
|
data/lib/wwwjdic/parsers/key.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,12 +16,17 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
require_relative '../constants'
|
22
26
|
|
23
27
|
module WWWJDic
|
24
28
|
module Parsers
|
29
|
+
|
25
30
|
# This class is an implementation of the Parsable duck type that
|
26
31
|
# checks the display type. The only needed parameter is the word to
|
27
32
|
# translate.
|
@@ -56,13 +61,13 @@ module WWWJDic
|
|
56
61
|
# displayed.
|
57
62
|
#
|
58
63
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
59
|
-
# Copyright::
|
64
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
60
65
|
# License:: GNU General Public License version 3
|
61
66
|
class Key
|
62
67
|
include Utils::Raisers
|
63
68
|
|
64
69
|
# The parsable duck type interface to every parser usage.
|
65
|
-
def parse(value = :
|
70
|
+
def parse(value = :english)
|
66
71
|
raise ArgumentError, I18n.t('error.nil') if value.nil?
|
67
72
|
raise ArgumentError, I18n.t('error.param', value: value) unless value.is_a? Symbol
|
68
73
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
module WWWJDic
|
@@ -47,12 +51,13 @@ module WWWJDic
|
|
47
51
|
# * for example sentence lookups using a regular expression, use T.
|
48
52
|
#
|
49
53
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
50
|
-
# Copyright::
|
54
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
51
55
|
# License:: GNU General Public License version 3
|
52
56
|
class Search
|
53
57
|
# The parsable duck type interface to every parser usage.
|
54
58
|
def parse(value = '')
|
55
|
-
return 'D' if value == CGI
|
59
|
+
return 'D' if value == CGI.escape(value).to_s
|
60
|
+
|
56
61
|
'U'
|
57
62
|
end
|
58
63
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2014 Marco Bresciani
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
19
23
|
#++
|
20
24
|
|
21
25
|
require_relative '../constants'
|
@@ -28,7 +32,7 @@ module WWWJDic
|
|
28
32
|
# with +true+ for regular.
|
29
33
|
#
|
30
34
|
# Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
|
31
|
-
# Copyright::
|
35
|
+
# Copyright:: (C) 2014 Marco Bresciani
|
32
36
|
# License:: GNU General Public License version 3
|
33
37
|
class Server
|
34
38
|
include Utils::Raisers
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# wwwjdic
|
3
|
-
#
|
3
|
+
# © 2014 Marco Bresciani
|
4
4
|
#
|
5
5
|
# This file is part of wwwjdic.
|
6
6
|
#
|
@@ -16,6 +16,10 @@
|
|
16
16
|
#
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with wwwjdic. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# SPDX-FileCopyrightText: 2012 Jon Maken
|
21
|
+
#
|
22
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
19
23
|
#++
|
20
24
|
|
21
25
|
module WWWJDic
|
@@ -35,8 +39,6 @@ module WWWJDic
|
|
35
39
|
require 'fileutils'
|
36
40
|
require 'tempfile'
|
37
41
|
|
38
|
-
#!/usr/bin/env ruby
|
39
|
-
#
|
40
42
|
# An HTTP/HTTPS/FTP file downloader library/CLI based upon
|
41
43
|
# MiniPortile's HTTP implementation.
|
42
44
|
#
|
@@ -45,45 +47,42 @@ module WWWJDic
|
|
45
47
|
# Revision:: 2012-03-25 23:01:19 -0600
|
46
48
|
class Downloader
|
47
49
|
|
48
|
-
VERSION = '0.1.0'
|
50
|
+
VERSION = '0.1.0'.freeze
|
49
51
|
|
50
52
|
class << self
|
51
53
|
attr_accessor :logger, :max_ca_verify_depth, :ftp_data_chunk_size
|
52
54
|
end
|
53
55
|
|
54
|
-
@logger =
|
56
|
+
@logger = $stdout.binmode
|
55
57
|
@max_ca_verify_depth = 5
|
56
58
|
@ftp_data_chunk_size = 8192
|
57
59
|
|
58
60
|
|
59
61
|
def self.download_file(url, full_path, count = 3)
|
60
|
-
raise
|
61
|
-
# return if File.exist?(full_path)
|
62
|
+
raise I18n.t('error.nil') if url.nil?
|
62
63
|
|
63
64
|
http_download(url, full_path, count)
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
def self.message(text)
|
67
|
+
private_class_method def self.message(text)
|
69
68
|
@logger.print text
|
70
69
|
@logger.flush
|
71
70
|
end
|
72
71
|
|
73
|
-
def self.output(text = '')
|
72
|
+
private_class_method def self.output(text = '')
|
74
73
|
@logger.puts text
|
75
74
|
@logger.flush
|
76
75
|
end
|
77
76
|
|
78
|
-
def self.http_download(url, full_path, count)
|
77
|
+
private_class_method def self.http_download(url, full_path, count)
|
79
78
|
uri = URI.parse(url)
|
80
79
|
|
81
80
|
begin
|
82
81
|
filename = File.basename(uri.path)
|
83
82
|
|
84
83
|
if ENV['HTTP_PROXY']
|
85
|
-
#protocol,
|
86
|
-
userinfo, proxy_host, proxy_port = URI
|
84
|
+
# protocol,
|
85
|
+
userinfo, proxy_host, proxy_port = URI.split(ENV['HTTP_PROXY'])
|
87
86
|
proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
|
88
87
|
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
|
89
88
|
else
|
@@ -102,6 +101,7 @@ module WWWJDic
|
|
102
101
|
|
103
102
|
when Net::HTTPRedirection
|
104
103
|
raise 'Too many redirections, halting.' if count <= 0
|
104
|
+
|
105
105
|
url = response['location']
|
106
106
|
return http_download(url, full_path, count - 1)
|
107
107
|
|
@@ -111,25 +111,23 @@ module WWWJDic
|
|
111
111
|
temp_file << response.body
|
112
112
|
temp_file.close
|
113
113
|
|
114
|
-
if full_path.nil?
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
FileUtils.mv temp_file.path, full_path, :force => true
|
120
|
-
end
|
114
|
+
return response.body if full_path.nil?
|
115
|
+
|
116
|
+
File.unlink full_path if File.exist?(full_path)
|
117
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
118
|
+
FileUtils.mv temp_file.path, full_path, force: true
|
121
119
|
else
|
122
120
|
puts response
|
123
121
|
end
|
124
122
|
end
|
125
123
|
|
126
|
-
rescue
|
124
|
+
rescue StandardError => e
|
127
125
|
File.unlink full_path if File.exist?(full_path) unless full_path.nil?
|
128
126
|
output "ERROR: #{e.message}"
|
129
127
|
raise 'Failed to download file'
|
130
128
|
end
|
131
129
|
end
|
132
|
-
end
|
130
|
+
end
|
133
131
|
end
|
134
132
|
end
|
135
133
|
end
|