gingerice 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aa2568c764a2f1d844124cfc9983d22ba4e06aa
4
- data.tar.gz: 4ebbb86b37f1e2f43fba0d1aa02741fe76c0c0a3
3
+ metadata.gz: dde01477e6f0cfef54d8495b7593f5abb5b56e57
4
+ data.tar.gz: 5777944483946d2208c517e0c213adad14981f32
5
5
  SHA512:
6
- metadata.gz: fc8610f79b813b40fed1bec8127e1d807f380e257fe46299cdf265b8b163257aa16ad8096461df4e587e3bf407b37c8d5ebffcb17239e7b5cdb6a3c9a869c896
7
- data.tar.gz: 7ecb04214a5f721e583aae3dc6d830acbcdc790096166e74f094799312f7f68379a45d634a7ac860e5d54268ee3b3a8f4ee68822c5d5b650efb7670398e8604f
6
+ metadata.gz: 6e636c071cddbbdf6b1022aeb1262d7bea389af150f0d182b4639d3ad400b404100a657cffc78aa87d11e7b8ef2f09dc4069264316cd40ca35ff58695bb97218
7
+ data.tar.gz: 9e8c3053ca3cab867e50a763d3ab09422dd122a1a88a2101da2f16e254cc79839189c6ed87d4918e3b2f01bbbc4175803c5b1b9b16f1b57a089f67fbd388f357
data/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- # Gingerice [![Gem Version](https://badge.fury.io/rb/gingerice.png)](http://badge.fury.io/rb/gingerice) [![Build Status](https://travis-ci.org/subosito/gingerice.png)](https://travis-ci.org/subosito/gingerice) [![Coverage Status](https://coveralls.io/repos/subosito/gingerice/badge.png)](https://coveralls.io/r/subosito/gingerice)
1
+ # Gingerice [![Gem Version](https://badge.fury.io/rb/gingerice.png)](http://badge.fury.io/rb/gingerice) [![Build Status](https://travis-ci.org/subosito/gingerice.png)](https://travis-ci.org/subosito/gingerice) [![Coverage Status](https://coveralls.io/repos/subosito/gingerice/badge.png)](https://coveralls.io/r/subosito/gingerice) [![Dependency Status](https://gemnasium.com/subosito/gingerice.png)](https://gemnasium.com/subosito/gingerice) [![Code Climate](https://codeclimate.com/github/subosito/gingerice.png)](https://codeclimate.com/github/subosito/gingerice)
2
2
 
3
3
  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.
4
4
 
@@ -20,34 +20,30 @@ Or install it yourself as:
20
20
 
21
21
  require 'gingerice'
22
22
 
23
- text = 'The smelt of fliwers bring back memories.'
23
+ text = 'The smelt of fliwers bring back memories.'
24
24
 
25
25
  parser = Gingerice::Parser.new
26
26
  parser.parse text
27
27
 
28
- # or you can:
29
- #
30
- # Gingerice::Tool.check text
31
-
32
28
  # output:
33
29
  #
34
30
  # => {
35
- # "text" => "The smelt of fliwers bring back memories.",
36
- # "result" => "The smell of flowers brings back memories.",
31
+ # "text" => "The smelt of fliwers bring back memories.",
32
+ # "result" => "The smell of flowers brings back memories.",
37
33
  # "corrections" => [
38
34
  # [0] {
39
- # "text" => "smelt",
40
- # "correct" => "smell",
35
+ # "text" => "smelt",
36
+ # "correct" => "smell",
41
37
  # "definition" => nil
42
38
  # },
43
39
  # [1] {
44
- # "text" => "fliwers",
45
- # "correct" => "flowers",
40
+ # "text" => "fliwers",
41
+ # "correct" => "flowers",
46
42
  # "definition" => "a plant cultivated for its blooms or blossoms"
47
43
  # },
48
44
  # [2] {
