okei 0.0.2 → 1.0.0.pre.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.rdoc +6 -7
- data/Rakefile +4 -13
- data/app/controllers/okei/api/v1/responder.rb +15 -2
- data/app/controllers/okei/api/v1/units_controller.rb +4 -0
- data/app/models/okei/unit.rb +32 -5
- data/app/use_cases/okei/find_unit.rb +2 -12
- data/app/use_cases/okei/get_unit.rb +1 -1
- data/app/views/okei/api/v1/units/_unit.json.jbuilder +2 -4
- data/db/migrate/{20141004212500_create_okei_units.rb → 20141019072900_create_okei_units.rb} +0 -2
- data/db/migrate/20141019072901_populate_okei_units.rb +60 -0
- data/db/migrate/20141019072902_populate_okei_correctors.rb +50 -0
- data/db/seeds/phrases.json +199 -0
- data/db/seeds/prefixes.json +12 -0
- data/db/seeds/words.json +10 -216
- data/lib/okei.rb +2 -0
- data/lib/okei/version.rb +4 -2
- data/lib/tasks/okei_tasks.rake +47 -28
- data/spec/dummy/db/migrate/20141018085223_create_corrector_bases.corrector.rb +14 -0
- data/spec/dummy/db/migrate/20141018085226_create_uuids_uuids.uuids.rb +10 -0
- data/spec/dummy/db/schema.rb +22 -12
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +20296 -0
- data/spec/dummy/log/test.log +183148 -0
- data/spec/examples/json_schemas/unit.json +7 -2
- data/spec/factories/units.rb +0 -1
- data/spec/models/okei/unit_spec.rb +7 -26
- data/spec/requests/okei/api/v1/find_unit_spec.rb +8 -11
- data/spec/requests/okei/api/v1/get_unit_spec.rb +2 -3
- data/spec/requests/okei/api/v1/get_units_spec.rb +2 -2
- data/spec/support/initializers/factory_girl_rails.rb +4 -0
- data/spec/use_cases/okei/find_unit_spec.rb +7 -10
- metadata +43 -21
- data/app/models/okei/line.rb +0 -63
- data/app/models/okei/word.rb +0 -26
- data/app/models/okei/words.rb +0 -40
- data/db/migrate/20141004212501_populate_okei_units.rb +0 -14
- data/db/migrate/20141004212502_create_okei_words.rb +0 -11
- data/db/migrate/20141004212503_populate_okei_words.rb +0 -15
- data/spec/factories/words.rb +0 -7
- data/spec/models/okei/line_spec.rb +0 -61
- data/spec/models/okei/word_spec.rb +0 -75
- data/spec/models/okei/words_spec.rb +0 -64
- data/spec/support/initializers/factory_girl.rb +0 -6
@@ -5,7 +5,12 @@
|
|
5
5
|
"type": "object",
|
6
6
|
|
7
7
|
"properties": {
|
8
|
-
"
|
8
|
+
"uuids": {
|
9
|
+
"type": "array",
|
10
|
+
"items": { "type": "string", "format": "^(a-f|\\d|-){36}$" },
|
11
|
+
"minimumItems": 1,
|
12
|
+
"unique": true
|
13
|
+
},
|
9
14
|
"name": { "type": "string", "minLength": 1 },
|
10
15
|
"code": { "type": "string", "minLength": 1 },
|
11
16
|
"num": { "type": "string", "format": "^(\\d){3}$" },
|
@@ -16,5 +21,5 @@
|
|
16
21
|
},
|
17
22
|
|
18
23
|
"additionalProperties": false,
|
19
|
-
"required": ["
|
24
|
+
"required": ["uuids", "name", "code", "base", "factor", "measure"]
|
20
25
|
}
|
data/spec/factories/units.rb
CHANGED
@@ -6,11 +6,14 @@ module Okei
|
|
6
6
|
|
7
7
|
let!(:unit) { Unit.new }
|
8
8
|
|
9
|
-
describe "#
|
9
|
+
describe "#uuids" do
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
let!(:value) { "48f53a7c-726f-4ec1-9b83-a12b247844a6" }
|
12
|
+
|
13
|
+
it "has a list of uuids" do
|
14
|
+
expect(unit).to respond_to :uuids
|
15
|
+
expect(unit).to respond_to :uuid
|
16
|
+
expect(Unit).to respond_to :by_uuid
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
@@ -75,28 +78,6 @@ module Okei
|
|
75
78
|
let!(:unit) { build :unit }
|
76
79
|
before { expect(unit).to be_valid }
|
77
80
|
|
78
|
-
it "fails when a uuid is absent" do
|
79
|
-
unit.uuid = nil
|
80
|
-
expect(unit).not_to be_valid
|
81
|
-
end
|
82
|
-
|
83
|
-
it "fails when uuid has a wrong format" do
|
84
|
-
%w(
|
85
|
-
48f53a7c-726f-4ec1-9b83-a12b2478446
|
86
|
-
48f53a7c-726f-4ec1-9b83-a12b2478446g
|
87
|
-
48f53a7c-726f-4ec19-b83-a12b2478446g
|
88
|
-
48f53a7c-726f-4ec1-9b83-a12b2478446ee
|
89
|
-
).each do |value|
|
90
|
-
unit.uuid = value
|
91
|
-
expect(unit).not_to be_valid
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "fails when a uuid is already taken" do
|
96
|
-
create :unit, uuid: unit.uuid
|
97
|
-
expect(unit).not_to be_valid
|
98
|
-
end
|
99
|
-
|
100
81
|
it "fails when a name is absent" do
|
101
82
|
unit.name = nil
|
102
83
|
expect(unit).not_to be_valid
|
@@ -8,14 +8,12 @@ module Okei
|
|
8
8
|
# Prepare context
|
9
9
|
# ==========================================================================
|
10
10
|
|
11
|
-
let!(:unit) { create :unit, code: "ТЫС
|
11
|
+
let!(:unit) { create :unit, code: "ТЫС М/С2" }
|
12
|
+
let!(:text) { "километров в сек" }
|
12
13
|
before do
|
13
|
-
|
14
|
-
"
|
15
|
-
|
16
|
-
"ЧАСОВ" => "ЧАС",
|
17
|
-
"ТЫС ЧЕЛ ЧАС" => "ТЫС ЧЕЛ-ЧАС"
|
18
|
-
}.each { |synonym, text| create :word, synonym: synonym, text: text }
|
14
|
+
allow(Corrector::Parse).to receive(:new) do |str, scope:|
|
15
|
+
(str == text) && (scope == "okei") ? unit.code : str
|
16
|
+
end
|
19
17
|
end
|
20
18
|
|
21
19
|
# ==========================================================================
|
@@ -32,7 +30,7 @@ module Okei
|
|
32
30
|
|
33
31
|
context "with proper text" do
|
34
32
|
|
35
|
-
before { call_request
|
33
|
+
before { call_request text }
|
36
34
|
|
37
35
|
it "responds with 200" do
|
38
36
|
expect(response.status).to eq 200
|
@@ -44,14 +42,13 @@ module Okei
|
|
44
42
|
|
45
43
|
it "responds with requested unit" do
|
46
44
|
received = JSON.parse(response.body)["unit"]
|
47
|
-
|
48
|
-
.each { |key| expect(received[key]).to eq unit.send(key) }
|
45
|
+
expect(received["uuids"]).to be_include unit.uuid
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
49
|
context "with wrong text" do
|
53
50
|
|
54
|
-
before { call_request "wrong" }
|
51
|
+
before { call_request "wrong text" }
|
55
52
|
|
56
53
|
it "responds with 404" do
|
57
54
|
expect(response.status).to eq 404
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
module Okei
|
5
|
-
describe "Getting unit"
|
5
|
+
describe "Getting unit"do
|
6
6
|
|
7
7
|
# ==========================================================================
|
8
8
|
# Prepare environment
|
@@ -36,8 +36,7 @@ module Okei
|
|
36
36
|
|
37
37
|
it "responds with requested unit" do
|
38
38
|
received = JSON.parse(response.body)["unit"]
|
39
|
-
|
40
|
-
.each { |key| expect(received[key]).to eq unit.send(key) }
|
39
|
+
expect(received["uuids"]).to be_include unit.uuid
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -20,7 +20,7 @@ module Okei
|
|
20
20
|
end
|
21
21
|
|
22
22
|
let(:uuids) do
|
23
|
-
JSON.parse(response.body)["units"].map { |unit| unit["
|
23
|
+
JSON.parse(response.body)["units"].map { |unit| unit["uuids"] }.flatten
|
24
24
|
end
|
25
25
|
|
26
26
|
# ==========================================================================
|
@@ -39,7 +39,7 @@ module Okei
|
|
39
39
|
expect(response.body).to match_json_schema(:get_units)
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "receives all units" do
|
43
43
|
expect(uuids).to eq [nmile.uuid, mole.uuid]
|
44
44
|
end
|
45
45
|
end
|
@@ -8,14 +8,12 @@ module Okei
|
|
8
8
|
# Prepare context
|
9
9
|
# ==========================================================================
|
10
10
|
|
11
|
-
let!(:unit) { create :unit, code: "ТЫС
|
11
|
+
let!(:unit) { create :unit, code: "ТЫС М/С2" }
|
12
|
+
let!(:text) { "километров в сек" }
|
12
13
|
before do
|
13
|
-
|
14
|
-
"
|
15
|
-
|
16
|
-
"ЧАСОВ" => "ЧАС",
|
17
|
-
"ТЫС ЧЕЛ ЧАС" => "ТЫС ЧЕЛ-ЧАС"
|
18
|
-
}.each { |synonym, text| create :word, synonym: synonym, text: text }
|
14
|
+
allow(Corrector::Parse).to receive(:new) do |str, scope:|
|
15
|
+
(str == text) && (scope == "okei") ? unit.code : str
|
16
|
+
end
|
19
17
|
end
|
20
18
|
|
21
19
|
# ==========================================================================
|
@@ -38,7 +36,6 @@ module Okei
|
|
38
36
|
|
39
37
|
context "with proper text" do
|
40
38
|
|
41
|
-
let!(:text) { "1000 человеко-часов" }
|
42
39
|
subject(:use_case) { prepare_case text }
|
43
40
|
|
44
41
|
it "returns the unit" do
|
@@ -52,14 +49,14 @@ module Okei
|
|
52
49
|
|
53
50
|
it "caches results of code preparing", :caching do
|
54
51
|
use_case.run
|
55
|
-
expect(
|
52
|
+
expect(Corrector::Phrase).not_to receive(:scope)
|
56
53
|
prepare_case(text).run
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
57
|
context "with wrong text" do
|
61
58
|
|
62
|
-
subject(:use_case) { prepare_case "тысяч
|
59
|
+
subject(:use_case) { prepare_case "тысяч км в сек" }
|
63
60
|
|
64
61
|
it "returns nil" do
|
65
62
|
expect(use_case.run).to be_nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: okei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 1.0.0.pre.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hexx
|
@@ -58,6 +58,34 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '4.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: corrector
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: uuids
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.0.0.pre.rc1
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.0.0.pre.rc1
|
61
89
|
- !ruby/object:Gem::Dependency
|
62
90
|
name: database_cleaner
|
63
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,10 +229,7 @@ files:
|
|
201
229
|
- Rakefile
|
202
230
|
- app/controllers/okei/api/v1/responder.rb
|
203
231
|
- app/controllers/okei/api/v1/units_controller.rb
|
204
|
-
- app/models/okei/line.rb
|
205
232
|
- app/models/okei/unit.rb
|
206
|
-
- app/models/okei/word.rb
|
207
|
-
- app/models/okei/words.rb
|
208
233
|
- app/use_cases/okei/find_unit.rb
|
209
234
|
- app/use_cases/okei/get_unit.rb
|
210
235
|
- app/use_cases/okei/get_units.rb
|
@@ -214,10 +239,11 @@ files:
|
|
214
239
|
- app/views/okei/api/v1/units/show.json.jbuilder
|
215
240
|
- config/locales/ru.yml
|
216
241
|
- config/routes.rb
|
217
|
-
- db/migrate/
|
218
|
-
- db/migrate/
|
219
|
-
- db/migrate/
|
220
|
-
- db/
|
242
|
+
- db/migrate/20141019072900_create_okei_units.rb
|
243
|
+
- db/migrate/20141019072901_populate_okei_units.rb
|
244
|
+
- db/migrate/20141019072902_populate_okei_correctors.rb
|
245
|
+
- db/seeds/phrases.json
|
246
|
+
- db/seeds/prefixes.json
|
221
247
|
- db/seeds/units.json
|
222
248
|
- db/seeds/words.json
|
223
249
|
- lib/okei.rb
|
@@ -255,8 +281,11 @@ files:
|
|
255
281
|
- spec/dummy/config/locales/en.yml
|
256
282
|
- spec/dummy/config/routes.rb
|
257
283
|
- spec/dummy/config/secrets.yml
|
284
|
+
- spec/dummy/db/migrate/20141018085223_create_corrector_bases.corrector.rb
|
285
|
+
- spec/dummy/db/migrate/20141018085226_create_uuids_uuids.uuids.rb
|
258
286
|
- spec/dummy/db/schema.rb
|
259
287
|
- spec/dummy/db/test.sqlite3
|
288
|
+
- spec/dummy/log/development.log
|
260
289
|
- spec/dummy/log/test.log
|
261
290
|
- spec/dummy/public/404.html
|
262
291
|
- spec/dummy/public/422.html
|
@@ -268,11 +297,7 @@ files:
|
|
268
297
|
- spec/examples/json_schemas/get_units.json
|
269
298
|
- spec/examples/json_schemas/unit.json
|
270
299
|
- spec/factories/units.rb
|
271
|
-
- spec/factories/words.rb
|
272
|
-
- spec/models/okei/line_spec.rb
|
273
300
|
- spec/models/okei/unit_spec.rb
|
274
|
-
- spec/models/okei/word_spec.rb
|
275
|
-
- spec/models/okei/words_spec.rb
|
276
301
|
- spec/requests/okei/api/v1/find_unit_spec.rb
|
277
302
|
- spec/requests/okei/api/v1/get_unit_spec.rb
|
278
303
|
- spec/requests/okei/api/v1/get_units_spec.rb
|
@@ -281,7 +306,6 @@ files:
|
|
281
306
|
- spec/support/initializers/caching.rb
|
282
307
|
- spec/support/initializers/coveralls.rb
|
283
308
|
- spec/support/initializers/database_cleaner.rb
|
284
|
-
- spec/support/initializers/factory_girl.rb
|
285
309
|
- spec/support/initializers/factory_girl_rails.rb
|
286
310
|
- spec/support/initializers/focus.rb
|
287
311
|
- spec/support/initializers/garbage_collection.rb
|
@@ -312,9 +336,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
312
336
|
version: '2.1'
|
313
337
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
314
338
|
requirements:
|
315
|
-
- - "
|
339
|
+
- - ">"
|
316
340
|
- !ruby/object:Gem::Version
|
317
|
-
version:
|
341
|
+
version: 1.3.1
|
318
342
|
requirements: []
|
319
343
|
rubyforge_project:
|
320
344
|
rubygems_version: 2.2.2
|
@@ -326,9 +350,6 @@ test_files:
|
|
326
350
|
- spec/routing/okei/api/v1/units_routing_spec.rb
|
327
351
|
- spec/spec_helper.rb
|
328
352
|
- spec/models/okei/unit_spec.rb
|
329
|
-
- spec/models/okei/words_spec.rb
|
330
|
-
- spec/models/okei/word_spec.rb
|
331
|
-
- spec/models/okei/line_spec.rb
|
332
353
|
- spec/dummy/public/500.html
|
333
354
|
- spec/dummy/public/422.html
|
334
355
|
- spec/dummy/public/404.html
|
@@ -351,6 +372,8 @@ test_files:
|
|
351
372
|
- spec/dummy/config/initializers/cookies_serializer.rb
|
352
373
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
353
374
|
- spec/dummy/config/initializers/assets.rb
|
375
|
+
- spec/dummy/db/migrate/20141018085223_create_corrector_bases.corrector.rb
|
376
|
+
- spec/dummy/db/migrate/20141018085226_create_uuids_uuids.uuids.rb
|
354
377
|
- spec/dummy/db/test.sqlite3
|
355
378
|
- spec/dummy/db/schema.rb
|
356
379
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -360,12 +383,12 @@ test_files:
|
|
360
383
|
- spec/dummy/app/controllers/application_controller.rb
|
361
384
|
- spec/dummy/Rakefile
|
362
385
|
- spec/dummy/README.rdoc
|
386
|
+
- spec/dummy/log/development.log
|
363
387
|
- spec/dummy/log/test.log
|
364
388
|
- spec/dummy/config.ru
|
365
389
|
- spec/dummy/bin/rake
|
366
390
|
- spec/dummy/bin/rails
|
367
391
|
- spec/dummy/bin/bundle
|
368
|
-
- spec/factories/words.rb
|
369
392
|
- spec/factories/units.rb
|
370
393
|
- spec/controllers/okei/api/v1/responder_spec.rb
|
371
394
|
- spec/controllers/okei/api/v1/units_controller_spec.rb
|
@@ -381,7 +404,6 @@ test_files:
|
|
381
404
|
- spec/support/matchers/controllers.rb
|
382
405
|
- spec/support/initializers/garbage_collection.rb
|
383
406
|
- spec/support/initializers/i18n.rb
|
384
|
-
- spec/support/initializers/factory_girl.rb
|
385
407
|
- spec/support/initializers/focus.rb
|
386
408
|
- spec/support/initializers/timecop.rb
|
387
409
|
- spec/support/initializers/factory_girl_rails.rb
|
data/app/models/okei/line.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Okei
|
4
|
-
|
5
|
-
# Converts source string to standardized line of text with:
|
6
|
-
#
|
7
|
-
# * cyrillic letters un upper register
|
8
|
-
# * numbers
|
9
|
-
# * ^ - a symbol of word break
|
10
|
-
# * slashes
|
11
|
-
# * spaces
|
12
|
-
# * %
|
13
|
-
#
|
14
|
-
# Line.new "1000шт в условн.эквивал."
|
15
|
-
# # => "1000 ШТ В УСЛОВН ЭКВИВАЛ"
|
16
|
-
#
|
17
|
-
class Line < String
|
18
|
-
|
19
|
-
def initialize(str = "")
|
20
|
-
super str.to_s.mb_chars.upcase
|
21
|
-
to_cyrillic
|
22
|
-
remove_dots_and_commas
|
23
|
-
clear_text
|
24
|
-
add_breaks
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# Converts latin letters to corresponding cyrillic
|
30
|
-
def to_cyrillic
|
31
|
-
{
|
32
|
-
"A" => "А", "B" => "В", "C" => "С", "D" => "Д", "E" => "Е",
|
33
|
-
"G" => "Д", "H" => "Н", "K" => "К", "M" => "М", "N" => "П",
|
34
|
-
"O" => "О", "P" => "Р", "Q" => "Д", "R" => "Г", "T" => "Т",
|
35
|
-
"U" => "И", "X" => "Х", "Y" => "У"
|
36
|
-
}.each { |lat, cyr| gsub! lat, cyr }
|
37
|
-
end
|
38
|
-
|
39
|
-
# Remove dots and commas except for dots between digits
|
40
|
-
def remove_dots_and_commas
|
41
|
-
gsub!(/\.+/, ",")
|
42
|
-
gsub!(/(\d),(\d)/, '\1.\2')
|
43
|
-
gsub!(/,/, " ")
|
44
|
-
end
|
45
|
-
|
46
|
-
# Removes unwanted symbols.
|
47
|
-
def clear_text
|
48
|
-
gsub!(/\%-[^\s]+/, "%")
|
49
|
-
gsub!(/[^А-Я\d\.\s\/\%]/, " ")
|
50
|
-
gsub!(/\A[^А-Я\d]+|[^А-Я\d]+\z/, " ")
|
51
|
-
gsub!(/\s{2,}/, " ")
|
52
|
-
strip!
|
53
|
-
end
|
54
|
-
|
55
|
-
# Add ^ to mark word breaks
|
56
|
-
def add_breaks
|
57
|
-
gsub!(
|
58
|
-
/\A(НАНО|МИКРО|МИЛЛИ|САНТИ|ПОЛ|ДЕКА|ДЕЦИ|ГЕКТО|КИЛО|МЕГА|ТЕРА)/, '\1 ^ '
|
59
|
-
)
|
60
|
-
gsub!(/([А-Я])[\s\.^]*(2|3)(?!\d)/, '\1 ^ \2')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/app/models/okei/word.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Okei
|
4
|
-
|
5
|
-
# Stores dictionary of words:
|
6
|
-
#
|
7
|
-
# Word.new synonym: "МЕТРЫ", text: "М"
|
8
|
-
# Word.new synonym: "МЕТР", text: "М"
|
9
|
-
#
|
10
|
-
# ...and units in their standard representation:
|
11
|
-
#
|
12
|
-
# Word.new synonym: "КВ М", text: "М2"
|
13
|
-
# Word.new synonym: "М КВ", text: "М2"
|
14
|
-
#
|
15
|
-
class Word < ActiveRecord::Base
|
16
|
-
|
17
|
-
validates :synonym, :text, presence: true
|
18
|
-
validates :synonym, uniqueness: { case_sensitive: false }, allow_nil: true
|
19
|
-
|
20
|
-
# Translates the line if a translation exists.
|
21
|
-
# Otherwise returns source line unchanged.
|
22
|
-
def self.translate(line)
|
23
|
-
find_by_synonym(line).try(:text) || line
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|