randexp 0.1.4 → 0.1.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.
- data/LICENSE +2 -2
- data/Rakefile +13 -4
- data/lib/randexp.rb +1 -1
- data/lib/randexp/core_ext.rb +1 -1
- data/lib/randexp/core_ext/integer.rb +1 -1
- data/lib/randexp/core_ext/range.rb +1 -1
- data/lib/randexp/core_ext/regexp.rb +1 -1
- data/lib/randexp/dictionary.rb +6 -4
- data/lib/randexp/parser.rb +1 -1
- data/lib/randexp/randgen.rb +12 -6
- data/lib/randexp/reducer.rb +2 -2
- data/lib/randexp/wordlists/female_names.rb +1 -1
- data/lib/randexp/wordlists/male_names.rb +1 -1
- data/lib/randexp/wordlists/real_name.rb +1 -1
- data/spec/regression/regexp_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -3
- data/spec/unit/core_ext/regexp_spec.rb +1 -1
- data/spec/unit/randexp/parser_spec.rb +1 -1
- data/spec/unit/randexp/reducer_spec.rb +1 -1
- data/spec/unit/randexp_spec.rb +1 -1
- data/spec/unit/randgen_spec.rb +30 -7
- metadata +17 -14
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008 Ben Burkert
|
1
|
+
Copyright (c) 2008-2009 Ben Burkert
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake/gempackagetask'
|
3
2
|
require 'rubygems/specification'
|
4
3
|
require 'date'
|
5
4
|
require "spec/rake/spectask"
|
6
5
|
require 'rake/rdoctask'
|
6
|
+
require 'bundler'
|
7
7
|
|
8
8
|
PROJECT_NAME = "randexp"
|
9
9
|
GEM = "randexp"
|
10
|
-
GEM_VERSION = "0.1.
|
10
|
+
GEM_VERSION = "0.1.5"
|
11
11
|
AUTHOR = "Ben Burkert"
|
12
12
|
EMAIL = "ben@benburkert.com"
|
13
13
|
HOMEPAGE = "http://github.com/benburkert/randexp"
|
@@ -18,6 +18,8 @@ RDOC_FILES = %w(LICENSE README README Rakefile TODO CHANGELOG) + Dir.glob("lib/*
|
|
18
18
|
|
19
19
|
RUBYFORGE_USER = "benburkert"
|
20
20
|
|
21
|
+
task :default => :specs
|
22
|
+
|
21
23
|
spec = Gem::Specification.new do |s|
|
22
24
|
s.name = GEM
|
23
25
|
s.version = GEM_VERSION
|
@@ -33,6 +35,13 @@ spec = Gem::Specification.new do |s|
|
|
33
35
|
s.require_path = 'lib'
|
34
36
|
s.autorequire = GEM
|
35
37
|
s.files = FILES
|
38
|
+
|
39
|
+
manifest = Bundler::Definition.from_gemfile('Gemfile')
|
40
|
+
manifest.dependencies.each do |d|
|
41
|
+
next unless d.groups.include?(:runtime)
|
42
|
+
s.add_dependency(d.name, d.version_requirements.to_s)
|
43
|
+
end
|
44
|
+
|
36
45
|
end
|
37
46
|
|
38
47
|
Rake::GemPackageTask.new(spec) do |package|
|
@@ -64,7 +73,7 @@ Spec::Rake::SpecTask.new("specs:unit") do |t|
|
|
64
73
|
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
65
74
|
t.rcov_opts << '--only-uncovered'
|
66
75
|
t.rcov_opts << '--output coverage/unit'
|
67
|
-
|
76
|
+
|
68
77
|
end
|
69
78
|
|
70
79
|
desc "Run all regression specs"
|
@@ -108,4 +117,4 @@ task :release => [:specs, :package, :doc] do
|
|
108
117
|
%w[zip tgz].each do |ext|
|
109
118
|
sh %{rubyforge add_file #{PROJECT_NAME} #{GEM} "#{GEM_VERSION}" pkg/#{GEM}-#{GEM_VERSION}.#{ext}}
|
110
119
|
end
|
111
|
-
end
|
120
|
+
end
|
data/lib/randexp.rb
CHANGED
data/lib/randexp/core_ext.rb
CHANGED
data/lib/randexp/dictionary.rb
CHANGED
@@ -10,8 +10,7 @@ class Randexp::Dictionary
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.words(options = {})
|
13
|
-
|
14
|
-
when options.has_key?(:length)
|
13
|
+
if options.has_key?(:length)
|
15
14
|
words_by_length[options[:length]]
|
16
15
|
else
|
17
16
|
@@words ||= load_dictionary
|
@@ -19,6 +18,9 @@ class Randexp::Dictionary
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def self.words_by_length
|
22
|
-
@@words_by_length ||=
|
21
|
+
@@words_by_length ||= begin
|
22
|
+
hash = Hash.new {|h,k| h[k] = [] }
|
23
|
+
words.inject(hash) {|h, w| h[w.size] << w; h }
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end
|
data/lib/randexp/parser.rb
CHANGED
data/lib/randexp/randgen.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Randgen
|
2
2
|
WORDS_PER_SENTENCE = 3..20
|
3
3
|
SENTENCES_PER_PARAGRAPH = 3..8
|
4
|
-
|
4
|
+
|
5
5
|
def self.bool(options = {})
|
6
6
|
['true', 'false'].pick
|
7
7
|
end
|
@@ -33,15 +33,16 @@ class Randgen
|
|
33
33
|
def self.word(options = {})
|
34
34
|
begin
|
35
35
|
word = Randexp::Dictionary.words(options).pick
|
36
|
+
word ||= options[:length].of { alpha_numeric }.join
|
36
37
|
end until word =~ /^\w+$/
|
37
38
|
|
38
39
|
word
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
def self.first_name(options = {})
|
42
43
|
RealName.first_names(options).pick
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def self.surname(options = {})
|
46
47
|
RealName.surnames(options).pick
|
47
48
|
end
|
@@ -49,11 +50,16 @@ class Randgen
|
|
49
50
|
class << self
|
50
51
|
alias_method :last_name, :surname
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
def self.name(options = {})
|
54
55
|
"#{first_name(options)} #{surname(options)}"
|
55
56
|
end
|
56
57
|
|
58
|
+
def self.email(options = {})
|
59
|
+
domain = options.fetch(:domain, "#{word(options)}.example.org")
|
60
|
+
"#{word(options)}@#{domain}"
|
61
|
+
end
|
62
|
+
|
57
63
|
def self.sentence(options = {})
|
58
64
|
((options[:length] || WORDS_PER_SENTENCE.pick).of { word } * " ").capitalize
|
59
65
|
end
|
@@ -62,11 +68,11 @@ class Randgen
|
|
62
68
|
((options[:length] || SENTENCES_PER_PARAGRAPH.pick).of { sentence } * ". ") + "."
|
63
69
|
end
|
64
70
|
|
65
|
-
def self.phone_number(options = {})
|
71
|
+
def self.phone_number(options = {})
|
66
72
|
case options[:length]
|
67
73
|
when 7 then /\d{3}-\d{4}/.gen
|
68
74
|
when 10 then /\d{3}-\d{3}-\d{4}/.gen
|
69
75
|
else /(\d{3}-)?\d{3}-\d{4}/.gen
|
70
76
|
end
|
71
77
|
end
|
72
|
-
end
|
78
|
+
end
|
data/lib/randexp/reducer.rb
CHANGED
@@ -88,7 +88,7 @@ class Randexp
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.randgen(args, quantity)
|
91
|
-
method_name = *args
|
91
|
+
method_name, _ = *args
|
92
92
|
case quantity
|
93
93
|
when :'?' then ['', Randgen.send(method_name, :length => 1)].pick
|
94
94
|
when :+, :'+?' then Randgen.send(method_name)
|
@@ -99,4 +99,4 @@ class Randexp
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
|
-
end
|
102
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/randexp_spec.rb
CHANGED
data/spec/unit/randgen_spec.rb
CHANGED
@@ -58,6 +58,9 @@ describe Randgen do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe ".word" do
|
61
|
+
it "should handle generating long strings" do
|
62
|
+
Randgen.word(:length => 64).length.should == 64
|
63
|
+
end
|
61
64
|
it "should pick an entry from Dictionary" do
|
62
65
|
10.times do
|
63
66
|
Randexp::Dictionary.words.should include(Randgen.word)
|
@@ -123,6 +126,26 @@ describe Randgen do
|
|
123
126
|
end
|
124
127
|
end
|
125
128
|
|
129
|
+
describe ".email" do
|
130
|
+
it "should pick a local-part from the dictionnary" do
|
131
|
+
100.times do
|
132
|
+
Randexp::Dictionary.words.should include(Randgen.email[/^(\w+)@/, 1])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should use the domain option paramter" do
|
137
|
+
100.times do
|
138
|
+
Randgen.email(:domain => 'foobar.com')[/@((?:\w|\.)+)$/, 1].should == 'foobar.com'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should pick a subdomain of example.org by default" do
|
143
|
+
100.times do
|
144
|
+
Randexp::Dictionary.words.should include(Randgen.email[/@(\w+)\.example\.org$/, 1])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
126
149
|
describe ".sentence" do
|
127
150
|
it "should be capitalized" do
|
128
151
|
10.times do
|
@@ -164,7 +187,7 @@ describe Randgen do
|
|
164
187
|
Randgen.first_name.should =~ /\w/
|
165
188
|
end
|
166
189
|
end
|
167
|
-
|
190
|
+
|
168
191
|
it "should generate a male first name" do
|
169
192
|
male_list = RealName.male_first_names
|
170
193
|
100.times do
|
@@ -172,7 +195,7 @@ describe Randgen do
|
|
172
195
|
male_list.include?(Randgen.first_name(:gender => :male)).should be_true
|
173
196
|
end
|
174
197
|
end
|
175
|
-
|
198
|
+
|
176
199
|
it "should generate a female first name" do
|
177
200
|
female_list = RealName.female_first_names
|
178
201
|
100.times do
|
@@ -180,19 +203,19 @@ describe Randgen do
|
|
180
203
|
female_list.include?(Randgen.first_name(:gender => :female)).should be_true
|
181
204
|
end
|
182
205
|
end
|
183
|
-
|
206
|
+
|
184
207
|
it "should generate a last name" do
|
185
208
|
100.times do
|
186
209
|
Randgen.last_name.should =~ /\w/
|
187
210
|
end
|
188
211
|
end
|
189
|
-
|
212
|
+
|
190
213
|
it "should generate a real name" do
|
191
214
|
100.times do
|
192
215
|
Randgen.name.should =~ /\w{2}/
|
193
216
|
end
|
194
217
|
end
|
195
|
-
|
218
|
+
|
196
219
|
it "should generate a real male name" do
|
197
220
|
male_list = RealName.male_first_names
|
198
221
|
100.times do
|
@@ -201,7 +224,7 @@ describe Randgen do
|
|
201
224
|
male_list.include?(name.split(' ').first).should be_true
|
202
225
|
end
|
203
226
|
end
|
204
|
-
|
227
|
+
|
205
228
|
it "should generate a real female name" do
|
206
229
|
female_list = RealName.female_first_names
|
207
230
|
100.times do
|
@@ -210,4 +233,4 @@ describe Randgen do
|
|
210
233
|
female_list.include?(name.split(' ').first).should be_true
|
211
234
|
end
|
212
235
|
end
|
213
|
-
end
|
236
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: randexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Burkert
|
@@ -9,10 +9,19 @@ autorequire: randexp
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ParseTree
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description: Library for generating random strings.
|
17
26
|
email: ben@benburkert.com
|
18
27
|
executables: []
|
@@ -29,9 +38,6 @@ files:
|
|
29
38
|
- Rakefile
|
30
39
|
- TODO
|
31
40
|
- CHANGELOG
|
32
|
-
- lib/randexp
|
33
|
-
- lib/randexp/core
|
34
|
-
- lib/randexp/core_ext
|
35
41
|
- lib/randexp/core_ext/array.rb
|
36
42
|
- lib/randexp/core_ext/integer.rb
|
37
43
|
- lib/randexp/core_ext/range.rb
|
@@ -41,18 +47,13 @@ files:
|
|
41
47
|
- lib/randexp/parser.rb
|
42
48
|
- lib/randexp/randgen.rb
|
43
49
|
- lib/randexp/reducer.rb
|
44
|
-
- lib/randexp/wordlists
|
45
50
|
- lib/randexp/wordlists/female_names.rb
|
46
51
|
- lib/randexp/wordlists/male_names.rb
|
47
52
|
- lib/randexp/wordlists/real_name.rb
|
48
53
|
- lib/randexp.rb
|
49
|
-
- spec/regression
|
50
54
|
- spec/regression/regexp_spec.rb
|
51
55
|
- spec/spec_helper.rb
|
52
|
-
- spec/unit
|
53
|
-
- spec/unit/core_ext
|
54
56
|
- spec/unit/core_ext/regexp_spec.rb
|
55
|
-
- spec/unit/randexp
|
56
57
|
- spec/unit/randexp/parser_spec.rb
|
57
58
|
- spec/unit/randexp/reducer_spec.rb
|
58
59
|
- spec/unit/randexp_spec.rb
|
@@ -62,6 +63,8 @@ files:
|
|
62
63
|
- wordlists/surnames
|
63
64
|
has_rdoc: true
|
64
65
|
homepage: http://github.com/benburkert/randexp
|
66
|
+
licenses: []
|
67
|
+
|
65
68
|
post_install_message:
|
66
69
|
rdoc_options: []
|
67
70
|
|
@@ -82,9 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
85
|
requirements: []
|
83
86
|
|
84
87
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.3.
|
88
|
+
rubygems_version: 1.3.5
|
86
89
|
signing_key:
|
87
|
-
specification_version:
|
90
|
+
specification_version: 3
|
88
91
|
summary: Library for generating random strings.
|
89
92
|
test_files: []
|
90
93
|
|