gingerice 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjE5MDM1NzI2YWRmMzk1YTkyYmJmZDVmNzc3NzIzMzM5MTAzNWNlMw==
5
- data.tar.gz: !binary |-
6
- Y2JhYzlhYTI1ODIzMDZmMmFiYjYzMGZmM2I2ZmY1ZGI5MWFjZGM3NA==
2
+ SHA256:
3
+ metadata.gz: 29f52a4173dabc4225ee57156931a2b8e4c5472a4c52b93bf439e1266eaae5f6
4
+ data.tar.gz: 17243cd5c4200f34d631b9cdec9cf37400fa44050edfb466e055ec4228aa61c3
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTgzMGFlNWNiN2M4ODRmOTc0ZDY4ZjA1NGI5NWJhOTYwZTc3NzU3NjEwZDYy
10
- ZWYyMTUxNzkyOWI1YjdmNmY5OWQ4ZTZjNDkzMDgyMDRlZDIxMDU4MTgwNzJl
11
- NGNiNGZlY2RmMjlkN2IyMDMwZmNkMzA1MmE2NDk4MmRkZjE3Mjc=
12
- data.tar.gz: !binary |-
13
- Yjg2Zjc0MGM2NzdiNGQ2YWJjM2E2ZThmZTY1OTgxZTkxMzE2MmIzNmRhNjZk
14
- MzM5YzlkZjM2MzcxMTExOGYxYWRhNmYxYmY4ZjFmMTg0ZjRmZDM3YTJmYWQ2
15
- OWFjM2EwMDJiYTFkZTdkZTY0ZjEwNmM0ZWJiYTg5NzQ5ZjdiMGU=
6
+ metadata.gz: 4384ec994b39850d968c3bb0336b00f658f129dce8ea037def48ed49fa559469dc6ea31954c3441585bb08c457a342f98c8749b22cc46a2c73376be34a616333
7
+ data.tar.gz: b505f5148eed7e478cd51f45d323a3cec4938823bc59f591b2a1cf0f7d6cfc28b343ac4616f4db1b2b39475765872badfec0f9863045e329503007cf4293d2bd
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
3
+ - 2.4.6
4
+ - 2.5.5
5
+ - 2.6.3
@@ -1,10 +1,9 @@
1
1
  # Gingerice
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/gingerice.png)](http://badge.fury.io/rb/gingerice)
4
- [![Build Status](https://travis-ci.org/subosito/gingerice.png)](https://travis-ci.org/subosito/gingerice)
5
- [![Coverage Status](https://coveralls.io/repos/subosito/gingerice/badge.png)](https://coveralls.io/r/subosito/gingerice)
6
- [![Dependency Status](https://gemnasium.com/subosito/gingerice.png)](https://gemnasium.com/subosito/gingerice)
7
- [![Code Climate](https://codeclimate.com/github/subosito/gingerice.png)](https://codeclimate.com/github/subosito/gingerice)
3
+ [![Gem Version](https://badge.fury.io/rb/gingerice.svg)](https://badge.fury.io/rb/gingerice)
4
+ [![Build Status](https://travis-ci.org/subosito/gingerice.svg?branch=master)](https://travis-ci.org/subosito/gingerice)
5
+ [![Coverage Status](https://coveralls.io/repos/github/subosito/gingerice/badge.svg?branch=master)](https://coveralls.io/github/subosito/gingerice?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/86b7817ae1779428f3a3/maintainability)](https://codeclimate.com/github/subosito/gingerice/maintainability)
8
7
 
9
8
  Ruby wrapper of Ginger Proofreader which corrects spelling and grammar mistakes based on the context of complete sentences by comparing each sentence to billions of similar sentences from the web.
10
9
 
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
23
24
  spec.add_development_dependency "simplecov"
24
25
  spec.add_development_dependency "coveralls"
25
26
 
@@ -11,7 +11,7 @@ module Gingerice
11
11
  @args = args
12
12
  @args << '-h' if @args.empty?
13
13
 
14
- @options = Gingerice::Parser.default_options.merge({ :verbose => false })
14
+ @options = Gingerice::Parser.default_options.merge({ :output => :simple })
15
15
  @args_parser = parse_args
16
16
  end
17
17
 
@@ -30,10 +30,10 @@ module Gingerice
30
30
  parser = Parser.new(parser_opts)
31
31
  response = parser.parse(args.last)
32
32
 
33
- if options[:verbose]
33
+ if options[:output] === :verbose
34
34
  ap response
35
35
  else
36
- puts response["result"]
36
+ puts response
37
37
  end
38
38
  end
39
39
  end
@@ -59,8 +59,17 @@ module Gingerice
59
59
  options[:lang] = lang
60
60
  end
61
61
 
62
- opt.on("-v", "--verbose", "Verbose output") do
63
- options[:verbose] = true
62
+ opt.on("-v", "--verbose", "Verbose output (deprecated: use --output verbose, instead)") do
63
+ options[:output] = :verbose
64
+ end
65
+
66
+ opt.on("-o", "--output OUTPUT", "Output type") do |output|
67
+ case output
68
+ when 'verbose'
69
+ options[:output] = :verbose
70
+ when 'count'
71
+ options[:output] = :count
72
+ end
64
73
  end
65
74
 
66
75
  opt.on("--version", "Show version") do
@@ -11,7 +11,7 @@ module Gingerice
11
11
  GINGER_API_KEY = '6ae0c3a0-afdc-4532-a810-82ded0054236'
12
12
  DEFAULT_LANG = 'US'
13
13
 
14
- attr_accessor :lang, :api_key, :api_version, :api_endpoint
14
+ attr_accessor :lang, :api_key, :api_version, :api_endpoint, :output
15
15
  attr_reader :text, :raw_response, :result
16
16
 
17
17
  def initialize(options = {})
@@ -26,7 +26,16 @@ module Gingerice
26
26
  def parse(text)
27
27
  @text = text
28
28
  perform_request
29
- process_response
29
+
30
+ case output
31
+ when :verbose
32
+ process_response
33
+ when :simple
34
+ process_response
35
+ result
36
+ when :count
37
+ process_count_response
38
+ end
30
39
  end
31
40
 
32
41
  def self.default_options
@@ -34,7 +43,8 @@ module Gingerice
34
43
  :api_endpoint => GINGER_API_ENDPOINT,
35
44
  :api_version => GINGER_API_VERSION,
36
45
  :api_key => GINGER_API_KEY,
37
- :lang => DEFAULT_LANG
46
+ :lang => DEFAULT_LANG,
47
+ :output => :verbose
38
48
  }
39
49
  end
40
50
 
@@ -60,6 +70,15 @@ module Gingerice
60
70
  end
61
71
  end
62
72
 
73
+ def process_count_response
74
+ begin
75
+ json_data = JSON.parse(raw_response)
76
+ json_data.fetch('LightGingerTheTextResult', []).length
77
+ rescue Exception => _
78
+ raise ParseError, "ERROR: We receive invalid JSON format!"
79
+ end
80
+ end
81
+
63
82
  def process_response
64
83
  begin
65
84
  json_data = JSON.parse(raw_response)
@@ -1,3 +1,3 @@
1
1
  module Gingerice
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  require 'simplecov'
2
2
  require 'coveralls'
3
3
 
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
5
5
  SimpleCov::Formatter::HTMLFormatter,
6
6
  Coveralls::SimpleCov::Formatter
7
- ]
7
+ ])
8
8
 
9
9
  SimpleCov.start
10
10
 
@@ -30,7 +30,7 @@ class TestGingerice < Test::Unit::TestCase
30
30
 
31
31
  @custom_parser = Gingerice::Parser.new({
32
32
  lang: 'ID',
33
- api_endpoint: 'http://example.id/',
33
+ api_endpoint: 'http://foo.bar/',
34
34
  api_version: '1.0',
35
35
  api_key: '123456'
36
36
  })
@@ -45,7 +45,7 @@ class TestGingerice < Test::Unit::TestCase
45
45
 
46
46
  def test_override_settings
47
47
  assert_equal 'ID', @custom_parser.lang
48
- assert_equal 'http://example.id/', @custom_parser.api_endpoint
48
+ assert_equal 'http://foo.bar/', @custom_parser.api_endpoint
49
49
  assert_equal '1.0', @custom_parser.api_version
50
50
  assert_equal '123456', @custom_parser.api_key
51
51
  end
@@ -77,14 +77,30 @@ class TestGingerice < Test::Unit::TestCase
77
77
  assert_equal ": \n", output.string
78
78
  end
79
79
 
80
+ def test_command_verbose_output_deprecated
81
+ output = capture_stdout do
82
+ command = Gingerice::Command.new(["--verbose", "He flyed to Jakarta"])
83
+ command.execute
84
+ end
85
+ assert_match 'corrections', output.string
86
+ end
87
+
80
88
  def test_command_verbose_output
81
89
  output = capture_stdout do
82
- command = Gingerice::Command.new(["-v", "He flyed to Jakarta"])
90
+ command = Gingerice::Command.new(["--output", "verbose", "He flyed to Jakarta"])
83
91
  command.execute
84
92
  end
85
93
  assert_match 'corrections', output.string
86
94
  end
87
95
 
96
+ def test_command_count_output
97
+ output = capture_stdout do
98
+ command = Gingerice::Command.new(["--output", "count", "Edwards will be sck yesterday"])
99
+ command.execute
100
+ end
101
+ assert_equal "2\n", output.string
102
+ end
103
+
88
104
  def test_command_help_usage
89
105
  output = capture_stdout do
90
106
  command = Gingerice::Command.new([])
@@ -102,10 +118,10 @@ class TestGingerice < Test::Unit::TestCase
102
118
  end
103
119
 
104
120
  def test_command_arg_api_endpoint
105
- command = Gingerice::Command.new(['--api-endpoint', 'http://example.id/'])
121
+ command = Gingerice::Command.new(['--api-endpoint', 'http://foo.bar/'])
106
122
  options = command.options
107
123
 
108
- assert_equal "http://example.id/", options[:api_endpoint]
124
+ assert_equal "http://foo.bar/", options[:api_endpoint]
109
125
  end
110
126
 
111
127
  def test_command_arg_api_version
@@ -131,12 +147,22 @@ class TestGingerice < Test::Unit::TestCase
131
147
 
132
148
  def test_request_exceptions
133
149
  exception = assert_raise(Gingerice::ConnectionError) { @custom_parser.parse('Hllo') }
134
- assert_equal "ERROR: Couldn't connect to API endpoint (http://example.id/)", exception.message
150
+ assert_equal "ERROR: Couldn't connect to API endpoint (http://foo.bar/)", exception.message
135
151
  end
136
152
 
137
153
  def test_parse_error_exceptions
138
154
  invalid_parser = Gingerice::Parser.new({
139
- api_endpoint: 'http://subosito.com/',
155
+ api_endpoint: 'https://subosito.com/',
156
+ })
157
+
158
+ exception = assert_raise(Gingerice::ParseError) { invalid_parser.parse('Hllo') }
159
+ assert_equal 'ERROR: We receive invalid JSON format!', exception.message
160
+ end
161
+
162
+ def test_parse_error_exceptions_output_count
163
+ invalid_parser = Gingerice::Parser.new({
164
+ api_endpoint: 'https://subosito.com/',
165
+ output: :count
140
166
  })
141
167
 
142
168
  exception = assert_raise(Gingerice::ParseError) { invalid_parser.parse('Hllo') }
metadata CHANGED
@@ -1,97 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gingerice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.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: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: simplecov
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: coveralls
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ! '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ! '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: addressable
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: awesome_print
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  description: Corrects spelling and grammar mistakes based on the context of complete
@@ -103,11 +117,11 @@ executables:
103
117
  extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
106
- - .editorconfig
107
- - .gitignore
108
- - .travis.yml
120
+ - ".editorconfig"
121
+ - ".gitignore"
122
+ - ".travis.yml"
109
123
  - Gemfile
110
- - README.markdown
124
+ - README.md
111
125
  - Rakefile
112
126
  - bin/gingerice
113
127
  - gingerice.gemspec
@@ -127,17 +141,16 @@ require_paths:
127
141
  - lib
128
142
  required_ruby_version: !ruby/object:Gem::Requirement
129
143
  requirements:
130
- - - ! '>='
144
+ - - ">="
131
145
  - !ruby/object:Gem::Version
132
146
  version: '0'
133
147
  required_rubygems_version: !ruby/object:Gem::Requirement
134
148
  requirements:
135
- - - ! '>='
149
+ - - ">="
136
150
  - !ruby/object:Gem::Version
137
151
  version: '0'
138
152
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.1.9
153
+ rubygems_version: 3.0.3
141
154
  signing_key:
142
155
  specification_version: 4
143
156
  summary: Corrects spelling and grammar mistakes based on the context of complete sentences.