wwwjdic 15.0.0 → 16.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +13 -0
  3. data/Gemfile +4 -0
  4. data/README.md +6 -7
  5. data/Rakefile +4 -0
  6. data/examples/basics.rb +4 -0
  7. data/examples/translate.rb +26 -0
  8. data/examples/uri.rb +16 -0
  9. data/html/CHANGELOG.html +37 -30
  10. data/html/COPYING_md.html +22 -30
  11. data/html/Gemfile.html +25 -31
  12. data/html/Object.html +825 -63
  13. data/html/README_md.html +27 -33
  14. data/html/Rakefile.html +25 -31
  15. data/html/WWWJDic.html +42 -124
  16. data/html/WWWJDic/ParsableDuckType.html +35 -57
  17. data/html/WWWJDic/Parser.html +48 -90
  18. data/html/WWWJDic/Parsers.html +28 -36
  19. data/html/WWWJDic/Parsers/Dict.html +47 -73
  20. data/html/WWWJDic/Parsers/Display.html +42 -68
  21. data/html/WWWJDic/Parsers/Key.html +42 -68
  22. data/html/WWWJDic/Parsers/Search.html +38 -61
  23. data/html/WWWJDic/Parsers/Server.html +42 -68
  24. data/html/WWWJDic/Splitter.html +76 -173
  25. data/html/WWWJDic/Utils.html +28 -36
  26. data/html/WWWJDic/Utils/Downloader.html +28 -36
  27. data/html/WWWJDic/Utils/Downloader/Downloader.html +41 -80
  28. data/html/WWWJDic/Utils/Raisers.html +42 -96
  29. data/html/WWWJDic/WWWJDic.html +160 -342
  30. data/html/copyright_md.html +22 -30
  31. data/html/created.rid +32 -54
  32. data/html/css/rdoc.css +1 -1
  33. data/html/index.html +26 -51
  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 +153 -161
  42. data/lib/wwwjdic.rb +7 -4
  43. data/lib/wwwjdic/application.rb +52 -25
  44. data/lib/wwwjdic/constants.rb +33 -3
  45. data/lib/wwwjdic/locales/de.yml +2 -0
  46. data/lib/wwwjdic/locales/en.yml +2 -0
  47. data/lib/wwwjdic/locales/es.yml +2 -0
  48. data/lib/wwwjdic/locales/fr.yml +2 -0
  49. data/lib/wwwjdic/locales/hu.yml +2 -0
  50. data/lib/wwwjdic/locales/it.yml +2 -0
  51. data/lib/wwwjdic/locales/ja.yml +3 -1
  52. data/lib/wwwjdic/locales/nl.yml +2 -0
  53. data/lib/wwwjdic/locales/ru.yml +2 -0
  54. data/lib/wwwjdic/locales/sl.yml +2 -0
  55. data/lib/wwwjdic/locales/sv.yml +2 -0
  56. data/lib/wwwjdic/parser.rb +7 -4
  57. data/lib/wwwjdic/parsers/dict.rb +4 -1
  58. data/lib/wwwjdic/parsers/display.rb +4 -1
  59. data/lib/wwwjdic/parsers/key.rb +4 -1
  60. data/lib/wwwjdic/parsers/search.rb +4 -0
  61. data/lib/wwwjdic/parsers/server.rb +4 -1
  62. data/lib/wwwjdic/utils/downloader.rb +7 -8
  63. data/lib/wwwjdic/utils/raisers.rb +7 -13
  64. data/lib/wwwjdic/utils/splitter.rb +18 -9
  65. data/lib/wwwjdic/version.rb +5 -1
  66. data/test/test_helper.rb +4 -0
  67. data/test/test_wwwjdic.rb +4 -0
  68. data/test/wwwjdic/locales/de.yml +2 -0
  69. data/test/wwwjdic/locales/en.yml +2 -0
  70. data/test/wwwjdic/locales/es.yml +2 -0
  71. data/test/wwwjdic/locales/fr.yml +2 -0
  72. data/test/wwwjdic/locales/hu.yml +2 -0
  73. data/test/wwwjdic/locales/it.yml +2 -0
  74. data/test/wwwjdic/locales/ja.yml +2 -0
  75. data/test/wwwjdic/locales/nl.yml +2 -0
  76. data/test/wwwjdic/locales/ru.yml +2 -0
  77. data/test/wwwjdic/locales/sl.yml +2 -0
  78. data/test/wwwjdic/locales/sv.yml +2 -0
  79. data/test/wwwjdic/locales/test_locales.rb +35 -19
  80. data/test/wwwjdic/parsers/test_dict.rb +62 -36
  81. data/test/wwwjdic/parsers/test_display.rb +4 -0
  82. data/test/wwwjdic/parsers/test_key.rb +4 -0
  83. data/test/wwwjdic/parsers/test_server.rb +4 -0
  84. data/test/wwwjdic/test_application.rb +196 -148
  85. data/test/wwwjdic/test_parsable_duck_type.rb +4 -3
  86. data/test/wwwjdic/utils/test_downloader.rb +4 -0
  87. data/test/wwwjdic/utils/test_raisers.rb +42 -27
  88. data/wwwjdic.gemspec +14 -11
  89. metadata +19 -33
