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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e32773381d2c8aa30b9c027bf9c5a00f4b76045eff5e6fd36626d94fa33de652
4
- data.tar.gz: 97e3c3b49b367939e270582fb3c6b2e940d623bfec93fab341af27fe1e3902d6
3
+ metadata.gz: 774c55a03bef5a73d7064ec5ed93d5a4b6d5c3848cec572e609281fd3f6605e8
4
+ data.tar.gz: 4b9c9c7f2d67dd926b904b088d3fdbaeaba222ad6bb5ede5ae4e2ac4c130589b
5
5
  SHA512:
6
- metadata.gz: 68f26c344a0feb1b1a730d9247e41c8dc93e27f1a52f22f7d16bdb0c1d719ba3ff03b294475f36e1c404c816192a995c9c3341ff845af0b29d6ad0a37e0e5028
7
- data.tar.gz: 3021702f504892d11d449c2de96ad98d5b5b1d7d514f4bc8f32e91b172e74383a3338faf1256fc03c57dcba34fb6442ccc560ad004e7ddc948c2e709562ce684
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
@@ -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["weight"]
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 if 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,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Text
4
4
  module Gen
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - G Palmer