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.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +419 -0
  3. data/COPYING.md +675 -0
  4. data/Gemfile +21 -0
  5. data/README.md +303 -0
  6. data/Rakefile +52 -0
  7. data/acknowledgements.md +55 -0
  8. data/authors.md +67 -0
  9. data/copyright.md +377 -0
  10. data/examples/basics.rb +117 -0
  11. data/examples/translate.rb +128 -0
  12. data/examples/uri.rb +129 -0
  13. data/html/CHANGELOG.html +597 -0
  14. data/html/COPYING_md.html +389 -0
  15. data/html/Gemfile.html +104 -0
  16. data/html/Object.html +185 -0
  17. data/html/README_md.html +343 -0
  18. data/html/Rakefile.html +137 -0
  19. data/html/WWWJDic/ParsableDuckType.html +159 -0
  20. data/html/WWWJDic/Parser.html +233 -0
  21. data/html/WWWJDic/Parsers/Dict.html +191 -0
  22. data/html/WWWJDic/Parsers/Display.html +184 -0
  23. data/html/WWWJDic/Parsers/Key.html +221 -0
  24. data/html/WWWJDic/Parsers/Search.html +214 -0
  25. data/html/WWWJDic/Parsers/Server.html +182 -0
  26. data/html/WWWJDic/Parsers.html +96 -0
  27. data/html/WWWJDic/Splitter.html +378 -0
  28. data/html/WWWJDic/Utils/Downloader/Downloader.html +227 -0
  29. data/html/WWWJDic/Utils/Downloader.html +108 -0
  30. data/html/WWWJDic/Utils/Raisers.html +235 -0
  31. data/html/WWWJDic/Utils.html +108 -0
  32. data/html/WWWJDic/WWWJDic.html +715 -0
  33. data/html/WWWJDic.html +348 -0
  34. data/html/acknowledgements_md.html +149 -0
  35. data/html/authors_md.html +181 -0
  36. data/html/copyright_md.html +422 -0
  37. data/html/created.rid +59 -0
  38. data/html/css/fonts.css +167 -0
  39. data/html/css/rdoc.css +590 -0
  40. data/html/fonts/Lato-Light.ttf +0 -0
  41. data/html/fonts/Lato-LightItalic.ttf +0 -0
  42. data/html/fonts/Lato-Regular.ttf +0 -0
  43. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  44. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  45. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  46. data/html/images/add.png +0 -0
  47. data/html/images/arrow_up.png +0 -0
  48. data/html/images/brick.png +0 -0
  49. data/html/images/brick_link.png +0 -0
  50. data/html/images/bug.png +0 -0
  51. data/html/images/bullet_black.png +0 -0
  52. data/html/images/bullet_toggle_minus.png +0 -0
  53. data/html/images/bullet_toggle_plus.png +0 -0
  54. data/html/images/date.png +0 -0
  55. data/html/images/delete.png +0 -0
  56. data/html/images/find.png +0 -0
  57. data/html/images/loadingAnimation.gif +0 -0
  58. data/html/images/macFFBgHack.png +0 -0
  59. data/html/images/package.png +0 -0
  60. data/html/images/page_green.png +0 -0
  61. data/html/images/page_white_text.png +0 -0
  62. data/html/images/page_white_width.png +0 -0
  63. data/html/images/plugin.png +0 -0
  64. data/html/images/ruby.png +0 -0
  65. data/html/images/tag_blue.png +0 -0
  66. data/html/images/tag_green.png +0 -0
  67. data/html/images/transparent.png +0 -0
  68. data/html/images/wrench.png +0 -0
  69. data/html/images/wrench_orange.png +0 -0
  70. data/html/images/zoom.png +0 -0
  71. data/html/index.html +363 -0
  72. data/html/js/darkfish.js +161 -0
  73. data/html/js/jquery.js +4 -0
  74. data/html/js/navigation.js +141 -0
  75. data/html/js/navigation.js.gz +0 -0
  76. data/html/js/search.js +109 -0
  77. data/html/js/search_index.js +1 -0
  78. data/html/js/search_index.js.gz +0 -0
  79. data/html/js/searcher.js +229 -0
  80. data/html/js/searcher.js.gz +0 -0
  81. data/html/table_of_contents.html +541 -0
  82. data/html/wwwjdic_gemspec.html +161 -0
  83. data/lib/wwwjdic/application.rb +233 -0
  84. data/lib/wwwjdic/constants.rb +113 -0
  85. data/lib/wwwjdic/locales/de.yml +29 -0
  86. data/lib/wwwjdic/locales/en.yml +29 -0
  87. data/lib/wwwjdic/locales/es.yml +29 -0
  88. data/lib/wwwjdic/locales/fr.yml +29 -0
  89. data/lib/wwwjdic/locales/hu.yml +29 -0
  90. data/lib/wwwjdic/locales/it.yml +29 -0
  91. data/lib/wwwjdic/locales/ja.yml +30 -0
  92. data/lib/wwwjdic/locales/nl.yml +29 -0
  93. data/lib/wwwjdic/locales/ru.yml +29 -0
  94. data/lib/wwwjdic/locales/sl.yml +29 -0
  95. data/lib/wwwjdic/locales/sv.yml +29 -0
  96. data/lib/wwwjdic/parser.rb +46 -0
  97. data/lib/wwwjdic/parsers/dict.rb +58 -0
  98. data/lib/wwwjdic/parsers/display.rb +50 -0
  99. data/lib/wwwjdic/parsers/key.rb +75 -0
  100. data/lib/wwwjdic/parsers/search.rb +60 -0
  101. data/lib/wwwjdic/parsers/server.rb +47 -0
  102. data/lib/wwwjdic/utils/downloader.rb +135 -0
  103. data/lib/wwwjdic/utils/raisers.rb +67 -0
  104. data/lib/wwwjdic/utils/splitter.rb +84 -0
  105. data/lib/wwwjdic/version.rb +20 -0
  106. data/lib/wwwjdic.rb +57 -0
  107. data/test/test_helper.rb +40 -0
  108. data/test/test_wwwjdic.rb +32 -0
  109. data/test/wwwjdic/locales/de.yml +22 -0
  110. data/test/wwwjdic/locales/en.yml +22 -0
  111. data/test/wwwjdic/locales/es.yml +22 -0
  112. data/test/wwwjdic/locales/fr.yml +22 -0
  113. data/test/wwwjdic/locales/hu.yml +22 -0
  114. data/test/wwwjdic/locales/it.yml +21 -0
  115. data/test/wwwjdic/locales/ja.yml +23 -0
  116. data/test/wwwjdic/locales/nl.yml +22 -0
  117. data/test/wwwjdic/locales/ru.yml +22 -0
  118. data/test/wwwjdic/locales/sl.yml +22 -0
  119. data/test/wwwjdic/locales/sv.yml +22 -0
  120. data/test/wwwjdic/locales/test_locales.rb +65 -0
  121. data/test/wwwjdic/parsers/test_dict.rb +73 -0
  122. data/test/wwwjdic/parsers/test_display.rb +51 -0
  123. data/test/wwwjdic/parsers/test_key.rb +52 -0
  124. data/test/wwwjdic/parsers/test_server.rb +51 -0
  125. data/test/wwwjdic/test_application.rb +219 -0
  126. data/test/wwwjdic/test_parsable_duck_type.rb +37 -0
  127. data/test/wwwjdic/utils/test_downloader.rb +41 -0
  128. data/test/wwwjdic/utils/test_raisers.rb +59 -0
  129. data/wwwjdic.gemspec +74 -0
  130. metadata +309 -0
