geekdict 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2469553df77ddbe3664fb8a8a2edd965741b727d
4
- data.tar.gz: 7484c1ac4f61feabee89183636dc64b8ca0aa269
3
+ metadata.gz: 0138aaba499bd255fbb35130ca866f99ab890df6
4
+ data.tar.gz: 01481941caefb8036fdbe54859b41dffef843d4b
5
5
  SHA512:
6
- metadata.gz: 49f8ed1feae8dbe3deb945963d84110841a585ec0a70ef223663f5844888e616b841df9f4fead7f4e49fbcb8628788db9313340c7546f66d5c92595ea591974f
7
- data.tar.gz: a9dd8b1af171b4af7ccfa43e18389e55fcef10ae5f3de9b776f835e06e98a3c2ec6bee13a6e504d127c11af0e9a6e4f1518d41d91c17ff1513e9416bb7a3b14c
6
+ metadata.gz: 04a085834becee238337a9b9c464246e729ba966805171684136eafce2d548260f2030e98fca6198e1a45043c7a06786352267c14d2e6597f1f49296000ec38b
7
+ data.tar.gz: e63a66be28b9853888365a7349b46d18b283a70344eb5a1505a447cf8802ad3c6c00db0b350097347984ebd217c1bdd9e47409a63278b08f368eab0a1acda4e4
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Bruce Li<wbinglee@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,20 +2,34 @@ Geek Dict
2
2
  ---------
3
3
  A command line tool for translation.
4
4
 
5
- ## Commands
5
+ Install
6
+ -------
7
+ You can install via rubygems:
6
8
 
7
- #### Translate a word
8
- ```
9
- $dict t hello
10
- 你好
11
- ```
9
+ gem install geekdict
12
10
 
13
- #### List all my new works
14
- ```
15
- $dict list
16
- ```
17
11
 
18
- #### Set target language
19
- ```
20
- $dict settings --lang chinese
21
- ```
12
+ Commands
13
+ --------
14
+ ### Translate a word
15
+
16
+ $geekdict t test
17
+ n. 试验;检验
18
+ vt. 试验;测试
19
+ vi. 试验;测试
20
+ n. (Test)人名;(英)特斯特
21
+
22
+ TODOs
23
+ -----
24
+ It's under active development until it satisfy my needs. Below are something in my mind:
25
+ * geekdict list : List all words you have searched
26
+ * geekdict remove : Remove word you know from your new words list
27
+ * Use google translate engine as alternative, as well as supporting other target language. Low priority, only focus on Chinese.
28
+ * A simple website
29
+ - Provide own translate service to translate and save new words
30
+ - A command line interface to do the same thing like this
31
+ - A nice web page to show all your new words, which could be a good place to review the new words and remember them.
32
+
33
+ License
34
+ -------
35
+ MIT license
data/geekdict.gemspec CHANGED
@@ -13,9 +13,12 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "geekdict"
15
15
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.files = %w[LICENSE README.md geekdict.gemspec Gemfile Rakefile]
17
+ s.files += Dir.glob("bin/**/*")
18
+ s.files += Dir.glob("lib/**/*.rb")
19
+ s.files += Dir.glob("spec/**/*")
20
+ s.test_files = Dir.glob("spec/**/*")
21
+ s.executables = %w[geekdict]
19
22
  s.require_paths = ["lib"]
20
23
 
21
24
  s.add_development_dependency "rake"
data/lib/geekdict/cli.rb CHANGED
@@ -6,7 +6,9 @@ module GeekDict
6
6
 
7
7
  desc "t", "Translate a word"
8
8
  option :lang, :aliases=>'-l'
9
+ option :debug, :aliases=>'-d', :type=>:boolean,:default=>false
9
10
  def t(word)
11
+ GeekDict.debugger options[:debug]
10
12
  result = GeekDict::Youdao.translate word
11
13
  output = result.join "\n"
12
14
  puts output
@@ -15,4 +17,3 @@ module GeekDict
15
17
 
16
18
  end
17
19
  end
