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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f9706cab70071fb817f4febe78e93b365d7c05b
4
- data.tar.gz: d19a6d233367b9cdbd2fbdae23a295292b9bef4a
3
+ metadata.gz: 8fed4725735c6c23cd964c3239aa454c8d1ee6c0
4
+ data.tar.gz: 3d304afaea8cc21216649e1da5c9b080dec183a4
5
5
  SHA512:
6
- metadata.gz: a4a20d1dd29d663569db2527e47b55466ff9c992fbb335f74f10af32668696eb96707b529cfdca5ef9c1af61f83890dc6fcd0a21b8ef99742684ceb9f4c2c136
7
- data.tar.gz: a95526f179a5a3d302c298dc25983e9e3531ab11dff4ea1c33089ee06a55d00a4c0d8078f1aa8623b5640ec2339797b82ed1241b88a0f5724a1af3811eb6751c
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 'uri'
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
- tmp_hash = JSON.parse(open("http://dict.youdao.com/jsonresult?q=#{URI.encode(entity)}&type=1").read)
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
@@ -1,5 +1,5 @@
1
1
  module Arb
2
2
  module Dict
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
data/lib/arb/dict.rb CHANGED
@@ -1,7 +1,27 @@
1
- require "arb/dict/version"
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
- # Your code goes here...
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.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-21 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop