text-gen 0.4.0 → 0.4.2
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/lib/text/gen/result_accumulator.rb +2 -2
- data/lib/text/gen/runner.rb +4 -2
- data/lib/text/gen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 774c55a03bef5a73d7064ec5ed93d5a4b6d5c3848cec572e609281fd3f6605e8
|
|
4
|
+
data.tar.gz: 4b9c9c7f2d67dd926b904b088d3fdbaeaba222ad6bb5ede5ae4e2ac4c130589b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb081e34e4013a9d850b4f93131de88426179f5dc953641753a81afe9a7e9892317f245b700d57d4a1a7ce1e716132bade08cc55805db398f3039e5688d413cf
|
|
7
|
+
data.tar.gz: 10f962fb737618a856fe8320e40fc740931bed0fd10b076df01abf6996ad020c7e3ab8a5e2212f8c09e4314367ca4dc643238c1eb3a1a0f2de118fe8e7e5b762
|
|
@@ -12,8 +12,8 @@ module Text
|
|
|
12
12
|
|
|
13
13
|
def initialize(unique:, count:, max_attempts:)
|
|
14
14
|
@unique = unique
|
|
15
|
-
@count = count
|
|
16
|
-
@max_attempts = max_attempts
|
|
15
|
+
@count = [count, 1].max
|
|
16
|
+
@max_attempts = [max_attempts, 1].max
|
|
17
17
|
@results = unique ? {} : []
|
|
18
18
|
@attempts = max_attempts * count
|
|
19
19
|
end
|
data/lib/text/gen/runner.rb
CHANGED
|
@@ -102,9 +102,11 @@ module Text
|
|
|
102
102
|
rand_weight = rand(total_weight)
|
|
103
103
|
current_weight = 0
|
|
104
104
|
item = items.find do |item|
|
|
105
|
-
current_weight += item
|
|
105
|
+
current_weight += item.fetch("weight", 1).to_i
|
|
106
106
|
current_weight > rand_weight
|
|
107
107
|
end
|
|
108
|
+
return unless item
|
|
109
|
+
|
|
108
110
|
result = run_item(item, depth)
|
|
109
111
|
result.merge_meta(meta)
|
|
110
112
|
result
|
|
@@ -112,7 +114,7 @@ module Text
|
|
|
112
114
|
|
|
113
115
|
def run_item(item, depth)
|
|
114
116
|
locale_item = Filter.replace_locale(item, locale)
|
|
115
|
-
item = locale_item
|
|
117
|
+
item = locale_item || item
|
|
116
118
|
|
|
117
119
|
results = item["segments"].map { |seg| run_segment(seg, depth) }
|
|
118
120
|
result = Result.merge(results,
|
data/lib/text/gen/version.rb
CHANGED