data/lib/wwwjdic.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -34,7 +38,6 @@ require_relative 'wwwjdic/parsers/server'
34
38
  # Copyright:: (C) 2014 Marco Bresciani
35
39
  # License:: GNU General Public License version 3
36
40
  module WWWJDic
37
-
38
41
  # Creates a new WWWJDic object (from the verb 'to Breen'... :) ).
39
42
  #
40
43
  # Usage::
@@ -46,9 +49,9 @@ module WWWJDic
46
49
 
47
50
  # Provides the parameters' parsers object.
48
51
  def self.parser
49
- parsers = {dict: Parsers::Dict.new, display: Parsers::Display.new,
50
- key: Parsers::Key.new, search: Parsers::Search.new,
51
- server: Parsers::Server.new}
52
+ parsers = { dict: Parsers::Dict.new, display: Parsers::Display.new,
53
+ key: Parsers::Key.new, search: Parsers::Search.new,
54
+ server: Parsers::Server.new }
52
55
 
53
56
  Parser.new parsers
54
57
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -36,7 +40,6 @@ module WWWJDic
36
40
  # Copyright:: (C) 2014 Marco Bresciani
37
41
  # License:: GNU General Public License version 3
38
42
  class WWWJDic
39
-
40
43
  # Creates a +WWWJDic+ object. This constructor should be used
41
44
  # through the WWWJDic::breener method only.
42
45
  #
@@ -57,20 +60,15 @@ module WWWJDic
57
60
  def uri(word = nil, args = {})
58
61
  raise ArgumentError, I18n.t('error.nil') if word.nil?
59
62
  raise ArgumentError, I18n.t('error.param', value: word) if word.empty?
60
- raise ArgumentError, I18n.t('error.param', value: args) unless args.keys.to_set.proper_subset? Set.new(ALLOWED_PARAMS)
61
-
62
- params = {}
63
- params[:search] = word
64
- @defaults[:search] = word
65
63
 
66
- unless args.nil?
67
- ALL_PARAMS.each do |param_name|
68
- params[param_name] = @parser.parse(param_name.to_s, args.fetch(param_name, @defaults[param_name]))
69
- end
64
+ unless args.keys.to_set.proper_subset? Set.new(ALLOWED_PARAMS)
65
+ raise ArgumentError,
66
+ I18n.t('error.param', value: args)
70
67
  end
71
68
 
72
- a_wwwjdic = URIS[params[:server]] + params[:dict] + DISPLAY[params[:display]] + params[:search] + KEYS[params[:key]]
73
- a_wwwjdic + CGI::escape(word).to_s
69
+ params = parse_params(args, word)
70
+
71
+ build_uri(params, word)
74
72
  end
75
73
 
76
74
  # Create the reference uri for a +word+ translation, according to
@@ -123,19 +121,7 @@ module WWWJDic
123
121
  def json_translate(word = nil, args = {}, filename = nil)
124
122
  translation = translate(word, args)
