geekdict 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +22 -0
- data/README.md +28 -14
- data/geekdict.gemspec +6 -3
- data/lib/geekdict/cli.rb +2 -1
- data/lib/geekdict/debugger.rb +28 -0
- data/lib/geekdict/version.rb +2 -2
- data/lib/geekdict/youdao/api.rb +6 -2
- data/lib/geekdict.rb +8 -1
- data/spec/cli_spec.rb +4 -3
- data/spec/debugger_spec.rb +12 -0
- metadata +6 -6
- data/.gitignore +0 -8
- data/.ruby-version +0 -1
- data/lib/geekdict/google/.keep +0 -0
- data/spec/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0138aaba499bd255fbb35130ca866f99ab890df6
|
4
|
+
data.tar.gz: 01481941caefb8036fdbe54859b41dffef843d4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
5
|
+
Install
|
6
|
+
-------
|
7
|
+
You can install via rubygems:
|
6
8
|
|
7
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
17
|
-
s.
|
18
|
-
s.
|
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
|
data/lib/geekdict/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module GeekDict
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/lib/geekdict/youdao/api.rb
CHANGED
@@ -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
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
|
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.
|
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-
|
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/
|
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
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.1
|
data/lib/geekdict/google/.keep
DELETED
File without changes
|
data/spec/.keep
DELETED
File without changes
|