forked from benburkert/randexp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbbf872
commit 069079f
Showing
10 changed files
with
246 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
== 0.1.0 "Very Beta" 2008-07-08 | ||
* Initial version of randexp! | ||
* Has support for very simple regular expressions. | ||
* Randgen has limited methods. | ||
* Dictionary is reading from the local words file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008 Ben Burkert | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
randexp | ||
by Ben Burkert | ||
http://github.com/benburkert/randexp | ||
|
||
== DESCRIPTION: | ||
|
||
andexp makes it easy to generate random string from most regular expressions. | ||
|
||
== REQUIREMENTS: | ||
|
||
* none! | ||
|
||
== INSTALL: | ||
|
||
$ gem sources -a http://gems.github.com/ (you only need to do this once) | ||
$ gem install benburkert-randexp | ||
|
||
== USAGE: | ||
|
||
randexp adds the #generate (or #gen, for short) method to the Regexp class, | ||
which generates a 'random' string that will match your regular expression. | ||
|
||
/abc|def/.gen | ||
# => "def" | ||
|
||
== Valid Regexp's | ||
|
||
randexp can only generate matching string from simple regular expression. | ||
Except for a few circumstances, wildcards are generally not allowed in the | ||
regular expression. is pretty domain specific, so trying to guess when to | ||
terminate a random pattern would produce unhelpful data: | ||
|
||
>> /Aa{3}h*!/.gen | ||
# => RuntimeError: Sorry, "h*" is too vague, try setting a range: "h{0,3}" | ||
>> /Aa{3}h{3,15}!/.gen | ||
=> "Aaaahhhhh!" | ||
|
||
>> /(never gonna (give you up|let you down), )*/.gen | ||
=> RuntimeError: Sorry, "(...)*" is too vague, try setting a range: "(...){0, 3}" | ||
>> /(never gonna (give you up|let you down), ){3,5}/.gen | ||
=> "never gonna give you up, never gonna let you down, never gonna give you up, never gonna give you up, " | ||
|
||
The exception being word characters (\w), which generate a random word from the Dictionary class. | ||
|
||
>> /\w+/.gen | ||
=> "groveling" | ||
|
||
= Primitives & Complex matches | ||
|
||
The single character matchers supported are words(\w), whitespace(\s), and digits(\d). | ||
|
||
>> /\d{50}/.gen | ||
=> "50315410741096763188525493528315906035878741451037" | ||
|
||
When a multiplicity constraint is placed on a word character, a word with the valid length is generated. | ||
|
||
>> /\w{10}/.gen # a word with 10 letters | ||
=> "Chaucerism" | ||
|
||
>> /\w{5,15}/.gen | ||
=> "cabalistic" | ||
|
||
Complex matchers use the [:...:] syntax within the regular expression. | ||
|
||
>> /[:sentence:]/.gen | ||
=> "Nonhearer demetricize toppiece filicic possessedness rhodizite zoomagnetism earwigginess steady" | ||
|
||
Complex matchers can also be added by extending the Randgen class. | ||
|
||
class Randgen | ||
def self.serial_number(options = {}) | ||
/XX\d{4}-\w-\d{5}/.gen | ||
end | ||
end | ||
|
||
>> /[:serial_number:]/.gen | ||
=> "XX3770-M-33114" | ||
|
||
= Dictionary | ||
|
||
The Dictionary loads the local users' words file, allowing randomly generated words to be chosen from | ||
thousands of entries to the words file. Words are mapped by their length to allow words to be randomly | ||
chosen based on size. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
h1. randexp | ||
bq. by Ben Burkert | ||
bq. http://github.com/benburkert/randexp | ||
|
||
h2. DESCRIPTION: | ||
|
||
andexp makes it easy to generate random string from most regular expressions. | ||
|
||
h2. REQUIREMENTS: | ||
|
||
* none! | ||
|
||
h2. INSTALL: | ||
|
||
$ gem sources -a http://gems.github.com/ (you only need to do this once) | ||
$ gem install benburkert-randexp | ||
|
||
h2. USAGE: | ||
|
||
randexp adds the #generate (or #gen, for short) method to the Regexp class, | ||
which generates a 'random' string that will match your regular expression. | ||
|
||
/abc|def/.gen | ||
# => "def" | ||
|
||
h2. Valid Regexp's | ||
|
||
randexp can only generate matching string from simple regular expression. | ||
Except for a few circumstances, wildcards are generally not allowed in the | ||
regular expression. is pretty domain specific, so trying to guess when to | ||
terminate a random pattern would produce unhelpful data: | ||
|
||
<pre> | ||
<code> | ||
>> /Aa{3}h*!/.gen | ||
# => RuntimeError: Sorry, "h*" is too vague, try setting a range: "h{0,3}" | ||
>> /Aa{3}h{3,15}!/.gen | ||
=> "Aaaahhhhh!" | ||
|
||
>> /(never gonna (give you up|let you down), )*/.gen | ||
=> RuntimeError: Sorry, "(...)*" is too vague, try setting a range: "(...){0, 3}" | ||
>> /(never gonna (give you up|let you down), ){3,5}/.gen | ||
=> "never gonna give you up, never gonna let you down, never gonna give you up, never gonna give you up, " | ||
</code> | ||
</pre> | ||
|
||
The exception being word characters (\w), which generate a random word from the Dictionary class. | ||
|
||
<pre> | ||
<code> | ||
>> /\w+/.gen | ||
=> "groveling" | ||
</code> | ||
</pre> | ||
|
||
h3. Primitives & Complex matches | ||
|
||
The single character matchers supported are words(\w), whitespace(\s), and digits(\d). | ||
|
||
<pre> | ||
<code> | ||
>> /\d{50}/.gen | ||
=> "50315410741096763188525493528315906035878741451037" | ||
</code> | ||
</pre> | ||
|
||
When a multiplicity constraint is placed on a word character, a word with the valid length is generated. | ||
|
||
<pre> | ||
<code> | ||
>> /\w{10}/.gen # a word with 10 letters | ||
=> "Chaucerism" | ||
|
||
>> /\w{5,15}/.gen | ||
=> "cabalistic" | ||
</code> | ||
</pre> | ||
|
||
Complex matchers use the [:...:] syntax within the regular expression. | ||
|
||
<pre> | ||
<code> | ||
>> /[:sentence:]/.gen | ||
=> "Nonhearer demetricize toppiece filicic possessedness rhodizite zoomagnetism earwigginess steady" | ||
</code> | ||
</pre> | ||
|
||
Complex matchers can also be added by extending the Randgen class. | ||
|
||
<pre> | ||
<code> | ||
class Randgen | ||
def self.serial_number(options = {}) | ||
/XX\d{4}-\w-\d{5}/.gen | ||
end | ||
end | ||
|
||
>> /[:serial_number:]/.gen | ||
=> "XX3770-M-33114" | ||
</code> | ||
</pre> | ||
|
||
h3. Dictionary | ||
|
||
The Dictionary loads the local users' words file, allowing randomly generated words to be chosen from | ||
thousands of entries to the words file. Words are mapped by their length to allow words to be randomly | ||
chosen based on size. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
class Randexp | ||
VERSION = "0.1.0" | ||
|
||
attr_accessor :sexp | ||
|
||
def initialize(source) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Gem::Specification.new do |s| | ||
s.name = "randexp" | ||
s.version = "0.1.0" | ||
s.date = "2008-07-08" | ||
s.summary = "Library for generating random strings" | ||
s.email = "ben@benburkert.com" | ||
s.homepage = "http://github.com/benburkert/randexp" | ||
s.description = "randexp makes it easy to generate random string from most regular expressions." | ||
s.has_rdoc = true | ||
s.authors = ["Ben Burkert"] | ||
s.files = %w(Rakefile CHANGELOG LICENSE README) + Dir["lib/**/*"] | ||
s.test_files = Dir["spec/**/*"] | ||
s.rdoc_options = ["--main", "README"] | ||
s.extra_rdoc_files = ["CHANGELOG", "README"] | ||
s.require_path = "lib" | ||
end |