arb-dict 0.1.6 → 0.1.8
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 +16 -11
- 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: 28bf5030418631822dd0b9d744288a48247f5e86
|
4
|
+
data.tar.gz: 5e1482aa201e1b5347d5abbb72da90b932cb38a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3009afef1c314db9f1cc541e925b4da65aa76616c001ecef3c7a70ec3189db7a5283deb065c8c5ad56956ceba66581e60a2bc9228d212d0e3bc42050698c0b7d
|
7
|
+
data.tar.gz: fbc07b8a14f017ba5df83c4cd63071e22ae813d7e2d2c42cf150c35ba4bef353bc6db21d0ed84a53f57b80918fd5131b0c9d7391108c74e0ea182f590dc429ab
|
data/bin/arb-dict
CHANGED
@@ -10,14 +10,17 @@ define_method :fmt_json do |main_hash,*args|
|
|
10
10
|
end
|
11
11
|
|
12
12
|
define_method :fmt_csv do |main_hash,separator|
|
13
|
-
|
14
|
-
puts tmp_arr.to_csv
|
13
|
+
puts main_hash.values.map{|tmp| next tmp.join(separator) if tmp.is_a? Array;tmp}.to_csv
|
15
14
|
end
|
16
15
|
|
17
16
|
define_method :fmt_raw do |main_hash,*args|
|
18
17
|
puts main_hash[:entity], ''
|
19
|
-
|
20
|
-
|
18
|
+
if main_hash[:entity].ascii_only?
|
19
|
+
puts "US[#{main_hash[:phonetic_us]}]"
|
20
|
+
puts "UK[#{main_hash[:phonetic_uk]}]"
|
21
|
+
else
|
22
|
+
puts "Phonetic[#{main_hash[:phonetic]}]"
|
23
|
+
end
|
21
24
|
puts ''
|
22
25
|
puts main_hash[:translation]
|
23
26
|
end
|
@@ -25,7 +28,7 @@ end
|
|
25
28
|
begin
|
26
29
|
opts = Slop.parse do |o|
|
27
30
|
o.string *%w{-f --format}, 'available choices: json,csv,raw(default)', default: 'raw'
|
28
|
-
o.string *%w{-s --separator},'
|
31
|
+
o.string *%w{-s --separator},'separator used in array#join in csv format(default: NEWLINE)',default: "\n"
|
29
32
|
end
|
30
33
|
rescue Slop::MissingArgument
|
31
34
|
puts 'Missing arguments!'
|
@@ -37,12 +40,14 @@ if opts
|
|
37
40
|
entity = opts.args.first
|
38
41
|
if entity
|
39
42
|
tmp_hash = JSON.parse(open("http://dict.youdao.com/jsonresult?q=#{URI.encode(entity)}&type=1").read)
|
40
|
-
main_hash = {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
main_hash = { entity: entity }
|
44
|
+
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')
|
47
|
+
else
|
48
|
+
main_hash[:phonetic]=(tmp_hash['sm'] || 'No Phonetic')
|
49
|
+
end
|
50
|
+
main_hash[:translation]=(tmp_hash['basic'] || 'No Translation')
|
46
51
|
send "fmt_#{opts[:format]}", main_hash,opts[:separator]
|
47
52
|
else
|
48
53
|
puts 'Missing target, please specify a word or phrase!'
|
data/lib/arb/dict/version.rb
CHANGED