49
- # "text" => "bring",
50
- # "correct" => "brings",
45
+ # "text" => "bring",
46
+ # "correct" => "brings",
51
47
  # "definition" => nil
52
48
  # }
53
49
  # ]
@@ -55,12 +51,35 @@ Or install it yourself as:
55
51
 
56
52
  This gem also provides executable which can be executed:
57
53
 
58
- % gingerice "Edwards will be sick yesterday"
54
+ % gingerice "Edwards will be sck yesterday"
59
55
 
60
56
  # output :
61
57
  #
62
58
  # Edwards was sick yesterday
63
59
 
60
+ Or if you want verbose output you can add `--verbose` or `-v` argument:
61
+
62
+ % gingerice --verbose "Edwards will be sck yesterday"
63
+
64
+ # output:
65
+ #
66
+ # {
67
+ # "text" => "Edwards will be sck yesterday",
68
+ # "result" => "Edwards was sick yesterday",
69
+ # "corrections" => [
70
+ # [0] {
71
+ # "text" => "will be",
72
+ # "correct" => "was",
73
+ # "definition" => nil
74
+ # },
75
+ # [1] {
76
+ # "text" => "sck",
77
+ # "correct" => "sick",
78
+ # "definition" => "affected by an impairment of normal physical or mental function"
79
+ # }
80
+ # ]
81
+ # }
82
+
64
83
  ## Contributing
65
84
 
66
85
  1. Fork it
@@ -72,3 +91,4 @@ This gem also provides executable which can be executed:
72
91
  ## Thanks
73
92
 