@@ -0,0 +1,29 @@
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
+ it:
20
+ error:
21
+ nil: Parametro nil non consentito.
22
+ param: "Il parametro %{value} non è valido."
23
+ uri: "L'URI %{value} non è valido."
24
+ value: "Il valore %{value} non è nell'intervallo previsto."
25
+ warn:
26
+ deprecated: Questo metodo è obsoleto.
27
+ test:
28
+ kotoba: parola
29
+ test: dato di prova
@@ -0,0 +1,30 @@
1
+ # wwwjdic
2
+ # Copyright © 2013 新部裕
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
+ ja:
21
+ error:
22
+ nil: nil パラメータは許されません。
23
+ param: "パラメータ %{value} は無効です。"
24
+ uri: "URI %{value} が無効です。"
25
+ value: "値 %{value} が範囲外です。"
26
+ warn:
27
+ deprecated: このメソッドはすでに廃止され、推奨されていません。
28
+ test:
29
+ kotoba: 言葉
30
+ test: 試験データ
@@ -0,0 +1,29 @@
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
+ nl:
20
+ error:
21
+ nil: nihil parameter niet toegestaan.
22
+ param: "Parameter %{value} is niet geldig."
23
+ uri: "URI %{value} is niet geldig."
24
+ value: "Waarde %{value} is niet in toegestane bereik."
25
+ warn:
26
+ deprecated: Deze methode is verouderd.
27
+ test:
28
+ kotoba: taal
29
+ test: test data
@@ -0,0 +1,29 @@
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
+ ru:
20
+ error:
21
+ nil: параметр ноль не допускается.
22
+ param: "Параметр %{value} не является допустимым."
23
+ uri: "URI %{value} не является допустимым."
24
+ value: "Значение %{value} не в допустимом диапазоне."
25
+ warn:
26
+ deprecated: Этот метод является устаревшим.
27
+ test:
28
+ kotoba: слово
29
+ test: test data
@@ -0,0 +1,29 @@
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
+ sl:
20
+ error:
21
+ nil: nil parameter ni dovoljeno.
22
+ param: "Parameter %{value} ni veljavna."
23
+ uri: "URI %{value} ni veljavna."
24
+ value: "Vrednost %{value} ni v dovoljenem obsegu."
25
+ warn:
26
+ deprecated: Ta metoda je bila opuščena.
27
+ test:
28
+ kotoba: beseda
29
+ test: test data
@@ -0,0 +1,29 @@
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
+ sv:
20
+ error:
21
+ nil: noll parameter inte tillåtet.
22
+ param: "Parameter %{value} är inte giltigt."
23
+ uri: "URI %{value} är inte giltigt."
24
+ value: "Värde %{value} är inte tillåtet intervall."
25
+ warn:
26
+ deprecated: Denna metod har föråldrad.
27
+ test:
28
+ kotoba: ord
29
+ test: test data
@@ -0,0 +1,46 @@
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 'constants'
22
+
23
+ module WWWJDic
24
+
25
+ # This class is a simple utility that is used to parse and filter
26
+ # parameters for wwwjdic.
27
+ #
28
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
29
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
30
+ # License:: GNU General Public License version 3
31
+ class Parser
32
+ attr_reader :parsers
33
+
34
+ def initialize(args = {})
35
+ @parsers = Hash.new
36
+ ALL_PARAMS.each {|param| parsers[param] = args[param]} unless args.nil?
37
+ end
38
+
39
+ # Provides the duck type for a generic parsing object.
40
+ def parse(method = nil, value = nil)
41
+ a_parser = nil
42
+ a_parser = parsers[method.to_sym] unless method.nil? or parsers.nil?
43
+ a_parser.parse value unless a_parser.nil?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,58 @@
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 '../constants'
22
+ require_relative '../utils/raisers'
23
+
24
+ module WWWJDic
25
+ module Parsers
26
+
27
+ # This class is an implementation of the Parsable duck type that
28
+ # checks the dictionary type. The only needed parameter is a valid
29
+ # dictionary.
30
+ #
31
+ # n = dictionary to use (1 = EDICT, 3 = ENAMDICT, etc. Examine the
32
+ # source of one of the pages to get the full list of codes.)
33
+ #
34
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
35
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
36
+ # License:: GNU General Public License version 3
37
+ class Dict
38
+ include Utils::Raisers
39
+
40
+ # The parsable duck type interface to every parser usage.
41
+ def parse(value = '1')
42
+ raise ArgumentError, I18n.t('error.nil') if value.nil?
43
+ raise ArgumentError, I18n.t('error.param', value: value) unless value.respond_to? :length
44
+ raise ArgumentError, I18n.t('error.param', value: value) if value.empty?
45
+
46
+ if value.length == 1
47
+ raiser_array('error.param', value, DICTIONARY_CODES)
48
+ value
49
+ else
50
+ if value.length > 1
51
+ raiser_array('error.param', value, DICTIONARY_NAMES)
52
+ DICTS_BY_NAMES[value]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
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 '../constants'
22
+
23
+ module WWWJDic
24
+ module Parsers
25
+
26
+ # This class is an implementation of the Parsable duck type that
27
+ # checks the display type. The only needed parameter is a boolean,
28
+ # with +true+ for regular.
29
+ #
30
+ # M = backdoor entry (regular display) or Z = backdoor entry (raw
31
+ # dictionary display)
32
+ #
33
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
34
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
35
+ # License:: GNU General Public License version 3
36
+ class Display
37
+ include Utils::Raisers
38
+
39
+ # The parsable duck type interface to every parser usage.
40
+ def parse(value = :display)
41
+ raise ArgumentError, I18n.t('error.nil') if value.nil?
42
+ raise ArgumentError, I18n.t('error.param', value: value) unless value.is_a? Symbol
43
+
44
+ raiser_array('error.param', value, DISPLAY.keys)
45
+
46
+ value
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,75 @@
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 '../constants'
22
+
23
+ module WWWJDic
24
+ module Parsers
25
+ # This class is an implementation of the Parsable duck type that
26
+ # checks the display type. The only needed parameter is the word to
27
+ # translate.
28
+ #
29
+ # k is the key type:
30
+ # * for dictionary lookups
31
+ # * for English keys use E, or P to get just "common words", Q to
32
+ # get an "exact match" and R to get both;
33
+ # * for Japanese keys use J (this is mandatory for romaji keys),
34
+ # P to get just "common words" (doesn't work with romaji), K for
35
+ # keys starting with kanji (first position), and L for kanji keys in
36
+ # any position.
37
+ # * for kanji lookups, use M followed by the KANJIDIC letter codes
38
+ # (B, U, V, N, etc.) or J if a reading or kanji is being provided.
39
+ # An optional stroke-count or stroke-count range can be included by
40
+ # placing it between "=" characters;
41
+ # * for text glossing use G, or H to turn on the "no repeated
42
+ # translations" option.
43
+ # * for multi-radical kanji lookups use J for jouyou kanji-only, H
44
+ # to include JIS X 0212 kanji, and X for anything else. An optional
45
+ # stroke-count or stroke-count range can be included by placing it
46
+ # between "=" characters.
47
+ # * for example sentence lookups with indexed words use E for EUC,
48
+ # ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8, followed by
49
+ # "lookupword=n=kana=". The kana is optional and is there to
50
+ # disambiguate between different headwords. For "n", 1 => random
51
+ # selection of 10, anything else => display up to 100 sentences
52
+ # starting at n.
53
+ # * for example sentence lookups using a regular expression, use E
54
+ # for EUC, ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8,
55
+ # followed by the search string. Up to 99 example sentences may be
56
+ # displayed.
57
+ #
58
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
59
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
60
+ # License:: GNU General Public License version 3
61
+ class Key
62
+ include Utils::Raisers
63
+
64
+ # The parsable duck type interface to every parser usage.
65
+ def parse(value = :exact)
66
+ raise ArgumentError, I18n.t('error.nil') if value.nil?
67
+ raise ArgumentError, I18n.t('error.param', value: value) unless value.is_a? Symbol
68
+
69
+ raiser_array('error.param', value, KEYS.keys)
70
+
71
+ value
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,60 @@
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
+ module Parsers
23
+ # This class is an implementation of the Parsable duck type that
24
+ # checks the display type. The only needed parameter is the word to
25
+ # translate.
26
+ #
27
+ # t is the search type:
28
+ # * for dictionary lookups use:
29
+ # * D where the lookup text is in ASCII, EUC, ISO-2022-JP or UCS
30
+ # (the old uxxxx format);
31
+ # * S where the lookup text is in Shift-JIS;
32
+ # * U where the lookup text is in UTF-8.
33
+ # * for kanji lookups use:
34
+ # * K for all lookups via codes, codepoints, etc. or where the
35
+ # text string (e.g. kanji or reading) is in EUC;
36
+ # * M for all lookups using a text string in UTF8;
37
+ # * N for all lookups using a text string in Shift_JIS;
38
+ # * for text glossing/translate words in text use:
39
+ # * G where the text is in EUC, ISO-2022-JP or UCS;
40
+ # * H where the text is in Shift-JIS;
41
+ # * I where the text is in UTF-8.
42
+ # * for multi-radical kanji lookups use:
43
+ # * B where the text is in EUC, ISO-2022-JP or UCS;
44
+ # * C where the text is in Shift-JIS;
45
+ # * F where the text is in UTF-8.
46
+ # * for example sentence lookups via indexed Japanese words, use E.
47
+ # * for example sentence lookups using a regular expression, use T.
48
+ #
49
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
50
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
51
+ # License:: GNU General Public License version 3
52
+ class Search
53
+ # The parsable duck type interface to every parser usage.
54
+ def parse(value = '')
55
+ return 'D' if value == CGI::escape(value).to_s
56
+ 'U'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,47 @@
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 '../constants'
22
+
23
+ module WWWJDic
24
+ module Parsers
25
+
26
+ # This class is an implementation of the Parsable duck type that
27
+ # checks the display type. The only needed parameter is a boolean,
28
+ # with +true+ for regular.
29
+ #
30
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
31
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
32
+ # License:: GNU General Public License version 3
33
+ class Server
34
+ include Utils::Raisers
35
+
36
+ # The parsable duck type interface to every parser usage.
37
+ def parse(value = :edrdg)
38
+ raise ArgumentError, I18n.t('error.nil') if value.nil?
39
+ raise ArgumentError, I18n.t('error.param', value: value) unless value.is_a? Symbol
40
+
41
+ raiser_array('error.param', value, URIS.keys)
42
+
43
+ value
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,135 @@
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
+ module Utils
23
+
24
+ # This module is a simple wrapper container for Peter R. Marreck's
25
+ # gist.
26
+ #
27
+ # Author:: {Jon Maken}[mailto:jon.forums@gmail.com]
28
+ # License:: 3-clause BSD
29
+ # Revision:: 2012-03-25 23:01:19 -0600
30
+ module Downloader
31
+
32
+ require 'net/http'
33
+ require 'net/ftp'
34
+ require 'openssl'
35
+ require 'fileutils'
36
+ require 'tempfile'
37
+
38
+ #!/usr/bin/env ruby
39
+ #
40
+ # An HTTP/HTTPS/FTP file downloader library/CLI based upon
41
+ # MiniPortile's HTTP implementation.
42
+ #
43
+ # Author:: Jon Maken
44
+ # License:: 3-clause BSD
45
+ # Revision:: 2012-03-25 23:01:19 -0600
46
+ class Downloader
47
+
48
+ VERSION = '0.1.0'
49
+
50
+ class << self
51
+ attr_accessor :logger, :max_ca_verify_depth, :ftp_data_chunk_size
52
+ end
53
+
54
+ @logger = STDOUT.binmode
55
+ @max_ca_verify_depth = 5
56
+ @ftp_data_chunk_size = 8192
57
+
58
+
59
+ 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
+
63
+ http_download(url, full_path, count)
64
+ end
65
+
66
+ private
67
+
68
+ def self.message(text)
69
+ @logger.print text
70
+ @logger.flush
71
+ end
72
+
73
+ def self.output(text = '')
74
+ @logger.puts text
75
+ @logger.flush
76
+ end
77
+
78
+ def self.http_download(url, full_path, count)
79
+ uri = URI.parse(url)
80
+
81
+ begin
82
+ filename = File.basename(uri.path)
83
+
84
+ if ENV['HTTP_PROXY']
85
+ #protocol,
86
+ userinfo, proxy_host, proxy_port = URI::split(ENV['HTTP_PROXY'])
87
+ proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
88
+ http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
89
+ else
90
+ http = Net::HTTP.new(uri.host, uri.port)
91
+ end
92
+
93
+ http.request_get(uri) do |response|
94
+ case response
95
+ when Net::HTTPNotFound
96
+ output '404 - Not Found'
97
+ return false
98
+
99
+ when Net::HTTPClientError
100
+ output "Error: Client Error: #{response.inspect}"
101
+ return false
102
+
103
+ when Net::HTTPRedirection
104
+ raise 'Too many redirections for the original URL, halting.' if count <= 0
105
+ url = response['location']
106
+ return http_download(url, full_path, count - 1)
107
+
108
+ when Net::HTTPOK
109
+ temp_file = Tempfile.new("download-#{filename}")
110
+ temp_file.binmode
111
+ temp_file << response.body
112
+ temp_file.close
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
121
+ else
122
+ puts response
123
+ end
124
+ end
125
+
126
+ rescue Exception => e
127
+ File.unlink full_path if File.exist?(full_path) unless full_path.nil?
128
+ output "ERROR: #{e.message}"
129
+ raise 'Failed to download file'
130
+ end
131
+ end
132
+ end # Downloader
133
+ end
134
+ end
135
+ end