arb-dict 0.1.8 → 0.2.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.
- checksums.yaml +4 -4
- data/bin/arb-dict +11 -4
- data/lib/arb/dict/version.rb +1 -1
- 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: b214c7c10d773613245dba86caa18295da2d08e9
|
4
|
+
data.tar.gz: 4c55d7e6356b7204f38e1a517c3c0ca8f69a32e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f711661b908e8c7224c257e9cc73dab2b89b51bd6302a076e8b7022522d245b267f54a14dcb176a2af3809fea17e5847bc00369126579b3ba2d47b0d797973
|
7
|
+
data.tar.gz: 72644150cbec7620239c0f8e8790eb8e2a9ebf01f913fb29d02574836bc5ff20a8a5a8ff731087928c47ed5f65c4fdfa188ff3233cb44c9ba2185a10100edc0f
|
data/bin/arb-dict
CHANGED
@@ -5,6 +5,12 @@ require 'slop'
|
|
5
5
|
require 'json'
|
6
6
|
require 'open-uri'
|
7
7
|
|
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
|
+
|
8
14
|
define_method :fmt_json do |main_hash,*args|
|
9
15
|
puts main_hash.to_json
|
10
16
|
end
|
@@ -36,18 +42,19 @@ rescue Slop::UnknownOption
|
|
36
42
|
puts 'Unknown options!'
|
37
43
|
end
|
38
44
|
|
45
|
+
|
39
46
|
if opts
|
40
47
|
entity = opts.args.first
|
41
48
|
if entity
|
42
49
|
tmp_hash = JSON.parse(open("http://dict.youdao.com/jsonresult?q=#{URI.encode(entity)}&type=1").read)
|
43
50
|
main_hash = { entity: entity }
|
44
51
|
if entity.ascii_only?
|
45
|
-
main_hash[:phonetic_us]=(tmp_hash['sm']
|
46
|
-
main_hash[:phonetic_uk]=(tmp_hash['uksm']
|
52
|
+
main_hash[:phonetic_us]=strict_value(tmp_hash['sm'],'No US Phonetic')
|
53
|
+
main_hash[:phonetic_uk]=strict_value(tmp_hash['uksm'],'No UK Phonetic')
|
47
54
|
else
|
48
|
-
main_hash[:phonetic]=(tmp_hash['sm']
|
55
|
+
main_hash[:phonetic]=strict_value(tmp_hash['sm'],'No Phonetic')
|
49
56
|
end
|
50
|
-
main_hash[:translation]=(tmp_hash['basic']
|
57
|
+
main_hash[:translation]=strict_value(tmp_hash['basic'],'No Translation')
|
51
58
|
send "fmt_#{opts[:format]}", main_hash,opts[:separator]
|
52
59
|
else
|
53
60
|
puts 'Missing target, please specify a word or phrase!'
|
data/lib/arb/dict/version.rb
CHANGED