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,161 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>wwwjdic.gemspec - wwwjdic 13.0.0</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ var index_rel_prefix = "./";
12
+ </script>
13
+
14
+ <script src="./js/jquery.js"></script>
15
+ <script src="./js/darkfish.js"></script>
16
+
17
+ <link href="./css/fonts.css" rel="stylesheet">
18
+ <link href="./css/rdoc.css" rel="stylesheet">
19
+
20
+
21
+
22
+
23
+ <body id="top" role="document" class="file">
24
+ <nav role="navigation">
25
+ <div id="project-navigation">
26
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
27
+ <h2>
28
+ <a href="./index.html" rel="home">Home</a>
29
+ </h2>
30
+
31
+ <div id="table-of-contents-navigation">
32
+ <a href="./table_of_contents.html#pages">Pages</a>
33
+ <a href="./table_of_contents.html#classes">Classes</a>
34
+ <a href="./table_of_contents.html#methods">Methods</a>
35
+ </div>
36
+ </div>
37
+
38
+ <div id="search-section" role="search" class="project-section initially-hidden">
39
+ <form action="#" method="get" accept-charset="utf-8">
40
+ <div id="search-field-wrapper">
41
+ <input id="search-field" role="combobox" aria-label="Search"
42
+ aria-autocomplete="list" aria-controls="search-results"
43
+ type="text" name="search" placeholder="Search" spellcheck="false"
44
+ title="Type to search, Up and Down to navigate, Enter to load">
45
+ </div>
46
+
47
+ <ul id="search-results" aria-label="Search Results"
48
+ aria-busy="false" aria-expanded="false"
49
+ aria-atomic="false" class="initially-hidden"></ul>
50
+ </form>
51
+ </div>
52
+
53
+ </div>
54
+
55
+
56
+
57
+ <div id="project-metadata">
58
+ <div id="fileindex-section" class="nav-section">
59
+ <h3>Pages</h3>
60
+
61
+ <ul class="link-list">
62
+
63
+ <li><a href="./CHANGELOG.html">CHANGELOG</a>
64
+
65
+ <li><a href="./COPYING_md.html">COPYING</a>
66
+
67
+ <li><a href="./Gemfile.html">Gemfile</a>
68
+
69
+ <li><a href="./README_md.html">README</a>
70
+
71
+ <li><a href="./Rakefile.html">Rakefile</a>
72
+
73
+ <li><a href="./acknowledgements_md.html">acknowledgements</a>
74
+
75
+ <li><a href="./authors_md.html">authors</a>
76
+
77
+ <li><a href="./copyright_md.html">copyright</a>
78
+
79
+ <li><a href="./wwwjdic_gemspec.html">wwwjdic.gemspec</a>
80
+
81
+ </ul>
82
+ </div>
83
+
84
+ </div>
85
+ </nav>
86
+
87
+ <main role="main" aria-label="Page wwwjdic.gemspec">
88
+
89
+ <p># wwwjdic # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani # # This file is part of wwwjdic. # # wwwjdic is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # wwwjdic is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with wwwjdic. If not, see &lt;<a href="http://www.gnu.org/licenses">www.gnu.org/licenses</a>/&gt;.</p>
90
+
91
+ <p>require_relative &#39;lib/wwwjdic/version&#39;</p>
92
+
93
+ <p>SUMMARY = &#39;This gem uses <a href="WWWJDic.html"><code>WWWJDic</code></a> Backdoor Entry/API as described by</p>
94
+
95
+ <pre>http://www.edrdg.org/wwwjdic/wwwjdicinf.html#backdoor_tag to to
96
+ interact with WWWJDic and translate to and from Japanese language.&#39;</pre>
97
+
98
+ <p>Gem::Specification.new do |a_gem|</p>
99
+
100
+ <pre class="ruby"> <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">name</span> = <span class="ruby-string">&#39;wwwjdic&#39;</span>
101
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">version</span> = <span class="ruby-constant">WWWJDic</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span>
102
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">license</span> = <span class="ruby-string">&#39;GPL-3.0&#39;</span>
103
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">licenses</span> = <span class="ruby-node">%w(GPL-3.0 BSD-3-Clause)</span>
104
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">author</span> = <span class="ruby-string">&#39;Marco Bresciani&#39;</span>
105
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">authors</span> = [<span class="ruby-string">&#39;Marco Bresciani&#39;</span>, <span class="ruby-string">&#39;新部裕&#39;</span>, <span class="ruby-string">&#39;Jon Maken&#39;</span>]
106
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">email</span> = <span class="ruby-string">&#39;marcobresciani_1974@libero.it&#39;</span>
107
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">homepage</span> = <span class="ruby-string">&#39;https://savannah.nongnu.org/projects/wwwjdic/&#39;</span>
108
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">summary</span> = <span class="ruby-constant">SUMMARY</span>
109
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">description</span> = <span class="ruby-node">&quot;#{SUMMARY} WWWJDic is an online Japanese
110
+ translation server made by Jim Breen and available at
111
+ http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C. GNU GPLv3 license;
112
+ source code available through anonymous checkout: `hg clone
113
+ http://hg.savannah.nongnu.org/hgweb/wwwjdic/` or write me and I&#39;ll send
114
+ it. You can even decide to contribute to this little free software
115
+ project by registering to Savannah and ask to be part of the &#39;wwwjdic&#39;
116
+ project!&quot;</span>
117
+
118
+ <span class="ruby-constant">COMMON_FILES</span> = <span class="ruby-node">%w(acknowledgements.md authors.md CHANGELOG COPYING.md
119
+ copyright.md Gemfile wwwjdic.gemspec Rakefile README.md)</span> <span class="ruby-comment">#ISSUES.md</span>
120
+
121
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">files</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-string">&#39;{examples,html,lib,test} /*&#39;</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">COMMON_FILES</span>
122
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">test_files</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-string">&#39;test/ test_*.rb&#39;</span>)
123
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">require_path</span> = <span class="ruby-string">&#39;lib&#39;</span>
124
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">require_paths</span> = <span class="ruby-node">%w(lib)</span>
125
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">extra_rdoc_files</span> = <span class="ruby-constant">COMMON_FILES</span>
126
+
127
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">required_ruby_version</span> = <span class="ruby-string">&#39;~&gt; 2.6&#39;</span>
128
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">rubygems_version</span> = <span class="ruby-string">&#39;~&gt; 3.0&#39;</span>
129
+
130
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_runtime_dependency</span> <span class="ruby-string">&#39;i18n&#39;</span>, <span class="ruby-string">&#39;~&gt;1.6&#39;</span>
131
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_runtime_dependency</span> <span class="ruby-string">&#39;json&#39;</span>, <span class="ruby-string">&#39;~&gt;2.2&#39;</span>
132
+
133
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&#39;bundler&#39;</span>, <span class="ruby-string">&#39;~&gt;2.0&#39;</span>
134
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&#39;minitest&#39;</span>, <span class="ruby-string">&#39;~&gt;5.11&#39;</span>
135
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&#39;rake&#39;</span>, <span class="ruby-string">&#39;~&gt;12.3&#39;</span>
136
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&#39;rdoc&#39;</span>, <span class="ruby-string">&#39;~&gt;6.1&#39;</span>
137
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&#39;simplecov&#39;</span>, <span class="ruby-string">&#39;~&gt;0.16&#39;</span>
138
+
139
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">requirements</span> = <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">required_ruby_version</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">dependencies</span>.<span class="ruby-identifier">to_s</span>
140
+
141
+ <span class="ruby-keyword">begin</span>
142
+ <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;changelog&#39;</span>
143
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>
144
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">post_install_message</span> = <span class="ruby-node">&quot;Thank you for using #{a_gem.name} version #{a_gem.version}.&quot;</span>
145
+ <span class="ruby-keyword">else</span>
146
+ <span class="ruby-identifier">a_gem</span>.<span class="ruby-identifier">post_install_message</span> = <span class="ruby-constant">CHANGELOG</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">version_changes</span>
147
+ <span class="ruby-keyword">end</span>
148
+ </pre>
149
+
150
+ <p>end</p>
151
+
152
+ </main>
153
+
154
+
155
+
156
+ <footer id="validator-badges" role="contentinfo">
157
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
158
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.1.1.
159
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
160
+ </footer>
161
+
@@ -0,0 +1,233 @@
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 'i18n'
22
+ require 'json'
23
+
24
+ require_relative 'constants'
25
+ require_relative 'utils/downloader'
26
+ require_relative 'utils/splitter'
27
+
28
+ module WWWJDic
29
+ # This class is a simple API to interact with WWWJDic Backboor
30
+ # Entry/API.
31
+ # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
32
+ # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
33
+ # License:: GNU General Public License version 3
34
+ class WWWJDic
35
+
36
+ # Creates a +WWWJDic+ object. This constructor should be used
37
+ # through the WWWJDic::breener method only.
38
+ #
39
+ # Usage:: <tt>new_wwwjdic = WWWJDic.new a_parser</tt>
40
+ # Returns:: a +WWWJDic+ object.
41
+ def initialize(parser)
42
+ I18n.load_path = Dir[File.join(File.dirname(__FILE__), '/locales/', '*.yml')]
43
+
44
+ @parser = parser
45
+
46
+ reset
47
+ end
48
+
49
+ # Create the reference uri for a +word+ translation, according to
50
+ # specified parameters.
51
+ #
52
+ # Usage:: <tt>new_wwwjdic.uri word
53
+ def uri(word = nil, args = {})
54
+ raise ArgumentError, I18n.t('error.nil') if word.nil?
55
+ raise ArgumentError, I18n.t('error.param', value: word) if word.empty?
56
+ raise ArgumentError, I18n.t('error.param', value: args) unless args.keys.to_set.proper_subset? Set.new(ALLOWED_PARAMS)
57
+
58
+ params = Hash.new
59
+ params[:search] = word
60
+ @defaults[:search] = word
61
+
62
+ unless args.nil?
63
+ ALL_PARAMS.each do |param_name|
64
+ params[param_name] = @parser.parse(param_name.to_s, args.fetch(param_name, @defaults[param_name]))
65
+ end
66
+ end
67
+
68
+ a_wwwjdic = URIS[params[:server]] + params[:dict] + DISPLAY[params[:display]] + params[:search] + KEYS[params[:key]]
69
+ a_wwwjdic + CGI::escape(word).to_s
70
+ end
71
+
72
+ # Create the reference uri for a +word+ translation, according to
73
+ # specified parameters, overriding for raw display mode.
74
+ #
75
+ # Usage:: <tt>new_wwwjdic.raw_uri word
76
+ def raw_uri(word = nil, args = {})
77
+ args = Hash.new if args.nil?
78
+ args[:display] = :raw
79
+ uri(word, args)
80
+ end
81
+
82
+ # Create the reference uri for a +word+ translation, according to
83
+ # specified parameters, with JSON output.
84
+ #
85
+ # Usage:: <tt>new_wwwjdic.json_uri word
86
+ def json_uri(word = nil, args = {})
87
+ an_uri = uri(word, args)
88
+
89
+ result = Hash.new
90
+ result[word] = an_uri
91
+
92
+ result.to_json
93
+ end
94
+
95
+ # Save a file, with specified +filename+, that contains the current
96
+ # wwwjdic configuration. Uses the internal state to retrieve data
97
+ # from the URI. Defaults to 'wwwjdic' with no specific extension.
98
+ #
99
+ # Usage::
100
+ # - <tt>a_string = new_wwwjdic.translate filename</tt>
101
+ # Params::
102
+ # - +filename+: [String] is the filename to be saved.
103
+ def translate(word = nil, args = {}, filename = nil)
104
+ a_uri = raw_uri(word, args)
105
+ Utils::Downloader::Downloader.download_file a_uri, filename # thanks Jon!
106
+ end
107
+
108
+ # Save a file, with specified +filename+, that contains the current
109
+ # wwwjdic configuration, in JSON format. Uses the internal state to
110
+ # retrieve data from the URI. Defaults to 'wwwjdic' with no specific
111
+ # extension.
112
+ #
113
+ # Usage::
114
+ # - <tt>a_string = new_wwwjdic.json_translate filename</tt>
115
+ # Params::
116
+ # - +filename+: [String] is the filename to be saved.
117
+ def json_translate(word = nil, args = {}, filename = nil)
118
+ translation = translate(word, args)
119
+
120
+ a_hash = Hash.new
121
+ a_hash[word.to_sym] = raw_uri(word, args)
122
+
123
+ the_splitter = Splitter.new translation
124
+
125
+ a_hash[:title] = the_splitter.title
126
+ a_hash[:translation] = the_splitter.translation
127
+ a_hash[:message] = the_splitter.message
128
+
129
+ unless a_hash[:translation].nil?
130
+ a_hash[:lines] = the_splitter.lines
131
+ a_hash[:content] = the_splitter.content
132
+ end
133
+
134
+ result = a_hash.to_json
135
+
136
+ File.open(filename, 'w+') {|f| f << JSON.pretty_generate(a_hash)} unless filename.nil?
137
+
138
+ result
139
+ end
140
+
141
+ # Configure the default used dictionary using either code/number or
142
+ # (exact) string.
143
+ #
144
+ # Usage:: <tt>new_wwwjdic.dictionary= dict
145
+ # Params::
146
+ # - +dict+: [String] is the dictionary code or (exact) full name.
147
+ def dictionary=(dict)
148
+ @defaults[:dict] = @parser.parse(:dict.to_s, dict)
149
+ @wwwjdic = URIS[@defaults[:server]] + @defaults[:dict] + DISPLAY[@defaults[:display]]
150
+ end
151
+
152
+ # Return the default used dictionary string, if any.
153
+ #
154
+ # Returns:: a String with the dictionary full name.
155
+ def dictionary
156
+ DICTS_BY_CODES[@defaults[:dict]]
157
+ end
158
+
159
+ # Store the Backdoor Entry/API server name, default to EDRDG.Org
160
+ # (:edrdg) instead of Monash (:monash).
161
+ #
162
+ # Usage:: <tt>new_wwwjdic.server= server
163
+ # Params::
164
+ # - +server+: [Symbol] is the server reference URI
165
+ def server=(server = :edrdg)
166
+ raise ArgumentError, I18n.t('error.nil') if server.nil?
167
+
168
+ @defaults[:server] = @parser.parse(:server.to_s, server)
169
+
170
+ @wwwjdic = URIS[@defaults[:server]] + @defaults[:dict] + DISPLAY[@defaults[:display]]
171
+ end
172
+
173
+ # Return the selected server URI
174
+ #
175
+ # Returns:: a String with the dictionary full name.
176
+ def server
177
+ URIS[@defaults[:server]]
178
+ end
179
+
180
+ # Restores the original status cleaning up the (possibly) previously
181
+ # saved URIs restoring the default +to_s+.
182
+ def reset
183
+ @defaults = Hash.new
184
+ @defaults[:dict] = '1'
185
+ @defaults[:display] = :regular
186
+
187
+ # Hi Marco,
188
+ #
189
+ # Will your code have the ability to allow which wwwjdic server
190
+ # is used? When a URL is being published I prefer it to be the
191
+ # one at http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C as my
192
+ # link with Monash is a bit tenuous, and may be turned off at
193
+ # short notice.
194
+ #
195
+ # Cheers
196
+ #
197
+ # Jim
198
+ @defaults[:server] = :edrdg
199
+
200
+ # That will work fine, but the key role of "k=J" is to force a
201
+ # romaji conversion if the key is not in Japanese coding (UTF-8,
202
+ # EUC or Shift_JIS.) If you want to look up using "sensei" it has
203
+ # to be a J. For anything else the value of J doesn't matter much.
204
+ # 1MUJ齧歯 and 1MUE齧歯 will both find 齧歯. 1MUJgesshi does too,
205
+ # but 1MUEgesshi won't.
206
+ #
207
+ # I think you have missed a key point I made in my previous email:
208
+ # "the key role of "k=J" is to force a romaji conversion if the
209
+ # key is not in Japanese coding (UTF-8, EUC or Shift_JIS.)"
210
+ #
211
+ # So something like ...JMUJord is saying that "ord" is romaji,
212
+ # which of course will not convert.
213
+ #
214
+ # ONLY use k=J if the key is Romaji, (or if it is in Japanese
215
+ # coding...).
216
+ #
217
+ # HTH
218
+ #
219
+ # Jim
220
+ @defaults[:key] = :exact
221
+
222
+ # Exactly. I'd fix on "t=U". There are occasions where you may
223
+ # want to use "k=K" if you want to force the kanji match to start
224
+ # at the beginning.
225
+ @defaults[:search] = 'U'
226
+ @wwwjdic = URIS[@defaults[:server]] + @defaults[:dict] + DISPLAY[@defaults[:display]]
227
+ end
228
+
229
+ def to_s
230
+ @wwwjdic.to_s
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,113 @@
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
+ # Allowed parameters for configuration
23
+ ALLOWED_PARAMS = [:dict, :display, :key, :server].freeze
24
+
25
+ # All parameters for configuration
26
+ ALL_PARAMS = ALLOWED_PARAMS + [:search]
27
+
28
+ # Numeric codes for language-specific dictionaries
29
+ AVAIL_LANGS = {en: '1', de: 'G', fr: 'H', ru: 'I', sv: 'J', hu: 'K', es: 'L', nl: 'M', sl: 'N', it: 'O'}.freeze
30
+
31
+ # Numeric codes for dictionaries usage
32
+ DICTIONARY_CODES = [('1'..'9').to_a, ('A'..'R').to_a].flatten
33
+
34
+ # Naming for all supported dictionaries
35
+ DICTIONARY_NAMES = ['Jpn-Eng General (EDICT)', 'Japanese Names (ENAMDICT)', 'Computing/Telecomms', 'Life Sciences/Bio-Med', 'Legal Terms', 'Finance/Marketing', 'Buddhism', 'Miscellaneous', 'Special Text-glossing', 'Engineering/Science', 'Linguistics', 'River & Water Systems', 'Automobile Industry', 'Japanese Wordnet', 'Work-in-progress File', 'Japanese-German (WaDoku)', 'Japanese-French', 'Japanese-Russian', 'Japanese-Swedish', 'Japanese-Hungarian', 'Japanese-Spanish', 'Japanese-Dutch', 'Japanese-Slovenian', 'Japanese-Italian', 'Untranslated', 'Combined Jpn-Eng', 'Expanded Text-glossing'].freeze
36
+
37
+ # Mapping between dictionaries names with codes
38
+ DICTS_BY_CODES = Hash[DICTIONARY_CODES.zip(DICTIONARY_NAMES)]
39
+
40
+ # Mapping between dictionaries codes with names
41
+ DICTS_BY_NAMES = Hash[DICTIONARY_NAMES.zip(DICTIONARY_CODES)]
42
+
43
+ # Display modes
44
+ DISPLAY = {regular: 'M', raw: 'Z'}.freeze
45
+
46
+ # k is the key type:
47
+ #
48
+ # for dictionary lookups
49
+ # for English keys use E, or P to get just "common words", Q
50
+ # to get an "exact match" and R to get both;
51
+ # for Japanese keys use J (this is mandatory for romaji keys),
52
+ # P to get just "common words" (doesn't work with romaji), K for keys
53
+ # starting with kanji (first position), and L for kanji keys in any
54
+ # position.
55
+ # for kanji lookups, use M followed by the KANJIDIC letter codes
56
+ # (B, U, V, N, etc.) or J if a reading or kanji is being provided. An
57
+ # optional stroke-count or stroke-count range can be included by
58
+ # placing it between "=" characters;
59
+ # for text glossing use G, or H to turn on the "no repeated
60
+ # translations" option.
61
+ # for multi-radical kanji lookups use J for jouyou kanji-only, H
62
+ # to include JIS X 0212 kanji, and X for anything else. An optional
63
+ # stroke-count or stroke-count range can be included by placing it
64
+ # between "=" characters.
65
+ # for example sentence lookups with indexed words use E for EUC,
66
+ # ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8, followed by
67
+ # "lookupword=n=kana=". The kana is optional and is there to
68
+ # disambiguate between different headwords. For "n", 1 => random
69
+ # selection of 10, anything else => display up to 100 sentences
70
+ # starting at n.
71
+ # for example sentence lookups using a regular expression, use E
72
+ # for EUC, ISO-2022-JP or UCS, S for Shift_JIS and U for UTF-8,
73
+ # followed by the search string. Up to 99 example sentences may be
74
+ # displayed.
75
+ KEYS = {english: 'E', common: 'P', exact: 'Q', both: 'R', japanese: 'J', start_kanji: 'K', any_kanji: 'L', kanji: 'M', glossing: 'G', no_repeated: 'H', jis_kanji: 'H', multi_radical: 'X'}.freeze
76
+
77
+ # KANJIDIC letter codes (see
78
+ # http://www.edrdg.org/kanjidic/kanjidic.html)
79
+ # [U] the Unicode/ISO 10646 code of the kanji in hexadecimal;
80
+ # [N] the index in Nelson (Modern Reader's Japanese-English Character
81
+ # Dictionary)
82
+ # [B] the classification radical number of the kanji (as in Nelson);
83
+ # [C] the "classical" radical number (where this differs from the one
84
+ # used in Nelson);
85
+ # [S] the total stroke-count of the kanji;
86
+ # [G] the "grade" of the kanji, In this case, G2 means it is a Jouyou
87
+ # (general use) kanji taught in the second year of elementary
88
+ # schooling in Japan;
89
+ # [H] the index in Halpern (New Japanese-English Character
90
+ # Dictionary);
91
+ # [F] the rank-order frequency of occurrence of the kanji in Japanese;
92
+ # [P] the "SKIP" coding of the kanji, as used in Halpern;
93
+ # [K] the index in the Gakken Kanji Dictionary (A New Dictionary of
94
+ # Kanji Usage);
95
+ # [L] the index in Heisig (Remembering The Kanji);
96
+ # [I] the index in the Spahn & Hadamitsky dictionary.
97
+ # [Q] the Four-Corner code;
98
+ # [MN,MP] the index and page number in the 13-volume Morohashi
99
+ # "DaiKanWaJiten";
100
+ # [E] the index in Henshall (A Guide To Remembering Japanese
101
+ # Characters);
102
+ # [Y] the PinYin (Chinese) pronunciation(s) of the kanji;
103
+ KANJIDIC_CODES = {unicode: 'U', nelson: 'N', radical: 'B', classical: 'C', stroke: 'S', grade: 'G', halpern: 'H', frequency: 'F', skip: 'P', gakken: 'K', heisig: 'L', spahn: 'I', corner: 'Q', morohashi_index: 'MN', morohashi_page: 'MP', henshall: 'E', pinyin: 'Y'}.freeze
104
+
105
+ # Reference URI for Backdoor Entry/API
106
+ URI_DEFAULT = 'http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi?'.freeze
107
+
108
+ # Monash URI for Backdoor Entry/API
109
+ URI_OLD = 'http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?'.freeze
110
+
111
+ # URIs for Backdoor Entry/API
112
+ URIS = {edrdg: URI_DEFAULT, monash: URI_OLD}.freeze
113
+ end
@@ -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
+ de:
20
+ error:
21
+ nil: nil-Parameter nicht erlaubt.
22
+ param: "Parameter %{value} ist nicht gültig."
23
+ uri: "URI %{value} ist nicht gültig."
24
+ value: "Der Wert %{value} ist nicht im zulässigen Bereich."
25
+ warn:
26
+ deprecated: Diese Methode ist veraltet.
27
+ test:
28
+ kotoba: Sprache
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
+ en:
20
+ error:
21
+ nil: nil parameter not allowed.
22
+ param: "Parameter %{value} is not valid."
23
+ uri: "URI %{value} is not valid."
24
+ value: "Value %{value} is not in allowed range."
25
+ warn:
26
+ deprecated: This method has been deprecated.
27
+ test:
28
+ kotoba: word
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
+ es:
20
+ error:
21
+ nil: parámetro nulo no permitido.
22
+ param: "El parámetro %{value} no es válido."
23
+ uri: "URI %{value} no es válido."
24
+ value: "Valor %{value} no está dentro del rango permitido."
25
+ warn:
26
+ deprecated: Este método ha quedado obsoleto.
27
+ test:
28
+ kotoba: palabra
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
+ fr:
20
+ error:
21
+ nil: paramètre nul pas autorisé.
22
+ param: "Paramètre %{value} n'est pas valide."
23
+ uri: "URI %{value} n'est pas valide."
24
+ value: "Valeur %{value} n'est pas dans la plage autorisée."
25
+ warn:
26
+ deprecated: Cette méthode a été déconseillée.
27
+ test:
28
+ kotoba: mot
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
+ hu:
20
+ error:
21
+ nil: nulla paraméter nem megengedett.
22
+ param: "Paraméter %{value} nem érvényes."
23
+ uri: "URI %{value} nem érvényes."
24
+ value: "Érték %{value} nem a megengedett tartományban."
25
+ warn:
26
+ deprecated: Ez a módszer már elavult.
27
+ test:
28
+ kotoba: hír
29
+ test: test data