genny 0.4.0 → 0.4.1
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 +8 -8
- data/README.md +19 -1
- data/VERSION +1 -1
- data/lib/genny/string.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTk3M2Q1ZGZkM2FlNWNlZmQ2NTBhYjc3OGFjM2E3NGI0MGQwNmNhZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTY5YjQzODFmODRkZWM0YmE3N2Q4MjhiOTk5MjMyNDI0ZTIzY2I2NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTJlNTMxMDhmNDljNWE0MzAzMDZlZjNjOTM2MjRiNzkxYmVlNTU2ZGJmZTdk
|
10
|
+
MzNhYzZkOGM3ODhkOTA5ZTg3OGYxNjdmMzc1YjM0ZGE1OWMyYzg3YjE5NGIw
|
11
|
+
MDc3MWM3NzZiNDY0NDA0YTA1MmM0MGViN2VhNjBkNjlkMzk1ZDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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.
|
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
|
-
|
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?
|