yan_speller 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a2aa6f07b620da55af72b861a04dee5403bbefe
4
+ data.tar.gz: c02206c53a93ae4e931d3fce2317a7423ba8735f
5
+ SHA512:
6
+ metadata.gz: baf0917cd09707f7db5089e20c97e4bc267b1b7174a5cd93b008899668a5835ed8eed9dfac5533240f2729a2bd3313640be66b6963f060fe14b2e9a2b0402fc3
7
+ data.tar.gz: 92e1e8ebe5629397f324c9af13eb3c1388a881bb0755a12e328c54555121b42212f0408c7bbc0dcf82148beec691941814d9e086f61286ce5cfb9ee9f08bee21
@@ -0,0 +1,18 @@
1
+ module YanSpeller
2
+ class SpellError
3
+
4
+ def initialize err
5
+ err.each do |key, value|
6
+ instance_variable_set("@#{key}".to_sym, value)
7
+ end
8
+ end
9
+
10
+ def to_s
11
+ "Error in the word <#{@word}>, maybe it is better to say <#{@s}>."
12
+ end
13
+
14
+
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,28 @@
1
+ require 'net/http'
2
+ # require 'uri'
3
+
4
+ module YanSpeller
5
+ class SpellRequest
6
+
7
+ DATA_URL = 'http://speller.yandex.net/services/spellservice.json/checkText'
8
+
9
+ attr_reader :success
10
+
11
+ def initialize
12
+ @success = false
13
+ end
14
+
15
+ def send text_for_check
16
+ @success = false
17
+ uri = URI(DATA_URL)
18
+ params = { text: text_for_check, ie: 'utf-8' }
19
+ uri.query = URI.encode_www_form params
20
+ result = Net::HTTP.get_response(uri)
21
+ @success = result.is_a? Net::HTTPSuccess
22
+ result
23
+ end
24
+
25
+ alias success? success
26
+
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'spell_error'
2
+ require_relative 'spell_request'
3
+ require 'json'
4
+
5
+ module YanSpeller
6
+ class Speller
7
+ attr_reader :status
8
+
9
+ def initialize
10
+ @spell_request = SpellRequest.new
11
+ @errors = []
12
+ @status = :request_fail
13
+ end
14
+
15
+ def check_spell text
16
+ result = @spell_request.send text
17
+ if @spell_request.success?
18
+ @errors = JSON.parse(result.body).map do |err|
19
+ SpellError.new err
20
+ end
21
+ @status = @errors.empty? ? :no_spell_errors : :spell_errors
22
+ else
23
+ @status = :request_fail
24
+ end
25
+ end
26
+
27
+ def errors_to_s
28
+ @errors.map { |err| err.to_s }
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'yan_speller/speller'
2
+
3
+ module YanSpeller
4
+
5
+ MAJOR = '1'
6
+ MINOR = '0'
7
+ PATCH = '1'
8
+
9
+ def self.version
10
+
11
+ [ MAJOR, MINOR, PATCH ].join '.'
12
+
13
+ end
14
+
15
+ def self.check text
16
+ speller = Speller.new
17
+ result = speller.check_spell(text)
18
+ if result == :no_spell_errors
19
+ puts 'No errors.It is all good and right.'
20
+ elsif result == :request_fail
21
+ puts 'Fail to get an answer.'
22
+ else
23
+ puts speller.errors_to_s
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ # First option.
30
+
31
+ puts 'Type some text for spell checking:'
32
+ text = gets.chomp.to_s
33
+ p YanSpeller::check text
34
+
35
+ # Second option.
36
+ # Comment these tree lines above and use this one below:
37
+
38
+ # p YanSpeller::check " " # insert your text between this " quotes "
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yan_speller
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Alfimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem for checking spell that use Yandex.speller service
14
+ email: francuz006@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/yan_speller.rb
20
+ - lib/yan_speller/spell_error.rb
21
+ - lib/yan_speller/spell_request.rb
22
+ - lib/yan_speller/speller.rb
23
+ homepage: https://rubygems.org/gems/yan_speller
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements:
42
+ - Internet connection
43
+ - Some text to check
44
+ rubyforge_project:
45
+ rubygems_version: 2.4.5
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Check spell of your text.
49
+ test_files: []