125
123
 
126
- a_hash = {}
127
- a_hash[word.to_sym] = raw_uri(word, args)
128
-
129
- the_splitter = Splitter.new translation
130
-
131
- a_hash[:title] = the_splitter.title
132
- a_hash[:translation] = the_splitter.translation
133
- a_hash[:message] = the_splitter.message
134
-
135
- unless a_hash[:translation].nil?
136
- a_hash[:lines] = the_splitter.lines
137
- a_hash[:content] = the_splitter.content
138
- end
124
+ a_hash = build_hash(args, translation, word)
139
125
 
140
126
  result = a_hash.to_json
141
127
 
@@ -207,7 +193,9 @@ module WWWJDic
207
193
  # romaji conversion if the key is not in Japanese coding (UTF-8,
208
194
  # EUC or Shift_JIS.) If you want to look up using "sensei" it has
209
195
  # to be a J. For anything else the value of J doesn't matter much.
196
+ # rubocop:disable Style/AsciiComments
210
197
  # 1MUJ齧歯 and 1MUE齧歯 will both find 齧歯. 1MUJgesshi does too,
198
+ # rubocop:enable Style/AsciiComments
211
199
  # but 1MUEgesshi won't.
212
200
  #
213
201
  # I think you have missed a key point I made in my previous email:
@@ -235,5 +223,44 @@ module WWWJDic
235
223
  def to_s
236
224
  @wwwjdic.to_s
237
225
  end
226
+
227
+ private
228
+
229
+ def build_hash(args, translation, word)
230
+ the_splitter = Splitter.new translation
231
+
232
+ a_hash = { word.to_sym => raw_uri(word, args),
233
+ title: the_splitter.title,
234
+ translation: the_splitter.translation,
235
+ message: the_splitter.message }
236
+
237
+ unless a_hash[:translation].nil?
238
+ a_hash[:lines] = the_splitter.lines
239
+ a_hash[:content] = the_splitter.content
240
+ end
241
+ a_hash
242
+ end
243
+
244
+ def build_uri(params, word)
245
+ a_wwwjdic = URIS[params[:server]] +
246
+ params[:dict] +
247
+ DISPLAY[params[:display]] +
248
+ params[:search] +
249
+ KEYS[params[:key]]
250
+ a_wwwjdic + CGI.escape(word).to_s
251
+ end
252
+
253
+ def parse_params(args, word)
254
+ params = {}
255
+ params[:search] = word
256
+ @defaults[:search] = word
257
+
258
+ unless args.nil?
259
+ ALL_PARAMS.each do |param_name|
260
+ params[param_name] = @parser.parse(param_name.to_s, args.fetch(param_name, @defaults[param_name]))
261
+ end
262
+ end
263
+ params
264
+ end
238
265
  end
239
266
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -32,7 +36,33 @@ module WWWJDic
32
36
  DICTIONARY_CODES = [('1'..'9').to_a, ('A'..'R').to_a].flatten
33
37
 
34
38
  # 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
39
+ DICTIONARY_NAMES = ['Jpn-Eng General (EDICT)',
40
+ 'Japanese Names (ENAMDICT)',
41
+ 'Computing/Telecomms',
42
+ 'Life Sciences/Bio-Med',
43
+ 'Legal Terms',
44
+ 'Finance/Marketing',
45
+ 'Buddhism',
46
+ 'Miscellaneous',
47
+ 'Special Text-glossing',
48
+ 'Engineering/Science',
49
+ 'Linguistics',
50
+ 'River & Water Systems',
51
+ 'Automobile Industry',
52
+ 'Japanese Wordnet',
53
+ 'Work-in-progress File',
54
+ 'Japanese-German (WaDoku)',
55
+ 'Japanese-French',
56
+ 'Japanese-Russian',
57
+ 'Japanese-Swedish',
58
+ 'Japanese-Hungarian',
59
+ 'Japanese-Spanish',
60
+ 'Japanese-Dutch',
61
+ 'Japanese-Slovenian',
62
+ 'Japanese-Italian',
63
+ 'Untranslated',
64
+ 'Combined Jpn-Eng',
65
+ 'Expanded Text-glossing'].freeze
36
66
 
