kanjidic 0.3.0 → 0.4.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kanjidic +83 -0
  3. data/lib/kanjidic.rb +7 -0
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d84cedfc8f473322799717d3323f921467f10a87
4
- data.tar.gz: 330e0ec676b954de1173e782009ff2da206bc976
3
+ metadata.gz: 7a84afcc6326773e3dce339b1a5e7308d6ff38c4
4
+ data.tar.gz: dfb53b89d2eefe510953ae9c3352239eb87b2e4a
5
5
  SHA512:
6
- metadata.gz: 7e36868efafa9aa48252192ae3e3de1dc2fedc4329acf6297dd7b60e6ad49be7a83202380fdc25f5139fe07ca4e94927ceb3e995485f6fc8e9b7d6ceb7453288
7
- data.tar.gz: fb481fcbde65c81a239bc86e5d259ed8b99fc519cc542b084af5e3dc2e9017f1f8e9e1c1278895dfa4d76c4f33b9e592fccfcf8de425449da9dc64156f1784e1
6
+ metadata.gz: 3abbfb813e3532e9c37aba8349ccf6c18369a3ead426b13e4e3f51e0570233b5ed4bf45a8171886c823b398dea72e1eced94d6c5aa5bde0b8d738a6a2cbf8686
7
+ data.tar.gz: ed7999d8710a4cebe97106c937812eaf9dca3f6b6ee925d73b9d4857ded86249f3c7141f3c971ebb4bdbe9827aeb302485f1ea0ff85dbff9e1d5c8423d1b7fb8
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "kanjidic"
4
+ require "optparse"
5
+ require "irb"
6
+
7
+ file_name = ARGV[0]
8
+ defaults = { file: file_name, jis: 0, ext_jis: [1, 2] }
9
+ raise "No such file #{file_name}" unless File.exist? file_name
10
+ options = {}
11
+
12
+ OptionParser.new do |opts|
13
+
14
+ opts.banner = "Usage: \tkanjidic FILE [options]\n\t\t\tkanjidic FILE [options] -e {expression}"
15
+
16
+ opts.on("-e EXPRESSION", "--expression EXPRESSION", "Run a Ruby expression inside the context of the dictionary") do |e|
17
+ options[:expression] = e
18
+ end
19
+
20
+ opts.on("-J PREFIX", "--JIS-prefix=PREFIX", "Run the dictionary with a custom prefix (only works with custom dictionary file)") do |p|
21
+ options[:jis] = p unless options[:file].nil?
22
+ end
23
+
24
+ opts.on("-x FILES", "--extensions=FILES", "Parse and add FILES to the dictionary") do |f|
25
+ options[:extensions] = f.split(";")
26
+ end
27
+
28
+ opts.on("--extensions-JIS=PREFIX", "Sets the prefixes for additional files.") do |p|
29
+ options[:ext_jis] = p.is_a?(Number) ? [p] : p
30
+ end
31
+
32
+ opts.on_head("-h", "--help", "Print this message") do
33
+ puts opts
34
+ exit
35
+ end
36
+
37
+ end.parse!
38
+
39
+ options = defaults.merge options
40
+
41
+ Kanjidic.open(options[:file], options[:jis])
42
+ if options[:extensions]
43
+ [options[:extensions], options[:ext_jis]].transpose.each do |ext, code|
44
+ Kanjidic.expand ext, code
45
+ end
46
+ end
47
+
48
+ if(e = options[:expression])
49
+ puts eval(e, Kanjidic.binding)
50
+ else
51
+ module Kanjidic
52
+ @@dic.freeze
53
+
54
+ def self.about arg = nil
55
+ unless arg.nil?
56
+ puts case arg
57
+ when Hash
58
+ arg.to_a.map { |k,v|
59
+ "#{k}".ljust(25) + "#{v}"
60
+ }.join("\n")
61
+ when Array
62
+ arg.join(", ")
63
+ else
64
+ arg
65
+ end
66
+ else
67
+ puts <<~HELP
68
+ All commands are evaluated inside the Kanjidic module (see library documentation for more information).
69
+ Unknown commands are redirected to the @@dic Array which contains the dictionary.
70
+ For example, to search for all kanji which can be pronunced "あ", type the command 'find_all { |k| k[:reading].include? "あ" }'
71
+
72
+ Type 'about symbols' to print a list of the symbols composing kanji Hashes
73
+ HELP
74
+ end
75
+ end
76
+ end
77
+ IRB.setup nil
78
+ IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
79
+ require 'irb/ext/multi-irb'
80
+ puts "Type 'about' for informations about this software."
81
+ puts "Type 'exit' to terminate the session."
82
+ IRB.irb nil, Kanjidic
83
+ end
@@ -282,6 +282,13 @@ module Kanjidic
282
282
  coded_symboles.merge(uncoded_symbols)
283
283
  end
284
284
 
285
+ # Alias for Kanjidic::all_symbols
286
+ #
287
+ # See Kanjidic::all_symbols
288
+ def self.symbols
289
+ all_symbols
290
+ end
291
+
285
292
  # Returns a hash of all symbols and their String representations
286
293
  def self.coded_symboles
287
294
  dictionaries.to_a.map { |e|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanjidic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Leclercq
@@ -12,10 +12,12 @@ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to extract and explore the KANJIDIC (http://ftp.monash.edu.au/pub/nihongo/kanjidic.html)
14
14
  email: maisbiensurqueoui@gmail.com
15
- executables: []
15
+ executables:
16
+ - kanjidic
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/kanjidic
19
21
  - lib/kanjidic.rb
20
22
  homepage: http://www.github.com/de-passage/kanjidic
21
23
  licenses:
@@ -37,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
39
  version: '0'
38
40
  requirements: []
39
41
  rubyforge_project:
40
- rubygems_version: 2.4.5
42
+ rubygems_version: 2.4.8
41
43
  signing_key:
42
44
  specification_version: 4
43
45
  summary: Extract and explore the KANJIDIC