kanjidic 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/bin/kanjidic +9 -2
- data/lib/kanjidic.rb +37 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cb9fc88a4e195baca868cb39878d4c8691072ce
|
|
4
|
+
data.tar.gz: 5c070cc640d2f802662ad5dac854ded9f90717cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18763a461c35e4e02353ab06813eefe926767aeacf1bfbaafd7ecc40f4233fc6b6e784dd0b2eae67fa52bf55952c658acde4095e1f8dc19bb9f69c05a9a542bc
|
|
7
|
+
data.tar.gz: 8d229595ec660f8db02849bcaf379585fecc794aaf165d29ece4adfdf7a7ae7f19bcff1cb556fe2d1fb2c7201d1588c80b53fa0c78c4d4423e5eb31359110755
|
data/bin/kanjidic
CHANGED
|
@@ -5,13 +5,20 @@ require "optparse"
|
|
|
5
5
|
require "irb"
|
|
6
6
|
|
|
7
7
|
file_name = ARGV[0]
|
|
8
|
+
unless file_name
|
|
9
|
+
$stderr.puts "Usage:\n\tkanjidic FILE [options]\n\tkanjidic FILE [options] -e {expression}"
|
|
10
|
+
exit
|
|
11
|
+
end
|
|
12
|
+
unless File.exist? file_name
|
|
13
|
+
$stderr.puts "No such file: #{file_name}"
|
|
14
|
+
exit
|
|
15
|
+
end
|
|
8
16
|
defaults = { file: file_name, jis: 0, ext_jis: [1, 2] }
|
|
9
|
-
raise "No such file #{file_name}" unless File.exist? file_name
|
|
10
17
|
options = {}
|
|
11
18
|
|
|
12
19
|
OptionParser.new do |opts|
|
|
13
20
|
|
|
14
|
-
opts.banner = "Usage
|
|
21
|
+
opts.banner = "Usage:\n\tkanjidic FILE [options]\n\tkanjidic FILE [options] -e {expression}"
|
|
15
22
|
|
|
16
23
|
opts.on("-e EXPRESSION", "--expression EXPRESSION", "Run a Ruby expression inside the context of the dictionary") do |e|
|
|
17
24
|
options[:expression] = e
|
data/lib/kanjidic.rb
CHANGED
|
@@ -214,7 +214,7 @@ module Kanjidic
|
|
|
214
214
|
# Takes a boolean parameter to indicate whether the regexp should be constructed from
|
|
215
215
|
# scratches as opposed to retrieved from a cached value, false by default (returns the cache).
|
|
216
216
|
#
|
|
217
|
-
#The resulting regexp will return matches as follow:
|
|
217
|
+
# The resulting regexp will return matches as follow:
|
|
218
218
|
#
|
|
219
219
|
# 3 groups (code, sub code, value) if the element is code based,
|
|
220
220
|
#
|
|
@@ -283,8 +283,6 @@ module Kanjidic
|
|
|
283
283
|
end
|
|
284
284
|
|
|
285
285
|
# Alias for Kanjidic::all_symbols
|
|
286
|
-
#
|
|
287
|
-
# See Kanjidic::all_symbols
|
|
288
286
|
def self.symbols
|
|
289
287
|
all_symbols
|
|
290
288
|
end
|
|
@@ -301,7 +299,7 @@ module Kanjidic
|
|
|
301
299
|
}.to_h)
|
|
302
300
|
end
|
|
303
301
|
|
|
304
|
-
# Return a hash of all symboles not associated with a letter code
|
|
302
|
+
# Return a hash of all symboles not associated with a letter code.
|
|
305
303
|
#
|
|
306
304
|
# The values are the description strings
|
|
307
305
|
def self.uncoded_symbols
|
|
@@ -347,6 +345,22 @@ module Kanjidic
|
|
|
347
345
|
end
|
|
348
346
|
end
|
|
349
347
|
|
|
348
|
+
|
|
349
|
+
# Basic search tool matching any entry in the dictionary that matches the conditions
|
|
350
|
+
# given in parameter
|
|
351
|
+
#
|
|
352
|
+
# Example:
|
|
353
|
+
# search pronunciation: "あ", jlpt: '1'
|
|
354
|
+
def self.search h = {}
|
|
355
|
+
raise "Load the dictionary before searching" unless @@dic
|
|
356
|
+
@@dic.select do |kanji|
|
|
357
|
+
h.inject(true) do |acc, a|
|
|
358
|
+
key, value = a
|
|
359
|
+
acc && _include?(value, kanji[key])
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
350
364
|
# Insert values in a hash depending on the previous content of the hash
|
|
351
365
|
#
|
|
352
366
|
# Essentially a deep_merge implementation..
|
|
@@ -391,5 +405,24 @@ module Kanjidic
|
|
|
391
405
|
}
|
|
392
406
|
r ? " (#{r[:character]})" : ""
|
|
393
407
|
end
|
|
408
|
+
|
|
409
|
+
private_class_method def self._include? value, target
|
|
410
|
+
case target
|
|
411
|
+
when Hash
|
|
412
|
+
value.is_a?(Hash) ?
|
|
413
|
+
(value.to_a.inject(true) { |acc, a|
|
|
414
|
+
k, v = a
|
|
415
|
+
acc && (target[k] == v)
|
|
416
|
+
}) : false
|
|
417
|
+
when Array
|
|
418
|
+
value.is_a?(Array) ?
|
|
419
|
+
(value.inject(true) { |acc, e|
|
|
420
|
+
acc && target.include?(e)
|
|
421
|
+
}) : target.include?(value)
|
|
422
|
+
|
|
423
|
+
else
|
|
424
|
+
value == target
|
|
425
|
+
end
|
|
426
|
+
end
|
|
394
427
|
end
|
|
395
428
|
|