arb-dict 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/arb-dict +11 -4
  3. data/lib/arb/dict/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28bf5030418631822dd0b9d744288a48247f5e86
4
- data.tar.gz: 5e1482aa201e1b5347d5abbb72da90b932cb38a1
3
+ metadata.gz: b214c7c10d773613245dba86caa18295da2d08e9
4
+ data.tar.gz: 4c55d7e6356b7204f38e1a517c3c0ca8f69a32e9
5
5
  SHA512:
6
- metadata.gz: 3009afef1c314db9f1cc541e925b4da65aa76616c001ecef3c7a70ec3189db7a5283deb065c8c5ad56956ceba66581e60a2bc9228d212d0e3bc42050698c0b7d
7
- data.tar.gz: fbc07b8a14f017ba5df83c4cd63071e22ae813d7e2d2c42cf150c35ba4bef353bc6db21d0ed84a53f57b80918fd5131b0c9d7391108c74e0ea182f590dc429ab
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'] || 'No US Phonetic')
46
- main_hash[:phonetic_uk]=(tmp_hash['uksm'] || 'No UK Phonetic')
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'] || 'No Phonetic')
55
+ main_hash[:phonetic]=strict_value(tmp_hash['sm'],'No Phonetic')
49
56
  end
50
- main_hash[:translation]=(tmp_hash['basic'] || 'No Translation')
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!'
@@ -1,5 +1,5 @@
1
1
  module Arb
2
2
  module Dict
3
- VERSION = "0.1.8"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arb-dict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arybin