wwwjdic 14.0.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +19 -0
  3. data/Gemfile +5 -1
  4. data/README.md +461 -192
  5. data/Rakefile +7 -2
  6. data/copyright.md +17 -29
  7. data/examples/basics.rb +51 -45
  8. data/examples/translate.rb +135 -86
  9. data/examples/uri.rb +34 -78
  10. data/html/CHANGELOG.html +48 -31
  11. data/html/COPYING_md.html +31 -35
  12. data/html/Gemfile.html +28 -32
  13. data/html/Object.html +71 -71
  14. data/html/README_md.html +326 -159
  15. data/html/Rakefile.html +29 -33
  16. data/html/WWWJDic.html +137 -98
  17. data/html/WWWJDic/ParsableDuckType.html +55 -55
  18. data/html/WWWJDic/Parser.html +88 -88
  19. data/html/WWWJDic/Parsers.html +33 -33
  20. data/html/WWWJDic/Parsers/Dict.html +71 -73
  21. data/html/WWWJDic/Parsers/Display.html +66 -66
  22. data/html/WWWJDic/Parsers/Key.html +67 -67
  23. data/html/WWWJDic/Parsers/Search.html +59 -58
  24. data/html/WWWJDic/Parsers/Server.html +66 -66
  25. data/html/WWWJDic/Splitter.html +173 -172
  26. data/html/WWWJDic/Utils.html +34 -34
  27. data/html/WWWJDic/Utils/Downloader.html +33 -33
  28. data/html/WWWJDic/Utils/Downloader/Downloader.html +91 -89
  29. data/html/WWWJDic/Utils/Raisers.html +95 -95
  30. data/html/WWWJDic/WWWJDic.html +343 -345
  31. data/html/copyright_md.html +37 -51
  32. data/html/created.rid +55 -57
  33. data/html/index.html +334 -164
  34. data/html/js/darkfish.js +84 -84
  35. data/html/js/navigation.js.gz +0 -0
  36. data/html/js/search.js +110 -110
  37. data/html/js/search_index.js +1 -1
  38. data/html/js/search_index.js.gz +0 -0
  39. data/html/js/searcher.js +229 -229
  40. data/html/js/searcher.js.gz +0 -0
  41. data/html/table_of_contents.html +44 -75
  42. data/lib/wwwjdic.rb +7 -11
  43. data/lib/wwwjdic/application.rb +13 -7
  44. data/lib/wwwjdic/constants.rb +16 -8
  45. data/lib/wwwjdic/locales/de.yml +5 -4
  46. data/lib/wwwjdic/locales/en.yml +5 -4
  47. data/lib/wwwjdic/locales/es.yml +5 -4
  48. data/lib/wwwjdic/locales/fr.yml +6 -4
  49. data/lib/wwwjdic/locales/hu.yml +6 -4
  50. data/lib/wwwjdic/locales/it.yml +6 -4
  51. data/lib/wwwjdic/locales/ja.yml +8 -4
  52. data/lib/wwwjdic/locales/nl.yml +5 -4
  53. data/lib/wwwjdic/locales/ru.yml +5 -4
  54. data/lib/wwwjdic/locales/sl.yml +5 -4
  55. data/lib/wwwjdic/locales/sv.yml +5 -4
  56. data/lib/wwwjdic/parser.rb +8 -4
  57. data/lib/wwwjdic/parsers/dict.rb +9 -7
  58. data/lib/wwwjdic/parsers/display.rb +6 -2
  59. data/lib/wwwjdic/parsers/key.rb +8 -3
  60. data/lib/wwwjdic/parsers/search.rb +8 -3
  61. data/lib/wwwjdic/parsers/server.rb +6 -2
  62. data/lib/wwwjdic/utils/downloader.rb +21 -23
  63. data/lib/wwwjdic/utils/raisers.rb +7 -3
  64. data/lib/wwwjdic/utils/splitter.rb +20 -14
  65. data/lib/wwwjdic/version.rb +2 -6
  66. data/test/test_helper.rb +5 -1
  67. data/test/test_wwwjdic.rb +6 -2
  68. data/test/wwwjdic/locales/de.yml +7 -1
  69. data/test/wwwjdic/locales/en.yml +7 -1
  70. data/test/wwwjdic/locales/es.yml +7 -1
  71. data/test/wwwjdic/locales/fr.yml +7 -1
  72. data/test/wwwjdic/locales/hu.yml +7 -1
  73. data/test/wwwjdic/locales/it.yml +10 -3
  74. data/test/wwwjdic/locales/ja.yml +9 -2
  75. data/test/wwwjdic/locales/nl.yml +7 -1
  76. data/test/wwwjdic/locales/ru.yml +7 -1
  77. data/test/wwwjdic/locales/sl.yml +7 -1
  78. data/test/wwwjdic/locales/sv.yml +7 -1
  79. data/test/wwwjdic/locales/test_locales.rb +12 -9
  80. data/test/wwwjdic/parsers/test_dict.rb +6 -2
  81. data/test/wwwjdic/parsers/test_display.rb +6 -2
  82. data/test/wwwjdic/parsers/test_key.rb +6 -2
  83. data/test/wwwjdic/parsers/test_server.rb +6 -2
  84. data/test/wwwjdic/test_application.rb +12 -8
  85. data/test/wwwjdic/test_parsable_duck_type.rb +6 -2
  86. data/test/wwwjdic/utils/test_downloader.rb +5 -1
  87. data/test/wwwjdic/utils/test_raisers.rb +10 -6
  88. data/wwwjdic.gemspec +30 -14
  89. metadata +50 -22
  90. data/acknowledgements.md +0 -55
  91. data/authors.md +0 -67
  92. data/html/acknowledgements_md.html +0 -150
  93. data/html/authors_md.html +0 -182
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,7 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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: 試験データ
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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 = Hash.new
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.parse value unless a_parser.nil?
47
+ a_parser&.parse value
44
48
  end
45
49
  end
46
50
  end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
- else
50
- if value.length > 1
51
- raiser_array('error.param', value, DICTIONARY_NAMES)
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
38
+ # Copyright:: (C) 2014 Marco Bresciani
35
39
  # License:: GNU General Public License version 3
36
40
  class Display
37
41
  include Utils::Raisers
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # wwwjdic
3
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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 = :exact)
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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::escape(value).to_s
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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
- # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani
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 = STDOUT.binmode
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 RuntimeError, I18n.t('error.nil') if url.nil?
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
- private
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::split(ENV['HTTP_PROXY'])
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
- return response.body
116
- else
117
- File.unlink full_path if File.exist?(full_path)
118
- FileUtils.mkdir_p File.dirname(full_path)
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 Exception => e
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 # Downloader
130
+ end
133
131
  end
134
132
  end
135
133
  end