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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/arb-dict +16 -11
  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: ff8c1fa03b78d918c55d8b7192c73c0286d0d2e5
4
- data.tar.gz: e3dea50d00516853f8ba872ee3236e49066651c0
3
+ metadata.gz: 28bf5030418631822dd0b9d744288a48247f5e86
4
+ data.tar.gz: 5e1482aa201e1b5347d5abbb72da90b932cb38a1
5
5
  SHA512:
6
- metadata.gz: ca187d3e303a2a0c43118536ca449399b2a3dc7e48fbb6a89ba984ffc5b6c88a41b91b09f49d6a2f1c2069dc6135b4ed888aa998534d499a3621a2ac72ccf91f
7
- data.tar.gz: 76e7ef3204cefee61be98a6880bf664d2a3a5bf48d4e6ed4d4ae36d960ea6e0b365c6c5025b347286e32f261598cb70dabcc9db3a5e5f8f230d230679e9b3187
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
- tmp_arr = [main_hash[:entity], main_hash[:phonetic_us], main_hash[:phonetic_uk],main_hash[:translation].join(separator)]
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
- puts "US[#{main_hash[:phonetic_us]}]"
20
- puts "UK[#{main_hash[:phonetic_uk]}]"
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},'translations separator used in csv format(default: NEWLINE)',default: "\n"
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
- entity: entity,
42
- phonetic_us: (tmp_hash['sm'] || 'No US Phonetic'),
43
- phonetic_uk: (tmp_hash['uksm'] || 'No UK Phonetic'),
44
- translation: (tmp_hash['basic'] || 'No Translation')
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!'
@@ -1,5 +1,5 @@
1
1
  module Arb
2
2
  module Dict
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.8"
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.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - arybin