russial 0.5.3 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 738361c2494919a080ebce961a1bcc9a43b3eeba
4
- data.tar.gz: b0021e4ca9c8f4ed96e1881e43048f0d2599eeae
3
+ metadata.gz: c6c93429bb71837afc0679f99dfb5d0245cee8f8
4
+ data.tar.gz: a335d150e45f29979e16876c8d439383d46d798a
5
5
  SHA512:
6
- metadata.gz: 83c5823086fc1e3e740905089447030adc5986836564924426c79b6995f1dab39c3b91c58aa657d964ca262ed72ba09609adb7131bded9bce9d9c9a87ca82413
7
- data.tar.gz: ee368bb95c28fd226410cc6d8324cac2dff6318d03e34b11d96a8cb689a2e502e81488bbb59edbba30111949c00b2ed1283a13b08f65071fa00bc05682eafc04
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
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Russial
3
- VERSION = "0.5.3"
3
+ VERSION = "0.6.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: russial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mesto.ru