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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/README.rdoc +6 -7
  4. data/Rakefile +4 -13
  5. data/app/controllers/okei/api/v1/responder.rb +15 -2
  6. data/app/controllers/okei/api/v1/units_controller.rb +4 -0
  7. data/app/models/okei/unit.rb +32 -5
  8. data/app/use_cases/okei/find_unit.rb +2 -12
  9. data/app/use_cases/okei/get_unit.rb +1 -1
  10. data/app/views/okei/api/v1/units/_unit.json.jbuilder +2 -4
  11. data/db/migrate/{20141004212500_create_okei_units.rb → 20141019072900_create_okei_units.rb} +0 -2
  12. data/db/migrate/20141019072901_populate_okei_units.rb +60 -0
  13. data/db/migrate/20141019072902_populate_okei_correctors.rb +50 -0
  14. data/db/seeds/phrases.json +199 -0
  15. data/db/seeds/prefixes.json +12 -0
  16. data/db/seeds/words.json +10 -216
  17. data/lib/okei.rb +2 -0
  18. data/lib/okei/version.rb +4 -2
  19. data/lib/tasks/okei_tasks.rake +47 -28
  20. data/spec/dummy/db/migrate/20141018085223_create_corrector_bases.corrector.rb +14 -0
  21. data/spec/dummy/db/migrate/20141018085226_create_uuids_uuids.uuids.rb +10 -0
  22. data/spec/dummy/db/schema.rb +22 -12
  23. data/spec/dummy/db/test.sqlite3 +0 -0
  24. data/spec/dummy/log/development.log +20296 -0
  25. data/spec/dummy/log/test.log +183148 -0
  26. data/spec/examples/json_schemas/unit.json +7 -2
  27. data/spec/factories/units.rb +0 -1
  28. data/spec/models/okei/unit_spec.rb +7 -26
  29. data/spec/requests/okei/api/v1/find_unit_spec.rb +8 -11
  30. data/spec/requests/okei/api/v1/get_unit_spec.rb +2 -3
  31. data/spec/requests/okei/api/v1/get_units_spec.rb +2 -2
  32. data/spec/support/initializers/factory_girl_rails.rb +4 -0
  33. data/spec/use_cases/okei/find_unit_spec.rb +7 -10
  34. metadata +43 -21
  35. data/app/models/okei/line.rb +0 -63
  36. data/app/models/okei/word.rb +0 -26
  37. data/app/models/okei/words.rb +0 -40
  38. data/db/migrate/20141004212501_populate_okei_units.rb +0 -14
  39. data/db/migrate/20141004212502_create_okei_words.rb +0 -11
  40. data/db/migrate/20141004212503_populate_okei_words.rb +0 -15
  41. data/spec/factories/words.rb +0 -7
  42. data/spec/models/okei/line_spec.rb +0 -61
  43. data/spec/models/okei/word_spec.rb +0 -75
  44. data/spec/models/okei/words_spec.rb +0 -64
  45. data/spec/support/initializers/factory_girl.rb +0 -6
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Okei
4
-
5
- # Breaks the source string to words properly:
6
- #
7
- # Words.new "М3 96% ЧИСТОГО СПИРТА /ЧЕЛ"
8
- # # => ["М", "^", "3", "96", "%", "ЧИСТОГО", "СПИРТА", "/", "ЧЕЛ"]
9
- #
10
- class Words < Array
11
-
12
- def initialize(line = "")
13
- @line = line.to_s
14
- super @line.scan(/[А-Я]+|\d+.\d+|\d+|\/|\^|\%/)
15
- end
16
-
17
- # Maps words back to `Words` (not a base `Array`):
18
- #
19
- # ["9.8", "М", "/", "С", "^", "2"].map { |i| i }.class
20
- # # => Words
21
- #
22
- # The method can be combined with `to_s`:
23
- #
24
- # ["9.8", "М", "/", "С", "^", "2"].map { |i| i.lower }.to_s
25
- # # => "9.8 м/с2"
26
- #
27
- def map
28
- Words.new super
29
- end
30
-
31
- # Joins words back to string when necessary:
32
- #
33
- # ["М", "^", "3", "96", "ПРОЦ", "ЧИСТОГО", "СПИРТА", "/", "ЧЕЛ"].to_s
34
- # # => "М3 96 ПРОЦ ЧИСТОГО СПИРТА/ЧЕЛ"
35
- #
36
- def to_s
37
- join(" ").gsub(" ^ ", "").gsub(" / ", "/")
38
- end
39
- end
40
- end
@@ -1,14 +0,0 @@
1
- # Populates db with units of measure.
2
- class PopulateOkeiUnits < ActiveRecord::Migration
3
-
4
- def up
5
- root = File.dirname File.dirname(Okei::Engine.called_from)
6
- seed = File.join(root, "db", "seeds", "units.json")
7
- Okei::Unit.delete_all
8
- JSON.parse(File.read seed).each { |item| Okei::Unit.create! item }
9
- end
10
-
11
- def down
12
- Okei::Unit.delete_all
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- # Creates db table for a dictionary of words used in unit names.
2
- class CreateOkeiWords < ActiveRecord::Migration
3
- def change
4
- create_table :okei_words do |t|
5
- t.string :synonym
6
- t.string :text
7
- end
8
-
9
- add_index :okei_words, :synonym, unique: true
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # Populates db with dictionary of words and phrases used in unit names.
2
- class PopulateOkeiWords < ActiveRecord::Migration
3
-
4
- def up
5
- root = File.dirname File.dirname(Okei::Engine.called_from)
6
- seed = File.join(root, "db", "seeds", "words.json")
7
- JSON.parse(File.read seed).each do |synonym, text|
8
- Okei::Word.create synonym: synonym, text: text
9
- end
10
- end
11
-
12
- def down
13
- Okei::Word.delete_all
14
- end
15
- end
@@ -1,7 +0,0 @@
1
- # encoding: utf-8
2
- FactoryGirl.define do
3
- factory :word, class: Okei::Word do
4
- sequence(:synonym) { |n| "ЕДИНИЦА#{ n }" }
5
- sequence(:text) { |n| "ЕД#{ n }" }
6
- end
7
- end
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
-
4
- module Okei
5
- describe Line do
6
-
7
- describe ".new" do
8
-
9
- # ========================================================================
10
- # Matchers
11
- # ========================================================================
12
-
13
- RSpec::Matchers.define :turn_to do |line|
14
- match do |str|
15
- expect(Line.new str).to eq line
16
- end
17
- failure_message do |str|
18
- "#{ str } should turn to #{ line }. #{ Line.new str } given."
19
- end
20
- end
21
-
22
- # ========================================================================
23
- # Tests
24
- # ========================================================================
25
-
26
- it "returns a string" do
27
- expect(Line.new).to be_kind_of String
28
- end
29
-
30
- specify { expect("усл метр/сек^2").to turn_to "УСЛ МЕТР/СЕК ^ 2" }
31
- specify { expect("100 М").to turn_to "100 М" }
32
- specify { expect("0,1КМ").to turn_to "0.1КМ" }
33
- specify { expect("М.1").to turn_to "М 1" }
34
- specify { expect("М2").to turn_to "М ^ 2" }
35
- specify { expect("М 2").to turn_to "М ^ 2" }
36
- specify { expect("М.2").to turn_to "М ^ 2" }
37
- specify { expect("М. 2").to turn_to "М ^ 2" }
38
- specify { expect("М^2").to turn_to "М ^ 2" }
39
- specify { expect("М3").to turn_to "М ^ 3" }
40
- specify { expect("М 3").to turn_to "М ^ 3" }
41
- specify { expect("М.3").to turn_to "М ^ 3" }
42
- specify { expect("М. 3").to turn_to "М ^ 3" }
43
- specify { expect("М^3").to turn_to "М ^ 3" }
44
- specify { expect("М.4").to turn_to "М 4" }
45
- specify { expect("ТЫС. Ч").to turn_to "ТЫС Ч" }
46
- specify { expect("ТЫС. Ч.").to turn_to "ТЫС Ч" }
47
- specify { expect(".ТЫС .Ч").to turn_to "ТЫС Ч" }
48
- specify { expect("в 20-фут.экв.").to turn_to "В 20 ФУТ ЭКВ" }
49
- specify { expect("METP B ЧAC").to turn_to "МЕТР В ЧАС" }
50
- specify { expect("ГЕКТОЛИТР").to turn_to "ГЕКТО ^ ЛИТР" }
51
- specify { expect("КИЛОЛИТР").to turn_to "КИЛО ^ ЛИТР" }
52
- specify { expect("МИЛЛИЛИТР").to turn_to "МИЛЛИ ^ ЛИТР" }
53
- specify { expect("МЕГАЛИТР").to turn_to "МЕГА ^ ЛИТР" }
54
- specify { expect("САНТИЛИТР").to turn_to "САНТИ ^ ЛИТР" }
55
- specify { expect("МИКРОЛИТР").to turn_to "МИКРО ^ ЛИТР" }
56
- specify { expect("ТЕРАЛИТР").to turn_to "ТЕРА ^ ЛИТР" }
57
- specify { expect("НАНОЛИТР").to turn_to "НАНО ^ ЛИТР" }
58
- specify { expect("40%-НОГО СПИРТА").to turn_to "40% СПИРТА" }
59
- end
60
- end
61
- end
@@ -1,75 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
-
4
- module Okei
5
- describe Word do
6
-
7
- describe "#synonym=" do
8
-
9
- subject(:word) { Word.new }
10
-
11
- it "sets #synonym" do
12
- value = "МЕТР"
13
- expect { word.synonym = value }.to change { word.synonym }.to value
14
- end
15
- end
16
-
17
- describe "#text=" do
18
-
19
- subject(:word) { Word.new }
20
-
21
- it "sets #text" do
22
- value = "М"
23
- expect { word.text = value }.to change { word.text }.to value
24
- end
25
- end
26
-
27
- describe "#valid?" do
28
-
29
- subject(:word) { build :word }
30
-
31
- before { expect(word).to be_valid }
32
-
33
- it "fails when #synonym is absent" do
34
- word.synonym = ""
35
- expect(word).not_to be_valid
36
- end
37
-
38
- it "fails when #synonym is taken" do
39
- create :word, synonym: word.synonym
40
- expect(word).not_to be_valid
41
- end
42
-
43
- it "fails when #text is absent" do
44
- word.text = ""
45
- expect(word).not_to be_valid
46
- end
47
-
48
- it "passes when #text is taken" do
49
- create :word, text: word.text
50
- expect(word).to be_valid
51
- end
52
- end
53
-
54
- describe ".translate" do
55
-
56
- let!(:line) { "ТЕКСТ" }
57
-
58
- context "when word exists" do
59
-
60
- let!(:word) { create :word, synonym: line }
61
-
62
- it "translates line" do
63
- expect(Word.translate line).to eq word.text
64
- end
65
- end
66
-
67
- context "when word is absent" do
68
-
69
- it "returns the source" do
70
- expect(Word.translate line).to eq line
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
-
4
- module Okei
5
- describe Words do
6
-
7
- describe ".new" do
8
-
9
- RSpec::Matchers.define :have_words do |list|
10
- match do |text|
11
- expect(Words.new text).to eq list
12
- end
13
- failure_message do |text|
14
- "#{ text } should have words #{ list }." \
15
- " #{ Words.new text } given."
16
- end
17
- end
18
-
19
- it "returns list of words" do
20
- expect(Words.new).to be_kind_of Array
21
- end
22
-
23
- specify { expect("УСЛ МЕТР/СЕК^2").to have_words %w(УСЛ МЕТР / СЕК ^ 2) }
24
- specify { expect("100 М").to have_words %w(100 М) }
25
- specify { expect("2ШТ").to have_words %w(2 ШТ) }
26
- specify { expect("1000КМ").to have_words %w(1000 КМ) }
27
- specify { expect("0.1КМ").to have_words %w(0.1 КМ) }
28
- specify { expect("М1").to have_words %w(М 1) }
29
- specify { expect("М.1").to have_words %w(М 1) }
30
- specify { expect("М4").to have_words %w(М 4) }
31
- specify { expect("М.4").to have_words %w(М 4) }
32
- specify { expect("ТЫС. Ч").to have_words %w(ТЫС Ч) }
33
- specify { expect("ТЫС. Ч.").to have_words %w(ТЫС Ч) }
34
- specify { expect(".ТЫС .Ч").to have_words %w(ТЫС Ч) }
35
- specify { expect("90%").to have_words %w(90 %) }
36
- end
37
-
38
- describe "#map" do
39
-
40
- subject(:words) { Words.new("M") }
41
-
42
- it "should return a Words object" do
43
- expect(subject.map { |word| word }).to be_kind_of Words
44
- end
45
- end
46
-
47
- describe "#to_s" do
48
-
49
- RSpec::Matchers.define :shape_into do |text|
50
- match do |words|
51
- expect(Words.new(words).to_s).to eq text
52
- end
53
- failure_message do |words|
54
- "'#{ words }' should shape into '#{ text }'." \
55
- " '#{ Words.new(words) }' given."
56
- end
57
- end
58
-
59
- specify { expect("К ^ М ^ 2").to shape_into "КМ2" }
60
- specify { expect("КМ / С").to shape_into "КМ/С" }
61
- specify { expect("КИЛОМ").to shape_into "КИЛОМ" }
62
- end
63
- end
64
- end
@@ -1,6 +0,0 @@
1
- # Add factory girl syntax
2
- require "factory_girl"
3
-
4
- RSpec.configure do |config|
5
- config.include FactoryGirl::Syntax::Methods
6
- end