russial 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/russial.rb +3 -2
- data/lib/russial/dictionary/dynamic_methods.rb +7 -1
- data/lib/russial/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c93429bb71837afc0679f99dfb5d0245cee8f8
|
4
|
+
data.tar.gz: a335d150e45f29979e16876c8d439383d46d798a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 905f247bd220bbe2e7a51fb59c86ef321380afbcc6f6c217b889cc176acf0db4627cda4ed66d9da5fad5d08bd96f81c22b77bac23abcddefe44cf5bc256a62fe
|
7
|
+
data.tar.gz: 9031e378a278634fb6af095d4682464eae985c046b82a4584563de9c0c6aed0e45b8445ae27fed0f066ba4b10659617a6a7acd0a2fdba0850b647cc0d03e8665
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ $ gem install russial
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
The Russial gem automatically works with any structures that you pass as dictionary. You can use it with plain Ruby or I18n/Rails.
|
28
|
+
Keys must be symbols.
|
28
29
|
|
29
30
|
### Plain Ruby
|
30
31
|
|
@@ -99,6 +100,29 @@ word.reset.past.singular.male # "прошёл"
|
|
99
100
|
word.reset.past.singular.female # "прошла"
|
100
101
|
```
|
101
102
|
|
103
|
+
### Substitutions
|
104
|
+
|
105
|
+
With this feature you can use the gem more advanced way. See example:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
flat_dictionary = {
|
109
|
+
"многокомнатная квартира": {
|
110
|
+
nominative: "___комнатная квартира",
|
111
|
+
genitive: "___комнатной квартиры",
|
112
|
+
dative: "___комнатной квартире",
|
113
|
+
accusative: "___комнатную квартиру",
|
114
|
+
instrumental: "___комнатной квартирой",
|
115
|
+
prepositional: "___комнатной квартире"
|
116
|
+
}
|
117
|
+
}
|
118
|
+
substitutions = { "___" => "трёх" }
|
119
|
+
|
120
|
+
word = Russial.new("многокомнатная квартира", dictionary: flat_dictionary, substitutions: substitutions)
|
121
|
+
|
122
|
+
word.dative # "трёхкомнатной квартире"
|
123
|
+
word.instrumental # "трёхкомнатной квартирой"
|
124
|
+
```
|
125
|
+
|
102
126
|
## Settings
|
103
127
|
|
104
128
|
You can configure this gem. Add settings to initializers.
|
data/lib/russial.rb
CHANGED
@@ -16,9 +16,10 @@ class Russial
|
|
16
16
|
prepend Dictionary::Initializer
|
17
17
|
extend Config::Configuration
|
18
18
|
|
19
|
-
def initialize(word, dictionary: {})
|
19
|
+
def initialize(word, dictionary: {}, substitutions: {})
|
20
20
|
@word = word.to_sym
|
21
21
|
@dictionary = prepare_dictionary(dictionary)
|
22
|
+
@substitutions = substitutions
|
22
23
|
@path = []
|
23
24
|
end
|
24
25
|
|
@@ -29,7 +30,7 @@ class Russial
|
|
29
30
|
|
30
31
|
private
|
31
32
|
|
32
|
-
attr_reader :dictionary, :word
|
33
|
+
attr_reader :dictionary, :word, :substitutions
|
33
34
|
attr_accessor :path
|
34
35
|
|
35
36
|
def soft_reset_path
|
@@ -38,7 +38,13 @@ class Russial
|
|
38
38
|
self
|
39
39
|
when String
|
40
40
|
soft_reset_path
|
41
|
-
memoized_result
|
41
|
+
substitutions.empty? ? memoized_result : substitute(memoized_result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def substitute(word)
|
46
|
+
substitutions.inject(word) do |result, (from, to)|
|
47
|
+
result.gsub(from, to)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
data/lib/russial/version.rb
CHANGED