gingerice 1.1.0 → 1.2.0
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/README.markdown +80 -57
- data/gingerice.gemspec +1 -0
- data/lib/gingerice.rb +0 -1
- data/lib/gingerice/command.rb +23 -25
- data/lib/gingerice/parser.rb +30 -12
- data/lib/gingerice/version.rb +1 -1
- data/test/test_gingerice.rb +58 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6087ed695413b5137a1bbb35d6c1c83a0bad3f3e
|
4
|
+
data.tar.gz: 41acc2f5e49bc2552b7836abd17effdf5629d647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5a6e945f6fe1150fe33ea6cff165975c199f198e9560918472f7b5c68a3527b72617f372403266ba79dace2115c5c1e18802e656f494029d52efb58610f8583
|
7
|
+
data.tar.gz: 3e16022c40bd5ccdbe91913e1ac3b8f5e95de6883f2868c46ec4da4d3026ce5c89081d0b4aa9204d43a9cd344da14524c7918ea4a04b9a132304142bbff8f141
|
data/README.markdown
CHANGED
@@ -6,79 +6,98 @@ Ruby wrapper of Ginger Proofreader which corrects spelling and grammar mistakes
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'gingerice'
|
11
|
+
```
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
|
-
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
14
18
|
|
15
19
|
Or install it yourself as:
|
16
20
|
|
17
|
-
|
21
|
+
```bash
|
22
|
+
$ gem install gingerice
|
23
|
+
```
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
```ruby
|
28
|
+
require 'gingerice'
|
29
|
+
|
30
|
+
text = 'The smelt of fliwers bring back memories.'
|
31
|
+
|
32
|
+
parser = Gingerice::Parser.new
|
33
|
+
parser.parse text
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
```
|
38
|
+
# output:
|
39
|
+
|
40
|
+
{
|
41
|
+
"text" => "The smelt of fliwers bring back memories.",
|
42
|
+
"result" => "The smell of flowers brings back memories.",
|
43
|
+
"corrections" => [
|
44
|
+
[0] {
|
45
|
+
"text" => "smelt",
|
46
|
+
"correct" => "smell",
|
47
|
+
"definition" => nil
|
48
|
+
},
|
49
|
+
[1] {
|
50
|
+
"text" => "fliwers",
|
51
|
+
"correct" => "flowers",
|
52
|
+
"definition" => "a plant cultivated for its blooms or blossoms"
|
53
|
+
},
|
54
|
+
[2] {
|
55
|
+
"text" => "bring",
|
56
|
+
"correct" => "brings",
|
57
|
+
"definition" => nil
|
58
|
+
}
|
59
|
+
]
|
60
|
+
}
|
61
|
+
```
|
51
62
|
|
52
63
|
This gem also provides executable which can be executed:
|
53
64
|
|
54
|
-
|
65
|
+
```bash
|
66
|
+
$ gingerice "Edwards will be sck yesterday"
|
67
|
+
```
|
55
68
|
|
56
|
-
|
57
|
-
|
58
|
-
|
69
|
+
```
|
70
|
+
# output:
|
71
|
+
|
72
|
+
Edwards was sick yesterday
|
73
|
+
```
|
59
74
|
|
60
75
|
Or if you want verbose output you can add `--verbose` or `-v` argument:
|
61
76
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
```bash
|
78
|
+
$ gingerice --verbose "Edwards will be sck yesterday"
|
79
|
+
```
|
80
|
+
|
81
|
+
```
|
82
|
+
# output:
|
83
|
+
|
84
|
+
{
|
85
|
+
"text" => "Edwards will be sck yesterday",
|
86
|
+
"result" => "Edwards was sick yesterday",
|
87
|
+
"corrections" => [
|
88
|
+
[0] {
|
89
|
+
"text" => "will be",
|
90
|
+
"correct" => "was",
|
91
|
+
"definition" => nil
|
92
|
+
},
|
93
|
+
[1] {
|
94
|
+
"text" => "sck",
|
95
|
+
"correct" => "sick",
|
96
|
+
"definition" => "affected by an impairment of normal physical or mental function"
|
97
|
+
}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
```
|
82
101
|
|
83
102
|
## Contributing
|
84
103
|
|
@@ -88,6 +107,10 @@ Or if you want verbose output you can add `--verbose` or `-v` argument:
|
|
88
107
|
4. Push to the branch (`git push origin my-new-feature`)
|
89
108
|
5. Create new Pull Request
|
90
109
|
|
110
|
+
## Ports
|
111
|
+
|
112
|
+
- Python library by @Azd325: https://github.com/Azd325/gingerit
|
113
|
+
|
91
114
|
## Thanks
|
92
115
|
|
93
116
|
Thank you for [Ginger Proofreader](http://www.gingersoftware.com/) for such awesome service. Hope they will keep it free :)
|
data/gingerice.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "simplecov"
|
23
24
|
spec.add_development_dependency "coveralls"
|
24
25
|
|
25
26
|
spec.add_dependency "addressable"
|
data/lib/gingerice.rb
CHANGED
data/lib/gingerice/command.rb
CHANGED
@@ -6,21 +6,18 @@ require 'gingerice/version'
|
|
6
6
|
module Gingerice
|
7
7
|
class Command
|
8
8
|
|
9
|
-
attr_reader :args, :
|
9
|
+
attr_reader :args, :args_parser, :options
|
10
10
|
|
11
11
|
def initialize(args)
|
12
12
|
@args = args
|
13
|
-
|
13
|
+
@args << '-h' if @args.empty?
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
options[:api_version] = Gingerice::Parser::GINGER_VERSION
|
19
|
-
options[:api_key] = Gingerice::Parser::GINGER_API_KEY
|
20
|
-
options[:lang] = Gingerice::Parser::DEFAULT_LANG
|
21
|
-
options[:verbose] = false
|
15
|
+
@options = Gingerice::Parser.default_options.merge({ :verbose => false })
|
16
|
+
@args_parser = args_parser
|
17
|
+
end
|
22
18
|
|
23
|
-
|
19
|
+
def args_parser
|
20
|
+
OptionParser.new do |opt|
|
24
21
|
opt.banner = 'Usage: gingerice [options] "some texts"'
|
25
22
|
|
26
23
|
opt.on("--api-endpoint API_ENDPOINT", "Set API endpoint") do |endpoint|
|
@@ -28,7 +25,7 @@ module Gingerice
|
|
28
25
|
end
|
29
26
|
|
30
27
|
opt.on("--api-version API_VERSION", "Set API version") do |version|
|
31
|
-
options[:
|
28
|
+
options[:api_version] = version
|
32
29
|
end
|
33
30
|
|
34
31
|
opt.on("--api-key API_KEY", "Set API key") do |api_key|
|
@@ -44,30 +41,31 @@ module Gingerice
|
|
44
41
|
end
|
45
42
|
|
46
43
|
opt.on("--version", "Show version") do
|
47
|
-
|
48
|
-
exit
|
44
|
+
options[:show] = :version
|
49
45
|
end
|
50
46
|
|
51
47
|
opt.on_tail("-h", "--help", "Show this message") do
|
52
|
-
|
53
|
-
exit
|
48
|
+
options[:show] = :help
|
54
49
|
end
|
55
|
-
end
|
56
50
|
|
57
|
-
|
58
|
-
|
51
|
+
opt.parse!(args)
|
52
|
+
end
|
59
53
|
end
|
60
54
|
|
61
55
|
def execute
|
62
|
-
options
|
56
|
+
if options.has_key?(:show)
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
case options[:show]
|
59
|
+
when :help
|
60
|
+
puts args_parser
|
61
|
+
when :version
|
62
|
+
puts "Gingerice: #{Gingerice::VERSION}"
|
63
|
+
end
|
68
64
|
|
69
|
-
|
70
|
-
|
65
|
+
else
|
66
|
+
parser_opts = options.select { |k, _| Parser.default_options.keys.include?(k) }
|
67
|
+
parser = Parser.new(parser_opts)
|
68
|
+
response = parser.parse(args.last)
|
71
69
|
|
72
70
|
if options[:verbose]
|
73
71
|
ap response
|
data/lib/gingerice/parser.rb
CHANGED
@@ -4,18 +4,17 @@ require 'json'
|
|
4
4
|
|
5
5
|
module Gingerice
|
6
6
|
class Parser
|
7
|
-
|
8
|
-
|
9
|
-
GINGER_API_KEY
|
10
|
-
DEFAULT_LANG
|
7
|
+
GINGER_API_ENDPOINT = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
|
8
|
+
GINGER_API_VERSION = '2.0'
|
9
|
+
GINGER_API_KEY = '6ae0c3a0-afdc-4532-a810-82ded0054236'
|
10
|
+
DEFAULT_LANG = 'US'
|
11
11
|
|
12
|
-
|
12
|
+
attr_accessor :lang, :api_key, :api_version, :api_endpoint
|
13
13
|
|
14
14
|
def initialize(options = {})
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@api_endpoint = options.fetch(:api_endpoint, GINGER_ENDPOINT)
|
15
|
+
merge_options(options).each do |key, value|
|
16
|
+
send("#{key}=", value)
|
17
|
+
end
|
19
18
|
end
|
20
19
|
|
21
20
|
def parse(text)
|
@@ -31,7 +30,24 @@ module Gingerice
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
33
|
+
def self.default_options
|
34
|
+
{
|
35
|
+
:api_endpoint => Gingerice::Parser::GINGER_API_ENDPOINT,
|
36
|
+
:api_version => Gingerice::Parser::GINGER_API_VERSION,
|
37
|
+
:api_key => Gingerice::Parser::GINGER_API_KEY,
|
38
|
+
:lang => Gingerice::Parser::DEFAULT_LANG
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
34
42
|
protected
|
43
|
+
def merge_options(options)
|
44
|
+
options.select! do |key, _|
|
45
|
+
Parser.default_options.include?(key)
|
46
|
+
end
|
47
|
+
|
48
|
+
Parser.default_options.merge(options)
|
49
|
+
end
|
50
|
+
|
35
51
|
def response_processor(text, content)
|
36
52
|
data = JSON.parse(content)
|
37
53
|
i = 0
|
@@ -49,7 +65,9 @@ module Gingerice
|
|
49
65
|
corrections << {
|
50
66
|
'text' => text[from..to],
|
51
67
|
'correct' => r['Suggestions'][0]['Text'],
|
52
|
-
'definition' => r['Suggestions'][0]['Definition']
|
68
|
+
'definition' => r['Suggestions'][0]['Definition'],
|
69
|
+
'start' => from,
|
70
|
+
'length' => to.to_i - from.to_i + 1
|
53
71
|
}
|
54
72
|
end
|
55
73
|
|
@@ -65,8 +83,8 @@ module Gingerice
|
|
65
83
|
|
66
84
|
def request_params
|
67
85
|
{
|
68
|
-
'lang'
|
69
|
-
'apiKey'
|
86
|
+
'lang' => lang,
|
87
|
+
'apiKey' => api_key,
|
70
88
|
'clientVersion' => api_version
|
71
89
|
}
|
72
90
|
end
|
data/lib/gingerice/version.rb
CHANGED
data/test/test_gingerice.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
require 'simplecov'
|
1
2
|
require 'coveralls'
|
2
|
-
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
|
9
|
+
SimpleCov.start
|
3
10
|
|
4
11
|
require 'stringio'
|
5
12
|
module Kernel
|
@@ -14,7 +21,6 @@ module Kernel
|
|
14
21
|
end
|
15
22
|
|
16
23
|
require 'test/unit'
|
17
|
-
require 'gingerice/parser'
|
18
24
|
require 'gingerice/command'
|
19
25
|
|
20
26
|
class TestGingerice < Test::Unit::TestCase
|
@@ -30,8 +36,8 @@ class TestGingerice < Test::Unit::TestCase
|
|
30
36
|
end
|
31
37
|
|
32
38
|
def test_default_settings
|
33
|
-
assert_equal Gingerice::Parser::
|
34
|
-
assert_equal Gingerice::Parser::
|
39
|
+
assert_equal Gingerice::Parser::GINGER_API_ENDPOINT, @parser.api_endpoint
|
40
|
+
assert_equal Gingerice::Parser::GINGER_API_VERSION, @parser.api_version
|
35
41
|
assert_equal Gingerice::Parser::GINGER_API_KEY, @parser.api_key
|
36
42
|
assert_equal Gingerice::Parser::DEFAULT_LANG, @parser.lang
|
37
43
|
end
|
@@ -50,6 +56,8 @@ class TestGingerice < Test::Unit::TestCase
|
|
50
56
|
assert_equal text, result['text']
|
51
57
|
assert_equal 'The smell of flowers brings back memories.', result['result']
|
52
58
|
assert_equal 3, result['corrections'].count
|
59
|
+
assert_equal 4, result['corrections'].first['start']
|
60
|
+
assert_equal 5, result['corrections'].first['length']
|
53
61
|
end
|
54
62
|
|
55
63
|
def test_exceptions
|
@@ -57,7 +65,7 @@ class TestGingerice < Test::Unit::TestCase
|
|
57
65
|
assert_equal 'getaddrinfo: Name or service not known', exception.message
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
68
|
+
def test_command_simple_output
|
61
69
|
output = capture_stdout do
|
62
70
|
command = Gingerice::Command.new(["Edwards will be sck yesterday"])
|
63
71
|
command.execute
|
@@ -65,12 +73,56 @@ class TestGingerice < Test::Unit::TestCase
|
|
65
73
|
assert_equal "Edwards was sick yesterday\n", output.string
|
66
74
|
end
|
67
75
|
|
68
|
-
def
|
76
|
+
def test_command_verbose_output
|
77
|
+
output = capture_stdout do
|
78
|
+
command = Gingerice::Command.new(["-v", "He flyed to Jakarta"])
|
79
|
+
command.execute
|
80
|
+
end
|
81
|
+
assert_match 'corrections', output.string
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_command_help_usage
|
69
85
|
output = capture_stdout do
|
70
86
|
command = Gingerice::Command.new([])
|
71
87
|
command.execute
|
72
88
|
end
|
73
89
|
assert_match "Usage:", output.string
|
74
90
|
end
|
91
|
+
|
92
|
+
def test_command_show_version
|
93
|
+
output = capture_stdout do
|
94
|
+
command = Gingerice::Command.new(['--version'])
|
95
|
+
command.execute
|
96
|
+
end
|
97
|
+
assert_equal "Gingerice: #{Gingerice::VERSION}\n", output.string
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_command_arg_api_endpoint
|
101
|
+
command = Gingerice::Command.new(['--api-endpoint', 'http://example.id/'])
|
102
|
+
options = command.options
|
103
|
+
|
104
|
+
assert_equal "http://example.id/", options[:api_endpoint]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_command_arg_api_version
|
108
|
+
command = Gingerice::Command.new(['--api-version', '1.0'])
|
109
|
+
options = command.options
|
110
|
+
|
111
|
+
assert_equal "1.0", options[:api_version]
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_command_arg_api_key
|
115
|
+
command = Gingerice::Command.new(['--api-key', '123456'])
|
116
|
+
options = command.options
|
117
|
+
|
118
|
+
assert_equal "123456", options[:api_key]
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_command_arg_lang
|
122
|
+
command = Gingerice::Command.new(['--lang', 'ID'])
|
123
|
+
options = command.options
|
124
|
+
|
125
|
+
assert_equal "ID", options[:lang]
|
126
|
+
end
|
75
127
|
end
|
76
128
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gingerice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alif Rachmawadi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: coveralls
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|