jmadlibs 0.8.2 → 0.8.5

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jmadlibs.rb +17 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f83474876cd9a7be9c1bf10249339431f0b2d4f
4
- data.tar.gz: 0ba2f288cc8a1a18c69fcd32cfd7cc48e8417e3e
3
+ metadata.gz: 70bb528dc1a0d1055a27ad44eda45f83f249e79e
4
+ data.tar.gz: fae188b16c19d5216101ba0b679e4b032ef76545
5
5
  SHA512:
6
- metadata.gz: a8d2a726486a64425d4a3329c507a2cdbf25149ad976c078a4c31162022990babc32dc827b0e661a076a25cb4147df2434926c15afabb83f7469fc100322783f
7
- data.tar.gz: bb742fdde3dbd1886b49db77e0b7fc14e53d9c9f81038866a8d99a19e68166282ca762ac10af57d653daf01f8285f4ab8f59668071f7ae99d67b4178a0d80076
6
+ metadata.gz: 51888365ff2bf0092ef38faf4627e72160d31e911c5165fa96d4d916538a3826d2e50238aeff5d55043a7e20eaef853fa8405c5382d49a83e205102ccc5042be
7
+ data.tar.gz: 56992191263a7624c9028888793830efc5b10c9b0aba6046cf9ad4bb3a43ab2cd1bddeb0b80e8283391eb4c28dd6cb378240c9d32a30a3d566bc5a55513020da
data/lib/jmadlibs.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # * joins between two lists: <lista+listb>
13
13
 
14
- # All of the above can be combined and appear in the results of a parsing,
14
+ # All of the above can be combined and appear in the results of a parsing,
15
15
  # so having any operator appear in a substitution word list is possible.
16
16
 
17
17
  # TODO:
@@ -25,10 +25,10 @@ class JMadlibs
25
25
  @loglevels = {0 => "NONE", 1 => "ERROR", 2 => "WARN", 3 => "INFO", 4 => "DEBUG", 5 => "ALL"}
26
26
  @loglevel = 3
27
27
  @rng = Random.new
28
- setPattern(pattern)
28
+ setPattern(pattern)
29
29
  setLibrary(library)
30
30
  end
31
-
31
+
32
32
  def log(msg, priority=5)
33
33
  if priority.is_a? String then priority = @loglevels.key(priority) end
34
34
  if priority <= @loglevel
@@ -48,7 +48,7 @@ class JMadlibs
48
48
  end
49
49
 
50
50
  def setLibrary(library)
51
- if !library.nil?
51
+ if !library.nil?
52
52
  log "Library updated", "DEBUG"
53
53
  @library = library
54
54
  end
@@ -101,6 +101,7 @@ class JMadlibs
101
101
  end
102
102
 
103
103
  def pluralise(word)
104
+ # TODO
104
105
  # add s by default
105
106
  # (lf)(fe?) -> ves
106
107
  # y -> ies
@@ -108,7 +109,6 @@ class JMadlibs
108
109
  # (se?)(sh)(ch)
109
110
 
110
111
  # this is a pretty big problem!
111
-
112
112
  return word
113
113
  end
114
114
 
@@ -119,7 +119,7 @@ class JMadlibs
119
119
  # do we need to do post-processing?
120
120
  post = target.rindex(/\$[ap]/)
121
121
 
122
- if !post.nil?
122
+ if !post.nil?
123
123
  specifier = target.slice(post+1, target.length - post - 1)
124
124
  target = target.slice(0, post)
125
125
  end
@@ -135,18 +135,18 @@ class JMadlibs
135
135
 
136
136
  if mult.nil? # only one list
137
137
  return "MISSING" if @library[target].nil?
138
- result = parse_pattern(@library[target].sample)
138
+ result = parse_pattern(@library[target].sample(random: @rng))
139
139
 
140
140
  else # more than one list
141
141
  multlist = []
142
142
  listnames = []
143
143
 
144
144
  # as long as we still have alternatives, keep adding them to listnames
145
- while !mult.nil?
145
+ while !mult.nil?
146
146
  listnames << target.slice(0, mult)
147
147
  target = target.slice(mult+1, target.length - mult - 1)
148
148
  mult = target.index /\+/
149
- end
149
+ end
150
150
  listnames << target # append final alternative
151
151
 
152
152
  # combine lists for sampling
@@ -155,7 +155,7 @@ class JMadlibs
155
155
  end
156
156
 
157
157
  return "MISSING" if multlist.length == 0 # no valid options found
158
- result = parse_pattern(multlist.sample)
158
+ result = parse_pattern(multlist.sample(random: @rng))
159
159
  end
160
160
 
161
161
  # do post-processing
@@ -186,23 +186,23 @@ class JMadlibs
186
186
  end
187
187
  end
188
188
 
189
- result = options.sample
189
+ result = options.sample(random: @rng)
190
190
  return parse_pattern(result)
191
191
  end
192
-
192
+
193
193
  def resolve_optional(target)
194
194
  chance = 50
195
195
 
196
196
  ind = target.index("%") # specified chance?
197
197
 
198
- if !ind.nil?
198
+ if !ind.nil?
199
199
  chance = target.slice(ind+1, target.length - ind - 1).to_i
200
200
  target = target.slice(0, ind)
201
201
  end
202
202
 
203
203
  result = ""
204
204
 
205
- if rand(100) <= chance
205
+ if @rng.rand(100) <= chance
206
206
  result = target
207
207
  end
208
208
 
@@ -238,7 +238,7 @@ class JMadlibs
238
238
  ind = target.index(">")
239
239
  type = "s"
240
240
  elsif target.slice(0) == "{"
241
- ind = target.index("}")
241
+ ind = target.index("}")
242
242
  type = "a"
243
243
  elsif target.slice(0) == "["
244
244
  ind = target.index("]")
@@ -259,13 +259,13 @@ class JMadlibs
259
259
  end
260
260
 
261
261
  # parse tokens
262
- tokens.each_with_index { |token, index|
262
+ tokens.each_with_index { |token, index|
263
263
  if flags[index] == "a"
264
264
  tokens[index] = resolve_alternative(token)
265
265
  elsif flags[index] == "o"
266
266
  tokens[index] = resolve_optional(token)
267
267
  elsif flags[index] == "s"
268
- tokens[index] = resolve_substitution(token)
268
+ tokens[index] = resolve_substitution(token)
269
269
  end
270
270
  }
271
271
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jmadlibs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gareth Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A madlibs engine with several powerful features
14
14
  email: jacelium@gmail.com