74
93
  Thank you for [Ginger Proofreader](http://www.gingersoftware.com/) for such awesome service. Hope they will keep it free :)
94
+
data/bin/gingerice CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
4
4
 
5
- require 'gingerice/parser'
6
- require 'gingerice/tool'
5
+ require 'gingerice/command'
7
6
 
8
- STDOUT.puts(Gingerice::Tool.check(ARGV.shift)['result'])
7
+ command = Gingerice::Command.new(ARGV)
8
+ command.execute
9
9
 
data/gingerice.gemspec CHANGED
@@ -20,6 +20,8 @@ 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 "coveralls"
23
24
 
24
25
  spec.add_dependency "addressable"
26
+ spec.add_dependency "awesome_print"
25
27
  end
data/lib/gingerice.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'gingerice/version'
2
2
  require 'gingerice/parser'
3
+ require 'gingerice/command'
@@ -0,0 +1,81 @@
1
+ require 'optparse'
2
+ require 'awesome_print'
3
+ require 'gingerice/parser'
4
+ require 'gingerice/version'
5
+
6
+ module Gingerice
7
+ class Command
8
+
9
+ attr_reader :args, :oparser
10
+
11
+ def initialize(args)
12
+ @args = args
13
+ end
14
+
15
+ def processor
16
+ options = {}
17
+ options[:api_endpoint] = Gingerice::Parser::GINGER_ENDPOINT
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
22
+
23
+ @oparser = OptionParser.new do |opt|
24
+ opt.banner = 'Usage: gingerice [options] "some texts"'
25
+
26
+ opt.on("--api-endpoint API_ENDPOINT", "Set API endpoint") do |endpoint|
27
+ options[:api_endpoint] = endpoint
28
+ end
29
+
30
+ opt.on("--api-version API_VERSION", "Set API version") do |version|
31
+ options[:api_endpoint] = version
32
+ end
33
+
34
+ opt.on("--api-key API_KEY", "Set API key") do |api_key|
35
+ options[:api_key] = api_key
36
+ end
37
+
38
+ opt.on("--lang LANG", "Set language, currently support 'US' only") do |lang|
39
+ options[:lang] = lang
40
+ end
41
+
42
+ opt.on("-v", "--verbose", "Verbose output") do
43
+ options[:verbose] = true
44
+ end
45
+
46
+ opt.on("--version", "Show version") do
47
+ puts Gingerice::VERSION
48
+ exit
49
+ end
50
+
51
+ opt.on_tail("-h", "--help", "Show this message") do
52
+ puts opt
53
+ exit
54
+ end
55
+ end
56
+
57
+ @oparser.parse!(args)
58
+ options
59
+ end
60
+
61
+ def execute
62
+ options = processor
63
+
64
+ if args.empty?
65
+ puts oparser
66
+ else
67
+ parser_options = options.reject { |key, value| key == :verbose }
68
+
69
+ parser = Parser.new(parser_options)
70
+ response = parser.parse(args.last)
71
+
72
+ if options[:verbose]
73
+ ap response
74
+ else
75
+ puts response["result"]
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -24,43 +24,45 @@ module Gingerice
24
24
 
25
25
  begin
26
26
  open(uri) do |stream|
27
- content = stream.read
28
- data = JSON.parse(content)
29
-
30
- i = 0
31
- result = ''
32
- corrections = []
27
+ response_processor(text, stream.read)
28
+ end
29
+ rescue Exception => e
30
+ raise StandardError, e.message
31
+ end
32
+ end
33
33
 
34
- data.fetch('LightGingerTheTextResult', []).each do |r|
35
- from = r['From']
36
- to = r['To']
34
+ protected
35
+ def response_processor(text, content)
36
+ data = JSON.parse(content)
37
+ i = 0
38
+ result = ''
39
+ corrections = []
37
40
 
38
- if i <= from
39
- result += text[i..from-1] unless from.zero?
40
- result += r['Suggestions'][0]['Text']
41
+ data.fetch('LightGingerTheTextResult', []).each do |r|
42
+ from = r['From']
43
+ to = r['To']
41
44
 
42
- corrections << {
43
- 'text' => text[from..to],
44
- 'correct' => r['Suggestions'][0]['Text'],
45
- 'definition' => r['Suggestions'][0]['Definition']
46
- }
47
- end
45
+ if i <= from
46
+ result += text[i..from-1] unless from.zero?
47
+ result += r['Suggestions'][0]['Text']
48
48
 
49
- i = to+1
50
- end
49
+ corrections << {
50
+ 'text' => text[from..to],
51
+ 'correct' => r['Suggestions'][0]['Text'],
52
+ 'definition' => r['Suggestions'][0]['Definition']
53
+ }
54
+ end
51
55
 
52
- if i < text.length
53
- result += text[i..-1]
54
- end
56
+ i = to+1
57
+ end
55
58
 
56
- { 'text' => text, 'result' => result, 'corrections' => corrections}
57
- end
58
- rescue Exception => e
59
- raise StandardError, e.message
59
+ if i < text.length
60
+ result += text[i..-1]
60
61
  end
62
+
63
+ { 'text' => text, 'result' => result, 'corrections' => corrections}
61
64
  end
62
65
 
63
- protected
64
66
  def request_params
65
67
  {
66
68
  'lang' => lang,
@@ -1,3 +1,3 @@
1
1
  module Gingerice
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,38 +1,76 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'stringio'
5
+ module Kernel
6
+ def capture_stdout
7
+ out = StringIO.new
8
+ $stdout = out
9
+ yield
10
+ return out
11
+ ensure
12
+ $stdout = STDOUT
13
+ end
14
+ end
15
+
1
16
  require 'test/unit'
2
- require 'gingerice'
17
+ require 'gingerice/parser'
18
+ require 'gingerice/command'
3
19
 
4
20
  class TestGingerice < Test::Unit::TestCase
5
21
  def setup
6
22
  @parser = Gingerice::Parser.new
7
- end
8
23
 
9
- def test_default_settings
10
- assert_equal @parser.api_endpoint, Gingerice::Parser::GINGER_ENDPOINT
11
- assert_equal @parser.api_version, Gingerice::Parser::GINGER_VERSION
12
- assert_equal @parser.api_key, Gingerice::Parser::GINGER_API_KEY
13
- assert_equal @parser.lang, Gingerice::Parser::DEFAULT_LANG
14
- end
15
-
16
- def test_override_settings
17
- custom_parser = Gingerice::Parser.new({
24
+ @custom_parser = Gingerice::Parser.new({
18
25
  lang: 'ID',
19
- api_endpoint: 'http://example.com/',
26
+ api_endpoint: 'http://example.id/',
20
27
  api_version: '1.0',
21
28
  api_key: '123456'
22
29
  })
30
+ end
23
31
 
24
- assert_equal custom_parser.lang, 'ID'
25
- assert_equal custom_parser.api_endpoint, 'http://example.com/'
26
- assert_equal custom_parser.api_version, '1.0'
27
- assert_equal custom_parser.api_key, '123456'
32
+ def test_default_settings
33
+ assert_equal Gingerice::Parser::GINGER_ENDPOINT, @parser.api_endpoint
34
+ assert_equal Gingerice::Parser::GINGER_VERSION, @parser.api_version
35
+ assert_equal Gingerice::Parser::GINGER_API_KEY, @parser.api_key
36
+ assert_equal Gingerice::Parser::DEFAULT_LANG, @parser.lang
37
+ end
38
+
39
+ def test_override_settings
40
+ assert_equal 'ID', @custom_parser.lang
41
+ assert_equal 'http://example.id/', @custom_parser.api_endpoint
42
+ assert_equal '1.0', @custom_parser.api_version
43
+ assert_equal '123456', @custom_parser.api_key
28
44
  end
29
45
 
30
46
  def test_parsed_results
31
47
  text = 'The smelt of fliwers bring back memories.'
32
48
  result = @parser.parse(text)
33
49
 
34
- assert_equal result['text'], text
35
- assert_equal result['result'], 'The smell of flowers brings back memories.'
36
- assert_equal result['corrections'].count, 3
50
+ assert_equal text, result['text']
51
+ assert_equal 'The smell of flowers brings back memories.', result['result']
52
+ assert_equal 3, result['corrections'].count
53
+ end
54
+
55
+ def test_exceptions
56
+ exception = assert_raise(StandardError) { @custom_parser.parse('Hllo') }
57
+ assert_equal 'getaddrinfo: Name or service not known', exception.message
58
+ end
59
+
60
+ def test_command_usage
61
+ output = capture_stdout do
62
+ command = Gingerice::Command.new(["Edwards will be sck yesterday"])
63
+ command.execute
64
+ end
65
+ assert_equal "Edwards was sick yesterday\n", output.string
66
+ end
67
+
68
+ def test_command_help
69
+ output = capture_stdout do
70
+ command = Gingerice::Command.new([])
71
+ command.execute
72
+ end
73
+ assert_match "Usage:", output.string
37
74
  end
38
75
  end
76
+
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.0.0
4
+ version: 1.1.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-27 00:00:00.000000000 Z
11
+ date: 2013-04-28 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: coveralls
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: addressable
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Corrects spelling and grammar mistakes based on the context of complete
56
84
  sentences.
57
85
  email:
@@ -70,8 +98,8 @@ files:
70
98
  - bin/gingerice
71
99
  - gingerice.gemspec
72
100
  - lib/gingerice.rb
101
+ - lib/gingerice/command.rb
73
102
  - lib/gingerice/parser.rb
74
- - lib/gingerice/tool.rb
75
103
  - lib/gingerice/version.rb
76
104
  - test/test_gingerice.rb
77
105
  homepage: https://github.com/subosito/gingerice
@@ -1,11 +0,0 @@
1
- module Gingerice
2
- class Tool
3
- class << self
4
- def check(text, lang = 'US')
5
- parser = Parser.new(lang: lang)
6
- parser.parse(text)
7
- end
8
- end
9
- end
10
- end
11
-