genny 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +19 -1
  3. data/VERSION +1 -1
  4. data/lib/genny/string.rb +4 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjMzY2FjYWYxN2UzOTE1ZTdmOTVjMmU1M2Q5N2MwMmEzOTNkMjEzNg==
4
+ ZTk3M2Q1ZGZkM2FlNWNlZmQ2NTBhYjc3OGFjM2E3NGI0MGQwNmNhZQ==
5
5
  data.tar.gz: !binary |-
6
- MGZlNjNlYTE3NjkwZGM5ZmExYjk5NmFlZmZhMGU3NTU3YWMxOTlkNQ==
6
+ NTY5YjQzODFmODRkZWM0YmE3N2Q4MjhiOTk5MjMyNDI0ZTIzY2I2NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGYxNmM0N2MyYWJiMGFkOTNlYTU2NzI5Y2QzMzNiNTU3MjIwNzJkODg0ZDc4
10
- ZjE0ZTQ4OWUzMDU0NmNiYjI3MGU4NTY3ODg5MGFkNTIzZGVmMzdmN2E5NWE3
11
- YTVkOWFiMWRkZGJlNTRlYTI2ZWFlZjYyZWRlM2RmOTZlY2JjMDU=
9
+ OTJlNTMxMDhmNDljNWE0MzAzMDZlZjNjOTM2MjRiNzkxYmVlNTU2ZGJmZTdk
10
+ MzNhYzZkOGM3ODhkOTA5ZTg3OGYxNjdmMzc1YjM0ZGE1OWMyYzg3YjE5NGIw
11
+ MDc3MWM3NzZiNDY0NDA0YTA1MmM0MGViN2VhNjBkNjlkMzk1ZDc=
12
12
  data.tar.gz: !binary |-
13
- MmVjNWYwMDk4MGY3Nzg5ZjQ0MWFiYjU4OTg1OTMxYTEyNGQwZTg0ZTY2ZjYx
14
- ODdlYjkyMWJhZDkxOGIyMmViMWZjNmU3YjViZDNmYTI3MGE3OTFiNWE2YzQw
15
- YWU4Nzc2ZGEyYjAwZDg0ZGI1OGYwMDliNDhlODNmNmVhOTFiYzU=
13
+ YmZhNDhmY2RkN2IwMWFmNzRkNjBiY2U4M2Y2NjM3ZTAyY2Y0ZTVmZmIzNDli
14
+ MTNmMzI5YjBmMTVjMzllZTJhODU1ZGMxNjExN2YxYThjYjdiNzQ0ZDNkZmNl
15
+ NjA3NmU5NDBhMzE1ODkwZmQxZTRhNzM4NDdjYmYwZWNjNjEwMjY=
data/README.md CHANGED
@@ -176,12 +176,30 @@ Generating a regular expression is a bit useless (it always returns `/.*/` which
176
176
  Genny::Regexp.genny
177
177
  # => /.*/
178
178
 
179
- # The following hasn't been implemented yet. But soon!
180
179
  /[a-f0-9]{2}/.extend(Genny::Regexp).genny
181
180
  # => "a7"
182
181
  Genny.extend_core
183
182
  /[a-f0-9]{2}/.genny
184
183
  # => "5c"
184
+
185
+ # You can also specify regular expressions as formats for strings
186
+ Genny::String.genny(format: "^979\\d{10}$")
187
+ # => "9790607263440"
188
+ ```
189
+
190
+ **Please note**: Regular expression support is not guaranteed. I mean, I'm parsing regular expressions *with regular expressions* and that way madness lies.
191
+
192
+ If you're calling `genny` on a regular expression instance, be sure to rescue `NotImplementedError` exceptions, which will be thrown if the generated string doesn't match the Regexp.
193
+
194
+ If you're generating a string with a format that looks like a regular expression, the worst that will happen is a string will be returned as if no `format` had been specified. If you need a specific regular expression to work and don't feel like driving yourself insane, you can specfify a `format` with the regular expression you need and write your own code to generate it:
195
+
196
+ ```
197
+ Genny::String.format("^(?!un)") do |opts|
198
+ Genny::String.genny.sub(/^un/, '')
199
+ end
200
+
201
+ Genny::String.genny(format: "^(?!un)")
202
+ # => "doesntstartwithun"
185
203
  ```
186
204
 
187
205
  ## Contributing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/lib/genny/string.rb CHANGED
@@ -18,7 +18,10 @@ module Genny
18
18
  viable_formats = @@formats.keys & [*opts[:format]]
19
19
  return @@formats[viable_formats.sample].call(opts) unless viable_formats.empty?
20
20
  if (re = ::Regexp.new(opts[:format]) rescue false)
21
- return re.extend(Genny::Regexp).genny
21
+ begin
22
+ return re.extend(Genny::Regexp).genny
23
+ rescue
24
+ end
22
25
  end
23
26
  guess = @@hints.inject(nil) { |guess, hint|
24
27
  break guess if !(guess = hint.call(opts)).nil?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital