corrector 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +67 -0
- data/CHANGELOG.rdoc +13 -0
- data/LICENSE.rdoc +21 -0
- data/README.rdoc +81 -0
- data/Rakefile +43 -0
- data/app/models/corrector/base.rb +36 -0
- data/app/models/corrector/phrase.rb +9 -0
- data/app/models/corrector/prefix.rb +30 -0
- data/app/models/corrector/word.rb +10 -0
- data/app/services/corrector/cyrillic.rb +36 -0
- data/app/services/corrector/parse.rb +66 -0
- data/app/services/corrector/words.rb +71 -0
- data/db/migrate/20141014223624_create_corrector_bases.rb +13 -0
- data/lib/corrector/engine.rb +12 -0
- data/lib/corrector/version.rb +6 -0
- data/lib/corrector.rb +6 -0
- data/lib/tasks/corrector_tasks.rake +7 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +26 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +25007 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/206/7F1/UNITS%2F%D0%9A%D0%98%D0%9B%D0%9E%D0%9C%D0%95%D0%A2%D0%A0%D0%90+%D0%92+%D0%A7%D0%90%D0%A1 +1 -0
- data/spec/dummy/tmp/cache/262/AB1/UNITS%2F%D0%9A%D0%98%D0%9B%D0%9E%D0%9C%D0%95%D0%A2%D0%A0%D0%9E%D0%92%2F%D0%A7%D0%90%D0%A1 +1 -0
- data/spec/dummy/tmp/cache/D58/820/UNITS%2F3+%D0%9A%D0%98%D0%9B%D0%9E%D0%9C%D0%95%D0%A2%D0%A0%D0%90 +1 -0
- data/spec/dummy/tmp/cache/E42/C10/UNITS%2F100+%D0%9C%D0%95%D0%A2%D0%A0%D0%9E%D0%92%2F%D0%A7%D0%90%D0%A1 +1 -0
- data/spec/factories/bases.rb +7 -0
- data/spec/factories/phrases.rb +7 -0
- data/spec/factories/prefixes.rb +7 -0
- data/spec/factories/words.rb +7 -0
- data/spec/models/corrector/base_spec.rb +90 -0
- data/spec/models/corrector/phrase_spec.rb +11 -0
- data/spec/models/corrector/prefix_spec.rb +35 -0
- data/spec/models/corrector/word_spec.rb +22 -0
- data/spec/services/corrector/cyrillic_spec.rb +26 -0
- data/spec/services/corrector/parse_spec.rb +58 -0
- data/spec/services/corrector/words_spec.rb +62 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/initializers/caching.rb +12 -0
- data/spec/support/initializers/coveralls.rb +4 -0
- data/spec/support/initializers/database_cleaner.rb +24 -0
- data/spec/support/initializers/factory_girl_rails.rb +5 -0
- data/spec/support/initializers/focus.rb +5 -0
- data/spec/support/initializers/garbage_collection.rb +11 -0
- data/spec/support/initializers/i18n.rb +1 -0
- data/spec/support/initializers/migrations.rb +3 -0
- data/spec/support/initializers/rails.rb +6 -0
- data/spec/support/initializers/random_order.rb +4 -0
- data/spec/support/initializers/rspec.rb +10 -0
- metadata +306 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b840557d16354f3fe065e83e369989379096a7e
|
4
|
+
data.tar.gz: 6807ca775443e5c58ecc2fb739b36e80a6f9c860
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c545c92bc3405f417bcc31035fd3aa5e93c3448017d3bb30bcda96583fd01b114bedd519bece232c344c163d4581e01a4d233ceb75b1a35f85a90610b1263e7
|
7
|
+
data.tar.gz: 6cbd1701c9419b6bbe5d6661a98e59ba13c46ea9f897d7b17df03cb165fe90afbd7cc139fc58f4b3b8519395521748113c12caa520aeeac68629983ca70222a7
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'spec/dummy/**/*'
|
4
|
+
- 'Rakefile'
|
5
|
+
|
6
|
+
Lint/HandleExceptions:
|
7
|
+
Exclude:
|
8
|
+
- 'spec/**/*'
|
9
|
+
|
10
|
+
Lint/RescueException:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/*'
|
13
|
+
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Exclude:
|
16
|
+
- 'db/**/*'
|
17
|
+
|
18
|
+
Style/AccessorMethodName:
|
19
|
+
Exclude:
|
20
|
+
- 'spec/**/*'
|
21
|
+
|
22
|
+
Style/AsciiComments:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/ClassAndModuleChildren:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
32
|
+
- 'db/**/*'
|
33
|
+
|
34
|
+
Style/EmptyLinesAroundBody:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/EmptyLineBetweenDefs:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*'
|
40
|
+
|
41
|
+
Style/PredicateName:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/RaiseArgs:
|
45
|
+
EnforcedStyle: compact
|
46
|
+
|
47
|
+
Style/SingleLineBlockParams:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/SingleLineMethods:
|
51
|
+
Exclude:
|
52
|
+
- 'spec/**/*'
|
53
|
+
|
54
|
+
Style/SpecialGlobalVars:
|
55
|
+
Exclude:
|
56
|
+
- 'Gemfile'
|
57
|
+
- '*.gemspec'
|
58
|
+
|
59
|
+
Style/StringLiterals:
|
60
|
+
EnforcedStyle: double_quotes
|
61
|
+
|
62
|
+
Style/SingleSpaceBeforeFirstArg:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/TrivialAccessors:
|
66
|
+
Exclude:
|
67
|
+
- 'spec/**/*'
|
data/CHANGELOG.rdoc
ADDED
data/LICENSE.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Andrew Kozin, https://github.com/nepalez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= Corrector
|
2
|
+
|
3
|
+
{<img src="http://img.shields.io/gem/v/corrector.svg?style=flat" alt="Gem Version" />}[https://rubygems.org/gems/corrector]
|
4
|
+
{<img src="http://img.shields.io/travis/nepalez/corrector.svg?style=flat" alt="Bild Status" />}[https://travis-ci.org/nepalez/corrector]
|
5
|
+
{<img src="http://img.shields.io/codeclimate/github/nepalez/corrector.svg?style=flat" alt="Code Metrics" />}[https://codeclimate.com/github/nepalez/corrector]
|
6
|
+
{<img src="http://img.shields.io/gemnasium/nepalez/corrector.svg?style=flat" alt="Dependency Status" />}[https://gemnasium.com/nepalez/corrector]
|
7
|
+
{<img src="http://img.shields.io/coveralls/nepalez/corrector.svg?style=flat" alt="Coverage Status" />}[https://coveralls.io/r/nepalez/corrector]
|
8
|
+
{<img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License" />}[https://github.com/nepalez/corrector/blob/master/LICENSE.rdoc]
|
9
|
+
|
10
|
+
== About
|
11
|
+
|
12
|
+
Rails plugin for cyrillic texts correction using words and phrases dictionary.
|
13
|
+
|
14
|
+
It defines two dictionaries:
|
15
|
+
|
16
|
+
+Word+:: A dictionary of words
|
17
|
+
+Prefix+:: A dictionary of word prefixes
|
18
|
+
+Phrase+:: A dictionary of phrases
|
19
|
+
|
20
|
+
and a service +Parse+ that:
|
21
|
+
|
22
|
+
* converts a source text to uppercase cyrillic one;
|
23
|
+
* breaks it to words;
|
24
|
+
* corrects any single word using +Prefix+ and +Word+ dictionaries;
|
25
|
+
* puts corrected words back to sentence;
|
26
|
+
* corrects the sentence using the +Phrase+ dictionary;
|
27
|
+
* returns the result.
|
28
|
+
|
29
|
+
The model is expected to be used as a part of various classificators - to allow
|
30
|
+
searching items by words in Russian.
|
31
|
+
|
32
|
+
=== Example
|
33
|
+
|
34
|
+
After adding some words and phrases:
|
35
|
+
|
36
|
+
Prefix.create! from: "КИЛО", to: "К", source: "UNITS"
|
37
|
+
Word.create! from: "МЕТРОВ", to: "М", source: "UNITS"
|
38
|
+
Word.create! from: "СЕКУНДУ", to: "С", source: "UNITS"
|
39
|
+
Phrase.create! from: "КМ В С", to: "ТЫС М/С", source: "UNITS"
|
40
|
+
|
41
|
+
the phrase can be corrected properly:
|
42
|
+
|
43
|
+
Parse.new "килоmетров в секyndу", source: "UNITS" # => "ТЫС М/С"
|
44
|
+
|
45
|
+
== Installation
|
46
|
+
|
47
|
+
Add this line to your application's Gemfile:
|
48
|
+
|
49
|
+
gem "corrector"
|
50
|
+
|
51
|
+
And then execute:
|
52
|
+
|
53
|
+
$ bundle
|
54
|
+
|
55
|
+
Or install it yourself as:
|
56
|
+
|
57
|
+
$ gem install corrector
|
58
|
+
|
59
|
+
== Initialization
|
60
|
+
|
61
|
+
You should copy db migrations to your project and then run the migrations.
|
62
|
+
|
63
|
+
=== in a Rails application
|
64
|
+
|
65
|
+
$ rake corrector:install
|
66
|
+
|
67
|
+
=== in a Rails mountable engine
|
68
|
+
|
69
|
+
$ rake app:corrector:install
|
70
|
+
|
71
|
+
== Contributing
|
72
|
+
|
73
|
+
1. Fork it ( https://github.com/nepalez/corrector/fork )
|
74
|
+
2. Create your feature branch (<tt>git checkout -b my-new-feature</tt>)
|
75
|
+
3. Commit your changes (<tt>git commit -am 'Add some feature'</tt>)
|
76
|
+
4. Push to the branch (<tt>git push origin my-new-feature</tt>)
|
77
|
+
5. Create a new Pull Request
|
78
|
+
|
79
|
+
== License
|
80
|
+
|
81
|
+
The plugin is distributed under {MIT license}[https://github.com/nepalez/corrector/blob/master/LICENSE.rdoc]
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require "rdoc/task"
|
9
|
+
rescue LoadError
|
10
|
+
require "rdoc/rdoc"
|
11
|
+
require "rake/rdoctask"
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = "rdoc"
|
17
|
+
rdoc.title = "Corrector"
|
18
|
+
rdoc.options << "--line-numbers"
|
19
|
+
rdoc.rdoc_files.include "README.rdoc"
|
20
|
+
rdoc.rdoc_files.include "lib/**/*.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
25
|
+
APP_RAKEFILE = File.expand_path "../spec/dummy/Rakefile", __FILE__
|
26
|
+
load "rails/tasks/engine.rake"
|
27
|
+
|
28
|
+
require "bundler/gem_tasks"
|
29
|
+
require "rspec/core/rake_task"
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new :spec
|
32
|
+
task :default do
|
33
|
+
sh "bundle exec rake db:migrate RAILS_ENV=test"
|
34
|
+
sh "bundle exec rspec spec"
|
35
|
+
end
|
36
|
+
|
37
|
+
task :full do
|
38
|
+
sh "coveralls report"
|
39
|
+
sh "rubocop"
|
40
|
+
sh "metric_fu"
|
41
|
+
sh "rails_best_practices"
|
42
|
+
sh "inch --pedantic"
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Corrector
|
4
|
+
|
5
|
+
# Stores a list of translations (words or phrases).
|
6
|
+
class Base < ActiveRecord::Base
|
7
|
+
|
8
|
+
validates :from, :to, :scope, presence: true
|
9
|
+
validates :from, uniqueness: { scope: :scope }, allow_nil: true
|
10
|
+
|
11
|
+
# Selects records in a requested scope.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Base.by_scope "UNITS" # Returns all units translations
|
15
|
+
#
|
16
|
+
# Params:
|
17
|
+
# +value+:: the scope to select records in
|
18
|
+
#
|
19
|
+
# Returns an <tt>ActiveRecord::Association</tt> object.
|
20
|
+
scope :by_scope, ->(value) { where scope: value }
|
21
|
+
|
22
|
+
# Scans the dictionary for source string translation.
|
23
|
+
# Returns the source if no translation found.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Base.scan "КИЛОМЕТР" # => "КМ"
|
27
|
+
#
|
28
|
+
# Params:
|
29
|
+
# +value+:: a string to be scanned
|
30
|
+
#
|
31
|
+
# Returns a translation or the source itself if no translation found.
|
32
|
+
def self.scan(value)
|
33
|
+
where(from: value).first.try(:to) || value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative "base"
|
3
|
+
|
4
|
+
module Corrector
|
5
|
+
|
6
|
+
# Stores words translations.
|
7
|
+
class Prefix < Base
|
8
|
+
validates :from, format: { without: /\s/ }, allow_nil: false
|
9
|
+
|
10
|
+
# Separates all prefixes in a scanned string.
|
11
|
+
#
|
12
|
+
# @example:
|
13
|
+
# Prefix.scan "КИЛОМЕТР" # => ["КИЛО", "^", "МЕТР"]
|
14
|
+
#
|
15
|
+
# Params:
|
16
|
+
# +value+: a word to be scanned for prefixes and splitted
|
17
|
+
#
|
18
|
+
# Returns an array of recognized word's parts.
|
19
|
+
def self.scan(value)
|
20
|
+
all.reduce(value.dup) { |str, prefix| prefix.send :scan, str }.split(" ")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Separates a prefix in a scanned value.
|
26
|
+
def scan(value)
|
27
|
+
value.gsub Regexp.new("^#{ from }"), "#{ to } ^ "
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Corrector
|
4
|
+
|
5
|
+
# Converts string to uppercase and its latin letters to cyrillic ones.
|
6
|
+
class Cyrillic < String
|
7
|
+
|
8
|
+
# The source line for conversion.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# str = Cyrillic.new "mapc" # => "МАРС"
|
12
|
+
# str.source # => "mapc"
|
13
|
+
#
|
14
|
+
attr_reader :source
|
15
|
+
|
16
|
+
# Converts letters in the source string to uppercase cyrillic ones.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Cyrillic.new "mapka" # => "МАРКА"
|
20
|
+
#
|
21
|
+
# Params:
|
22
|
+
# +value+:: The source string to be converted.
|
23
|
+
#
|
24
|
+
# Returns a converted string.
|
25
|
+
def initialize(value)
|
26
|
+
@source = value
|
27
|
+
super line
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def line
|
33
|
+
source.to_s.mb_chars.upcase.tr("ABCDEHKMNOPTXY", "АВСДЕНКМ№ОРТХУ")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Corrector
|
4
|
+
|
5
|
+
# Converts a source to string using stored prefixes, words and phrases
|
6
|
+
class Parse < String
|
7
|
+
|
8
|
+
# Returns the source string having been parsed.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# str = Parse.new "километра в час", scope: "UNITS" # => "КМ/Ч"
|
12
|
+
# str.source # => "километра в час"
|
13
|
+
#
|
14
|
+
attr_reader :source
|
15
|
+
|
16
|
+
# Parses given string, caches and returns the result of parsing.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Parse.new "километра в час", scope: "UNITS" # => "КМ/Ч"
|
20
|
+
#
|
21
|
+
# Params:
|
22
|
+
# +value+:: a string to be parsed
|
23
|
+
# +scope+:: a scope (dictionary) for translations
|
24
|
+
#
|
25
|
+
# Returns a converted string with a +source+ method containing the source
|
26
|
+
# string and +scope+ containing the scope for translation.
|
27
|
+
def initialize(value = "", scope:)
|
28
|
+
@source, @scope = value.to_s, scope
|
29
|
+
super phrase
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :scope
|
35
|
+
|
36
|
+
def cyrillic
|
37
|
+
@cyrillic ||= Cyrillic.new source
|
38
|
+
end
|
39
|
+
|
40
|
+
def words
|
41
|
+
@words ||= Words.new(cyrillic)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parts
|
45
|
+
@parts ||= words.map do |word|
|
46
|
+
Prefix.by_scope(scope).scan(word) || word
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def line
|
51
|
+
@line ||= parts.map do |part|
|
52
|
+
Word.by_scope(scope).scan(part) || part
|
53
|
+
end.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def cache_key
|
57
|
+
@cache ||= [scope, cyrillic]
|
58
|
+
end
|
59
|
+
|
60
|
+
def phrase
|
61
|
+
Rails.cache.fetch cache_key do
|
62
|
+
Phrase.by_scope(scope).scan(line) || line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Corrector
|
4
|
+
|
5
|
+
# Breaks source string to words.
|
6
|
+
class Words < Array
|
7
|
+
|
8
|
+
# The source array or string for the current words list.
|
9
|
+
#
|
10
|
+
# @example:
|
11
|
+
# words = Words.new "М В С2" # => #< Words ["М", "В", "С", "2"]>
|
12
|
+
# words.source # => "М В С2"
|
13
|
+
#
|
14
|
+
# words = Wrods.new ["М", "В", "С2"] # => #< Words ["М", "В", "С2"]>
|
15
|
+
# words.source # => ["М", "В", "С2"]
|
16
|
+
#
|
17
|
+
# Returns either array or string.
|
18
|
+
attr_reader :source
|
19
|
+
|
20
|
+
# Initializes the array containing words from the source array or string.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# Words.new # => #<Words []>
|
24
|
+
# Words.new "М В С2" # => #<Words ["М", "В", "С", "2"]>
|
25
|
+
# Words.new ["М", "В", "С2"] # => #<Words ["М", "В", "С2"]>
|
26
|
+
#
|
27
|
+
# Params:
|
28
|
+
# +value+:: An array of words or a string to be splitted to words.
|
29
|
+
# Default value: <tt>[]</tt>.
|
30
|
+
#
|
31
|
+
# Returns the array of recognized words from the initial string.
|
32
|
+
# Both the +map+ and +to_s+ methods of the array are redefined.
|
33
|
+
def initialize(value = [])
|
34
|
+
@source = value
|
35
|
+
value.is_a?(Array) ? super(value) : super(words)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Maps +Words+ class object.
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# words = Words.new(%w(РАЗ ДВА)).map { |i| i }
|
42
|
+
# words.is_a? Words # => true
|
43
|
+
#
|
44
|
+
# Returns the mapped +Words+ object.
|
45
|
+
def map
|
46
|
+
Words.new super.flatten
|
47
|
+
end
|
48
|
+
|
49
|
+
# Converts words list to a string. Joins words divided by the +^+ symbol
|
50
|
+
# and removes spaces around the slash.
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# words = Words.new %w(К ^ М / C ^ 2)
|
54
|
+
# words.to_s # => "КМ/С2"
|
55
|
+
#
|
56
|
+
# Returns a converted string with +source+ method to check the source.
|
57
|
+
def to_s
|
58
|
+
map(&:strip).join(" ").gsub(/\s*\^\s*/, "").gsub(/\s*\/\s*/, "/")
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def line
|
64
|
+
@line ||= source.to_s.gsub(/\,/, ".").gsub(/\|/, "/")
|
65
|
+
end
|
66
|
+
|
67
|
+
def words
|
68
|
+
line.scan(/[А-ЯA-Z]+|\d+\.\d+|\d+|№|\/|%|\$|\^/)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateCorrectorBases < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :corrector_bases do |t|
|
4
|
+
t.string :type, limit: 6
|
5
|
+
t.string :from, null: false
|
6
|
+
t.string :to, null: false
|
7
|
+
t.string :scope
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :corrector_bases, [:scope, :from], unique: true
|
11
|
+
add_index :corrector_bases, :type
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Corrector
|
2
|
+
|
3
|
+
# Rails Engine settings
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace Corrector
|
6
|
+
|
7
|
+
config.generators do |generator|
|
8
|
+
generator.test_framework :rspec, fixture: true, view_specs: true
|
9
|
+
generator.fixture_replacement :factory_girl, dir: "spec/factories"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/corrector.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
data/spec/dummy/bin/rake
ADDED