ruen_speller 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruen_speller.rb +15 -0
- data/lib/ruen_speller/all_requires.rb +10 -0
- data/lib/ruen_speller/answer.rb +22 -0
- data/lib/ruen_speller/controller.rb +56 -0
- data/lib/ruen_speller/data.rb +9 -0
- data/lib/ruen_speller/http_requests.rb +39 -0
- data/lib/ruen_speller/request.rb +34 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22f322800ef090af57108d8457deab463d659859
|
4
|
+
data.tar.gz: 1ea9a875a83fbc787324a7b26b895f2ce6cfe430
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43df3f56b7f878d783849416aec4db316ba5ac0f67b575835c1b69d95d1832c45b03a11af3b40238454fa44c569e0a07f5c5067b1740307559f16027f3b1ec80
|
7
|
+
data.tar.gz: de634a8ea8a5313d31781052504526d6851dc3e1183780b1e311bffa56b3da1039c3884812399de0f441a3a3a7d67f37f510a1771dea4fe8f69cb627b1a7f64e
|
data/lib/ruen_speller.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'ruen_speller/all_requires'
|
2
|
+
|
3
|
+
module RuenSpeller
|
4
|
+
|
5
|
+
ERRORS_CLASSES = [:IncorrectDataError, :PermissibleNumberError]
|
6
|
+
ERRORS_CLASSES.each { |err| const_set err, Class.new(StandardError) }
|
7
|
+
|
8
|
+
def self.correct?(*text)
|
9
|
+
raise (PermissibleNumberError) if text.join('').split('').size > 10000
|
10
|
+
Array.wrap(Controller.new.check_text(text))
|
11
|
+
rescue IncorrectDataError
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RuenSpeller
|
2
|
+
|
3
|
+
class Answer
|
4
|
+
|
5
|
+
attr_reader :request_value, :checked_values
|
6
|
+
@@answers_buffer = Array.new
|
7
|
+
|
8
|
+
def self.get_answers_buffer
|
9
|
+
@@answers_buffer
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(req_text, check_text)
|
13
|
+
@request_value = req_text
|
14
|
+
@checked_values = check_text
|
15
|
+
@@answers_buffer << @request_value
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"'#{@request_value}' : #{@checked_values}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'all_requires'
|
2
|
+
|
3
|
+
module RuenSpeller
|
4
|
+
|
5
|
+
class Controller
|
6
|
+
|
7
|
+
include HttpRequests
|
8
|
+
|
9
|
+
def check_text(text_to_check)
|
10
|
+
|
11
|
+
data_validate(text_to_check)
|
12
|
+
@answers = json_parse! send_request(text_to_check, set_request_type(text_to_check))
|
13
|
+
|
14
|
+
if all_correct?
|
15
|
+
true
|
16
|
+
else
|
17
|
+
@answers
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def json_parse!(data)
|
24
|
+
JSON.parse(data).map! do |record|
|
25
|
+
record["s"] = ["unrecognized"] if record["s"].empty?
|
26
|
+
Answer.new(record["word"], record["s"])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def all_correct?
|
31
|
+
unless Request.get_questions_buffer.empty?
|
32
|
+
Answer.get_answers_buffer.empty?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def data_validate data
|
37
|
+
data.map! do |entry|
|
38
|
+
unless entry.kind_of?(String)
|
39
|
+
unless entry.kind_of?(TrueClass || FalseClass)
|
40
|
+
entry.consta
|
41
|
+
else
|
42
|
+
entry
|
43
|
+
end
|
44
|
+
else
|
45
|
+
entry
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_request_type data
|
51
|
+
data.last == true ? true : false
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'all_requires'
|
2
|
+
|
3
|
+
module RuenSpeller
|
4
|
+
|
5
|
+
module HttpRequests
|
6
|
+
|
7
|
+
def send_request(request_text, request_is_post = false)
|
8
|
+
|
9
|
+
request_arguments = prepare(request_text).request_string
|
10
|
+
|
11
|
+
if request_is_post
|
12
|
+
uri = URI(URI.encode(Data::DATA_URL))
|
13
|
+
Net::HTTP.post_form(uri, {"text" => "#{request_arguments}"}).body
|
14
|
+
else
|
15
|
+
Net::HTTP.get URI(URI.encode(Data::DATA_URL+"?text=#{request_arguments}"))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def prepare(data)
|
22
|
+
|
23
|
+
if data.length == 1
|
24
|
+
Request.new(data.first)
|
25
|
+
elsif data.length > 1
|
26
|
+
Request.new(data.join(" "))
|
27
|
+
elsif data.empty?
|
28
|
+
Request.new data
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'all_requires'
|
2
|
+
|
3
|
+
module RuenSpeller
|
4
|
+
|
5
|
+
class Request
|
6
|
+
|
7
|
+
@@questions_buffer = Array.new
|
8
|
+
|
9
|
+
def self.get_questions_buffer
|
10
|
+
return @@questions_buffer
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :request_string
|
14
|
+
|
15
|
+
def initialize data
|
16
|
+
|
17
|
+
if data.blank?
|
18
|
+
raise IncorrectDataError
|
19
|
+
elsif data.split("").include?(" ")
|
20
|
+
@@questions_buffer = data.split(" ")
|
21
|
+
data = @@questions_buffer.join("+")
|
22
|
+
else
|
23
|
+
@@questions_buffer << data
|
24
|
+
end
|
25
|
+
|
26
|
+
@request_string = "#{data}"
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{@request_string}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruen_speller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timo Moss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: |
|
28
|
+
This simple gem I has done in training.
|
29
|
+
It checking the spelling English or Russian text wiht tech.yandex.ru/speller site.
|
30
|
+
email: javatimomoss@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/ruen_speller.rb
|
36
|
+
- lib/ruen_speller/all_requires.rb
|
37
|
+
- lib/ruen_speller/answer.rb
|
38
|
+
- lib/ruen_speller/controller.rb
|
39
|
+
- lib/ruen_speller/data.rb
|
40
|
+
- lib/ruen_speller/http_requests.rb
|
41
|
+
- lib/ruen_speller/request.rb
|
42
|
+
homepage: http://rubygems.org/gem/speller
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements:
|
61
|
+
- Internet connection
|
62
|
+
- Enough courage to use it
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.4.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: "Сheck the spelling of your text"
|
68
|
+
test_files: []
|