37
67
  # Mapping between dictionaries names with codes
38
68
  DICTS_BY_CODES = Hash[DICTIONARY_CODES.zip(DICTIONARY_NAMES)]
@@ -111,10 +141,10 @@ module WWWJDic
111
141
  henshall: 'E', pinyin: 'Y' }.freeze
112
142
 
113
143
  # Reference URI for Backdoor Entry/API
114
- URI_DEFAULT = 'http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi?'.freeze
144
+ URI_DEFAULT = 'http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi?'
115
145
 
116
146
  # Monash URI for Backdoor Entry/API
117
- URI_OLD = 'http://nihongo.monash.edu/cgi-bin/wwwjdic?'.freeze
147
+ URI_OLD = 'http://nihongo.monash.edu/cgi-bin/wwwjdic?'
118
148
 
119
149
  # URIs for Backdoor Entry/API
120
150
  URIS = { edrdg: URI_DEFAULT, monash: URI_OLD }.freeze
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,7 +1,9 @@
1
1
  #--
2
2
  # wwwjdic
3
- # (C) 2013 新部裕
3
+ # © 2013 新部裕
4
+ # rubocop:disable Style/AsciiComments
4
5
  # © 2014 Marco Bresciani
6
+ # rubocop:enable Style/AsciiComments
5
7
  #
6
8
  # This file is part of wwwjdic.
7
9
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,8 @@
1
1
  #--
2
2
  # wwwjdic
3
+ # rubocop:disable Style/AsciiComments
3
4
  # © 2014 Marco Bresciani
5
+ # rubocop:enable Style/AsciiComments
4
6
  #
5
7
  # This file is part of wwwjdic.
6
8
  #
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -25,7 +29,6 @@
25
29
  require_relative 'constants'
26
30
 
27
31
  module WWWJDic
28
-
29
32
  # This class is a simple utility that is used to parse and filter
30
33
  # parameters for wwwjdic.
31
34
  #
@@ -41,10 +44,10 @@ module WWWJDic
41
44
  end
42
45
 
43
46
  # Provides the duck type for a generic parsing object.
44
- def parse(method = nil, value = nil)
47
+ def parse(method = nil, params = nil)
45
48
  a_parser = nil
46
- a_parser = parsers[method.to_sym] unless method.nil? or parsers.nil?
47
- a_parser&.parse value
49
+ a_parser = parsers[method.to_sym] unless method.nil? || parsers.nil?
50
+ a_parser&.parse params
48
51
  end
49
52
  end
50
53
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -27,7 +31,6 @@ require_relative '../utils/raisers'
27
31
 
28
32
  module WWWJDic
29
33
  module Parsers
30
-
31
34
  # This class is an implementation of the Parsable duck type that
32
35
  # checks the dictionary type. The only needed parameter is a valid
33
36
  # dictionary.
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -26,7 +30,6 @@ require_relative '../constants'
26
30
 
27
31
  module WWWJDic
28
32
  module Parsers
29
-
30
33
  # This class is an implementation of the Parsable duck type that
31
34
  # checks the display type. The only needed parameter is a boolean,
32
35
  # with +true+ for regular.
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -26,7 +30,6 @@ require_relative '../constants'
26
30
 
27
31
  module WWWJDic
28
32
  module Parsers
29
-
30
33
  # This class is an implementation of the Parsable duck type that
31
34
  # checks the display type. The only needed parameter is the word to
32
35
  # translate.
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # wwwjdic
5
+ # rubocop:disable Style/AsciiComments
3
6
  # © 2014 Marco Bresciani
7
+ # rubocop:enable Style/AsciiComments
4
8
  #
5
9
  # This file is part of wwwjdic.
6
10
  #
@@ -26,7 +30,6 @@ require_relative '../constants'
26
30
 
27
31
  module WWWJDic
28
32
  module Parsers
29
-
30
33
  # This class is an implementation of the Parsable duck type that
31
34
  # checks the display type. The only needed parameter is a boolean,
32
35
  # with +true+ for regular.