18
-
@@ -0,0 +1,28 @@
1
+ require 'logger'
2
+
3
+ module GeekDict
4
+ class Debugger
5
+
6
+ def initialize(enable=false)
7
+ @enable = enable
8
+ @logger = new_logger if enable
9
+ end
10
+
11
+ def debug(msg)
12
+ @logger.debug msg if @enable
13
+ end
14
+
15
+
16
+ private
17
+
18
+ def new_logger()
19
+ Logger.new(STDOUT).tap do |l|
20
+ l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
21
+ l.formatter = proc do |severity, datetime, progname, msg|
22
+ "#{datetime} : #{msg}\n"
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module GeekDict
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.2"
3
+ end
@@ -11,16 +11,20 @@ module GeekDict
11
11
  module_function
12
12
 
13
13
  def translate(word)
14
+ @debugger = GeekDict.debugger
14
15
  client = HTTPClient.new
15
16
  query = { keyfrom: APIKEYFROM, key: APIKEY, type: 'data', doctype: 'json',version: APIVERSION, q: word }
16
17
  res = client.get(APIURL, query)
18
+ @debugger.debug "Response status: #{res.status_code}"
19
+ @debugger.debug "Response Content-Type: #{res.content_type}"
20
+ @debugger.debug "Response Body: #{res.body}"
17
21
  res = JSON.parse res.body
18
22
  error_code = res['errorCode']
19
- if error_code == 0
23
+ if error_code == 0 && res['basic'] && res['basic']['explains']
20
24
  res['basic']['explains']
21
25
  else
22
26
  []
23
27
  end
24
28
  end
25
29
  end
26
- end
30
+ end
data/lib/geekdict.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  require 'geekdict/cli'
2
+ require 'geekdict/debugger'
2
3
  require 'geekdict/youdao/api'
3
4
 
4
5
  module GeekDict
5
6
 
6
- end
7
+ module_function
8
+
9
+ def debugger(enable=false)
10
+ @debugger ||= GeekDict::Debugger.new enable
11
+ end
12
+
13
+ end
data/spec/cli_spec.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require 'geekdict'
2
2
 
3
3
  describe GeekDict::CLI do
4
-
4
+
5
5
  describe 'translate good' do
6
-
6
+
7
7
  it 'should output translate result as string' do
8
8
  cli = GeekDict::CLI.new
9
9
  result = cli.t 'good'
10
10
  expect(result).to include("好")
11
11
  end
12
+
12
13
  end
13
- end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'geekdict'
2
+
3
+ describe GeekDict::Debugger do
4
+
5
+ describe 'Debug msg' do
6
+
7
+ it 'should output debug message' do
8
+ debugger = GeekDict::Debugger.new true
9
+ debugger.debug "Test bug"
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geekdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruce Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-31 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -74,21 +74,20 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".gitignore"
78
- - ".ruby-version"
79
77
  - Gemfile
78
+ - LICENSE
80
79
  - README.md
81
80
  - Rakefile
82
81
  - bin/geekdict
83
82
  - geekdict.gemspec
84
83
  - lib/geekdict.rb
85
84
  - lib/geekdict/cli.rb
86
- - lib/geekdict/google/.keep
85
+ - lib/geekdict/debugger.rb
87
86
  - lib/geekdict/version.rb
88
87
  - lib/geekdict/youdao/api.rb
89
88
  - lib/geekdict/youdao/config.rb
90
- - spec/.keep
91
89
  - spec/cli_spec.rb
90
+ - spec/debugger_spec.rb
92
91
  - spec/youdao/api_spec.rb
93
92
  homepage: ''
94
93
  licenses: []
@@ -115,4 +114,5 @@ specification_version: 4
115
114
  summary: A command line tool for translation.
116
115
  test_files:
117
116
  - spec/cli_spec.rb
117
+ - spec/debugger_spec.rb
118
118
  - spec/youdao/api_spec.rb
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- coverage
6
- *.swp
7
- .idea/*
8
- .DS_Store
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.1
File without changes
data/spec/.keep DELETED
File without changes