arb-dict 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/arb-dict +2 -16
- data/lib/arb/dict/version.rb +1 -1
- data/lib/arb/dict.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fed4725735c6c23cd964c3239aa454c8d1ee6c0
|
4
|
+
data.tar.gz: 3d304afaea8cc21216649e1da5c9b080dec183a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 393b0a99314750af6b1730a1e2df06f1b1fe542a0bc3bd36e8e410efc4a7bab7e4af46c0a12610e398513bc35f03192c770f717a6db1e9ae46838b731751ff70
|
7
|
+
data.tar.gz: 88498063f8e6d35ad56c51d703a69e6edca97b6bcb8f14c89eea5c643f1432eb1e48955528be87f97a8b04213b3b2c158bc998e41f2a8f27296d1c4bdb233ce4
|
data/bin/arb-dict
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
2
|
+
require 'arb/dict'
|
3
3
|
require 'csv'
|
4
4
|
require 'slop'
|
5
5
|
require 'json'
|
6
|
-
require 'open-uri'
|
7
6
|
|
8
|
-
def strict_value(str,default)
|
9
|
-
return default unless str
|
10
|
-
return default if str.is_a? String and str.size<=0
|
11
|
-
str
|
12
|
-
end
|
13
7
|
|
14
8
|
define_method :fmt_json do |main_hash,*args|
|
15
9
|
puts main_hash.to_json
|
@@ -57,15 +51,7 @@ if opts
|
|
57
51
|
end
|
58
52
|
end
|
59
53
|
opts.args.each do |entity|
|
60
|
-
|
61
|
-
main_hash = { entity: entity }
|
62
|
-
if entity.ascii_only?
|
63
|
-
main_hash[:phonetic_us]=strict_value(tmp_hash['sm'],'No US Phonetic')
|
64
|
-
main_hash[:phonetic_uk]=strict_value(tmp_hash['uksm'],'No UK Phonetic')
|
65
|
-
else
|
66
|
-
main_hash[:phonetic]=strict_value(tmp_hash['sm'],'No Phonetic')
|
67
|
-
end
|
68
|
-
main_hash[:translation]=strict_value(tmp_hash['basic'],'No Translation')
|
54
|
+
main_hash=Arb::Dict.query(entity)
|
69
55
|
send "fmt_#{opts[:format]}", main_hash,opts[:separator]
|
70
56
|
end
|
71
57
|
end
|
data/lib/arb/dict/version.rb
CHANGED
data/lib/arb/dict.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'arb/dict/version'
|
2
5
|
|
3
6
|
module Arb
|
4
7
|
module Dict
|
5
|
-
|
8
|
+
def self.query(entity)
|
9
|
+
tmp_hash = JSON.parse(open("http://dict.youdao.com/jsonresult?q=#{URI.encode(entity)}&type=1").read)
|
10
|
+
main_hash = { entity: entity }
|
11
|
+
if entity.ascii_only?
|
12
|
+
main_hash[:phonetic_us]=strict_value(tmp_hash['sm'],'No US Phonetic')
|
13
|
+
main_hash[:phonetic_uk]=strict_value(tmp_hash['uksm'],'No UK Phonetic')
|
14
|
+
else
|
15
|
+
main_hash[:phonetic]=strict_value(tmp_hash['sm'],'No Phonetic')
|
16
|
+
end
|
17
|
+
main_hash[:translation]=strict_value(tmp_hash['basic'],'No Translation')
|
18
|
+
main_hash
|
19
|
+
end
|
20
|
+
private
|
21
|
+
def self.strict_value(str,default)
|
22
|
+
return default unless str
|
23
|
+
return default if str.is_a? String and str.size<=0
|
24
|
+
str
|
25
|
+
end
|
6
26
|
end
|
7
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arb-dict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arybin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|