malvestuto_random_data 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +63 -0
- data/License.txt +20 -0
- data/Manifest.txt +26 -0
- data/PostInstall.txt +0 -0
- data/README.rdoc +130 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/config/website.yml +2 -0
- data/lib/random_data/array_randomizer.rb +65 -0
- data/lib/random_data/booleans.rb +10 -0
- data/lib/random_data/contact_info.rb +24 -0
- data/lib/random_data/dates.rb +47 -0
- data/lib/random_data/grammar.rb +61 -0
- data/lib/random_data/locations.rb +134 -0
- data/lib/random_data/markov.rb +77 -0
- data/lib/random_data/names.rb +73 -0
- data/lib/random_data/numbers.rb +31 -0
- data/lib/random_data/papers.rb +49 -0
- data/lib/random_data/text.rb +70 -0
- data/lib/random_data/version.rb +3 -0
- data/lib/random_data.rb +65 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/test/henry_v_prolog.txt +41 -0
- data/test/test_helper.rb +3 -0
- data/test/test_random_data.rb +277 -0
- metadata +96 -0
data/History.txt
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
== 1.5.0 2008-11-06
|
2
|
+
* 2 major enhancement:
|
3
|
+
* Totally cleaned up and reconfigured hoe using newgem 1.0's conventions
|
4
|
+
* Added Markov model text generator (courtesy of Hugh Sasse)
|
5
|
+
|
6
|
+
* 1 minor enhancement:
|
7
|
+
* Added roulette method to Array (courtesy of Hugh Sasse)
|
8
|
+
|
9
|
+
* 1 minor fix:
|
10
|
+
* Fixed newline bug in the name generator (courtesy of Harold Gimenez)
|
11
|
+
|
12
|
+
== 1.3.1 2008-06-06
|
13
|
+
|
14
|
+
* 2 minor enhancements:
|
15
|
+
* Added added more last and firstnames (courtesy of Hugh Sasse)
|
16
|
+
* Added firstname_male and firstname_female (courtesy of Hugh Sasse)
|
17
|
+
|
18
|
+
== 1.3.0 2008-05-25
|
19
|
+
|
20
|
+
All these enhancements are from Hugh Sasse. Thanks Hugh!
|
21
|
+
|
22
|
+
* 4 major enhancements:
|
23
|
+
* Added RandomData::Grammar, which lets you create simple random sentences (see rdocs)
|
24
|
+
* Added Random.bit and Random.bits
|
25
|
+
* Added Random.grammatical_construct
|
26
|
+
* Fixed up rdocs which had gotten out of date
|
27
|
+
|
28
|
+
* 2 minor enhancements:
|
29
|
+
* Added Random.uk_post_code
|
30
|
+
* Zipcodes should strings, not integers
|
31
|
+
|
32
|
+
== 1.2.1 2007-11-29
|
33
|
+
|
34
|
+
* 1 minor fix:
|
35
|
+
* Updated gem manifest
|
36
|
+
|
37
|
+
== 1.2.0 2007-11-29
|
38
|
+
|
39
|
+
Thanks to Paul Barry and Hugh Sasse for some awesome patches!
|
40
|
+
|
41
|
+
* 1 major enhancement:
|
42
|
+
* Added method_missing to Random class, which looks for a method_name.dat and fetches a random line for you (see docs for details) (Hugh Sasse)
|
43
|
+
* added Random.date_between method to get a date between 2 given dates (Paul Barry)
|
44
|
+
* added Random.boolean method to get a random true or false (Paul Barry)
|
45
|
+
* added Random.number to get a random number less than a number or within a given range (Paul Barry)
|
46
|
+
|
47
|
+
* 1 minor enhancement:
|
48
|
+
* enhanced Random.date method to handle a Range as well as a Fixnum, which allows you to get a date guaranteed to be in the past (Paul Barry)
|
49
|
+
|
50
|
+
* 1 minor fix:
|
51
|
+
* Location sources organized into more understandable categories, for easier future expansion (Hugh Sasse)
|
52
|
+
* Fixed path of require statements in random_data.rb (Paul Barry)
|
53
|
+
* make initial never return nil, because if it returns nil then ContactInfo#email can thrown and error because it tries to call nil. (Paul Barry)
|
54
|
+
|
55
|
+
== 1.0.1 2007-09-17
|
56
|
+
|
57
|
+
* 1 minor fix:
|
58
|
+
* Not creating the Random class properly by extending it (vs. including modules)
|
59
|
+
|
60
|
+
== 1.0.0 2007-09-17
|
61
|
+
|
62
|
+
* 1 major enhancement:
|
63
|
+
* Initial release
|
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Mike Subelsky, subelsky.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
config/website.yml
|
8
|
+
lib/random_data.rb
|
9
|
+
lib/random_data/array_randomizer.rb
|
10
|
+
lib/random_data/booleans.rb
|
11
|
+
lib/random_data/contact_info.rb
|
12
|
+
lib/random_data/dates.rb
|
13
|
+
lib/random_data/grammar.rb
|
14
|
+
lib/random_data/locations.rb
|
15
|
+
lib/random_data/markov.rb
|
16
|
+
lib/random_data/names.rb
|
17
|
+
lib/random_data/numbers.rb
|
18
|
+
lib/random_data/text.rb
|
19
|
+
lib/random_data/version.rb
|
20
|
+
script/console
|
21
|
+
script/destroy
|
22
|
+
script/generate
|
23
|
+
script/txt2html
|
24
|
+
test/henry_v_prolog.txt
|
25
|
+
test/test_helper.rb
|
26
|
+
test/test_random_data.rb
|
data/PostInstall.txt
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
= random_data
|
2
|
+
|
3
|
+
This gem provides a Random singleton class with a series of methods for generating random test data including names, mailing addresses, dates, phone numbers, e-mail addresses, and text. Instead of:
|
4
|
+
|
5
|
+
<tt>foo.name = "John Doe"</tt>
|
6
|
+
|
7
|
+
You get:
|
8
|
+
|
9
|
+
<tt>foo.name = "#{Random.firstname} #{Random.initial} #{Random.lastname}"</tt>
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
<tt>sudo gem install random_data</tt>
|
14
|
+
|
15
|
+
or get the gem manually from http://rubyforge.org/frs/?group_id=4458
|
16
|
+
|
17
|
+
== Methods
|
18
|
+
|
19
|
+
=== Contact Methods
|
20
|
+
Random.phone, Random.international_phone, Random.email
|
21
|
+
|
22
|
+
=== Time/Date Methods
|
23
|
+
Random.date, Random.date_between
|
24
|
+
|
25
|
+
=== Location Methods
|
26
|
+
Random.address_line_1, Random.address_line_2, Random.zipcode, Random.uk_post_code, Random.state, Random.state_full, Random.country, Random.city
|
27
|
+
|
28
|
+
=== Name Methods
|
29
|
+
Random.firstname, Random.firstname_male, Random.firstname_female, Random.initial, Random.lastname
|
30
|
+
|
31
|
+
=== Text Methods
|
32
|
+
Random.alphanumeric, Random.paragraphs
|
33
|
+
|
34
|
+
=== Grammatical Methods
|
35
|
+
Random.grammatical_construct
|
36
|
+
|
37
|
+
=== Number Methods
|
38
|
+
Random.number, Random.bit, Random.bits
|
39
|
+
|
40
|
+
=== Boolean Methods
|
41
|
+
Random.boolean
|
42
|
+
|
43
|
+
=== Markov Generator Methods
|
44
|
+
Random.MarkovGenerator.new
|
45
|
+
Random.MarkovGenerator.insert
|
46
|
+
Random.MarkovGenerator.generate
|
47
|
+
|
48
|
+
=== Array Extension
|
49
|
+
Array.rand
|
50
|
+
Array.roulette
|
51
|
+
|
52
|
+
=== Choose From File Methods
|
53
|
+
Random implements a method_missing helper that will choose a line at random from a file in your load path. See Random::method_missing for details.
|
54
|
+
|
55
|
+
Note that some methods take parameters to bound or limit the amount of data returned. See RDocs for details.
|
56
|
+
|
57
|
+
== Examples of Some Methods
|
58
|
+
|
59
|
+
>>Random.alphanumeric
|
60
|
+
=> "cfbutm3vYfhZXil0"
|
61
|
+
|
62
|
+
>> Random.alphanumeric(5)
|
63
|
+
=> "XYVyn"
|
64
|
+
|
65
|
+
>> Random.paragraphs
|
66
|
+
=> "Ulysses, fighting evil and tyranny with all his power and with all of his might. Ulysses, fighting evil and tyranny with all his power and with all
|
67
|
+
of his might. \n\nHe's got style, a groovy style, and a car that just won't stop. \n\n"
|
68
|
+
|
69
|
+
>> Random.paragraphs(3)
|
70
|
+
=> "Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum. Down the road that's where I'll always be.
|
71
|
+
He's got style, a groovy style, and a car that just won't stop. I've gotten burned over Cheryl Tiegs and blown up for Raquel Welch, but when I end up in the
|
72
|
+
hay it's only hay hey hey. Hey there where ya goin, not exactly knowin'. \n\nLorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor
|
73
|
+
incididunt ut labore et dolore magna aliqua. I might jump an open drawbridge or Tarzan from a vine, beause I'm the unknown stuntman that makes Eastwood look so
|
74
|
+
fine. He just keeps on movin' and ladies keep improvin'. Rolling down to Dallas - who is providin my palace?. Every stop I make I make a new friend; Can't
|
75
|
+
stay for long just turn around and I'm gone again. \n\nAlways fighting all the evil forces bringing peace and justice to all. \n\n"
|
76
|
+
|
77
|
+
>> Random.firstname
|
78
|
+
=> "Thomas"
|
79
|
+
|
80
|
+
>> Random.initial
|
81
|
+
=> "E"
|
82
|
+
|
83
|
+
>> Random.lastname
|
84
|
+
=> "Robinson"
|
85
|
+
|
86
|
+
>> Random.date
|
87
|
+
=> Sun, 09 Sep 2007
|
88
|
+
|
89
|
+
(Returns an actual date object, shown here in its to_s form)
|
90
|
+
|
91
|
+
>> Random.date(1000)
|
92
|
+
=> Sun, 26 Nov 2006
|
93
|
+
|
94
|
+
>> Random.email
|
95
|
+
=> "zrodriguez@example.com"
|
96
|
+
|
97
|
+
>> Random.phone
|
98
|
+
=> "564-103-8353"
|
99
|
+
|
100
|
+
>> Random.international_phone
|
101
|
+
=> "011-24-37-9704"
|
102
|
+
|
103
|
+
>> Random.address_line_1
|
104
|
+
=> "38367 Adams Rd"
|
105
|
+
|
106
|
+
>> Random.address_line_2
|
107
|
+
=> "Lot 247"
|
108
|
+
|
109
|
+
>> Random.zipcode
|
110
|
+
=> 22904
|
111
|
+
|
112
|
+
(Note that the zipcodes are totally random and may not be real zipcodes)
|
113
|
+
|
114
|
+
>> Random.state
|
115
|
+
=> "MD"
|
116
|
+
|
117
|
+
>> Random.state_full
|
118
|
+
=> "New Mexico"
|
119
|
+
|
120
|
+
>> Random.country
|
121
|
+
=> "Philippines"
|
122
|
+
|
123
|
+
== Contact
|
124
|
+
Let me know if you have patches, comments, or suggestions: mailto:mike@subelsky.com
|
125
|
+
|
126
|
+
== Special Thanks
|
127
|
+
Major thanks to Hugh Sasse and {Paul Barry}[http://paulbarry.com/] for their contributions.
|
128
|
+
|
129
|
+
== Copyright
|
130
|
+
Copyright (c) 2008 {Mike Subelsky}[http://subelsky.com/], Baltimore, Maryland, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "random_data"
|
9
|
+
gem.summary = "A Ruby gem that provides a Random class with a series of methods for generating random test data including names, mailing addresses, dates, phone numbers, e-mail addresses, and text."
|
10
|
+
gem.description = "A Ruby gem that provides a Random class with a series of methods for generating random test data including names, mailing addresses, dates, phone numbers, e-mail addresses, and text."
|
11
|
+
gem.email = "random_data@mikeshop.net"
|
12
|
+
gem.authors = ["Mike Subelsky"]
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
20
|
+
# task :default => [:spec, :features]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.5.1
|
data/config/website.yml
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Extends the Array class with a function used to randomly choose elements. Note that if you are using Rails, ActiveSupport recently was updated to include a similar
|
2
|
+
# function. This code checks for the presence of that method and does not try to replace it. They work the same though so no worries.
|
3
|
+
|
4
|
+
module RandomData
|
5
|
+
module ArrayRandomizer
|
6
|
+
|
7
|
+
# Randomly chooses an element from an array
|
8
|
+
# >> [1,2,3].rand = 3
|
9
|
+
# [].rand = nil
|
10
|
+
|
11
|
+
def rand
|
12
|
+
return self[Kernel.rand(self.size)]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Takes an array of non-negative weights
|
16
|
+
# and returns the index selected by a
|
17
|
+
# roulette wheel weighted according to those
|
18
|
+
# weights.
|
19
|
+
# If a block is given then k is used to determine
|
20
|
+
# how many times the block is called. In this
|
21
|
+
# case nil is returned.
|
22
|
+
def roulette(k=1)
|
23
|
+
wheel = []
|
24
|
+
weight = 0
|
25
|
+
# Create the cumulative array.
|
26
|
+
self.each do |x|
|
27
|
+
raise "Illegal negative weight #{x}" if x < 0
|
28
|
+
wheel.push(weight += x)
|
29
|
+
end
|
30
|
+
# print "wheel is #{wheel.inspect}\n";
|
31
|
+
# print "weight is #{weight.inspect}\n";
|
32
|
+
raise "Array had all zero weights" if weight.zero?
|
33
|
+
wheel.push(weight + 1) #Add extra element
|
34
|
+
if block_given?
|
35
|
+
k.times do
|
36
|
+
r = Kernel.rand() # so we don't pick up that from array.
|
37
|
+
# print "r is #{r.inspect}\n";
|
38
|
+
roll = weight.to_f * r
|
39
|
+
# print "roll is #{roll.inspect}\n";
|
40
|
+
0.upto(self.size - 1) do |i|
|
41
|
+
if wheel[i+1] > roll
|
42
|
+
yield i
|
43
|
+
break
|
44
|
+
end # if
|
45
|
+
end # upto
|
46
|
+
end # if block_given?
|
47
|
+
return nil
|
48
|
+
else
|
49
|
+
r = Kernel.rand() # so we don't pick up that from array.
|
50
|
+
# print "r is #{r.inspect}\n";
|
51
|
+
roll = weight.to_f * r
|
52
|
+
# print "roll is #{roll.inspect}\n";
|
53
|
+
0.upto(self.size - 1) do |i|
|
54
|
+
return i if wheel[i+1] > roll
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
unless Array.respond_to?(:rand)
|
64
|
+
Array.send :include, RandomData::ArrayRandomizer
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RandomData
|
2
|
+
# Methods for randomly generating contact data like phone numbers and e-mail addresses
|
3
|
+
|
4
|
+
module ContactInfo
|
5
|
+
|
6
|
+
# Returns a randomly-generated string of digits that roughly resembles a US telephone number. Not guaranteed to be a valid area code.
|
7
|
+
def phone
|
8
|
+
"#{rand(900) + 100}-#{rand(900)+100}-#{rand(10000)+1000}"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a randomly-generated string of digits that roughly resembles an international telephone number as dialed from the US.
|
12
|
+
# Not guaranteed to be a valid number but just good enough to get some sample data going.
|
13
|
+
|
14
|
+
def international_phone
|
15
|
+
"011-#{rand(100) + 1}-#{rand(100)+10}-#{rand(10000)+1000}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns an e-mail address of the form "{first_initial}{last_name}@{domain}"
|
19
|
+
def email
|
20
|
+
domains = %w(yahoo.com gmail.com privacy.net webmail.com msn.com hotmail.com example.com privacy.net)
|
21
|
+
"#{(initial + lastname).downcase}\@#{domains.rand}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module RandomData
|
4
|
+
|
5
|
+
# Defines methods for random date generation
|
6
|
+
|
7
|
+
module Dates
|
8
|
+
|
9
|
+
# Returns a date within a specified range of days. If dayrange is an Integer, then the date
|
10
|
+
# returned will be plus or minus half what you specify. The default is ten days, so by default
|
11
|
+
# you will get a date within plus or minus five days of today.
|
12
|
+
#
|
13
|
+
# If dayrange is a Range, then you will get a date the falls between that range
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
#
|
17
|
+
# Random.date # => a Date +/- 5 days of today
|
18
|
+
# Random.date(20) # => a Date +/- 10 days of today
|
19
|
+
# Random.date(-60..-30) # => a Date between 60 days ago and 30 days ago
|
20
|
+
#
|
21
|
+
def date(dayrange=10)
|
22
|
+
if dayrange.is_a?(Range)
|
23
|
+
offset = rand(dayrange.max-dayrange.min) + dayrange.min
|
24
|
+
else
|
25
|
+
offset = rand(dayrange*2) - dayrange
|
26
|
+
end
|
27
|
+
Date.today + offset
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a date within the specified Range. The Range can be Date or String objects.
|
31
|
+
#
|
32
|
+
#Example:
|
33
|
+
# min = Date.parse('1966-11-15')
|
34
|
+
# max = Date.parse('1990-01-01')
|
35
|
+
# Random.date(min..max) # => a Date between 11/15/1996 and 1/1/1990
|
36
|
+
# Random.date('1966-11-15'..'1990-01-01') # => a Date between 11/15/1996 and 1/1/1990
|
37
|
+
#
|
38
|
+
def date_between(range)
|
39
|
+
min_date = range.min.is_a?(Date) ? range.min : Date.parse(range.min)
|
40
|
+
max_date = range.max.is_a?(Date) ? range.max : Date.parse(range.max)
|
41
|
+
|
42
|
+
diff = (max_date - min_date).to_i
|
43
|
+
min_date + rand(diff)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
module RandomData
|
3
|
+
|
4
|
+
# Defines methods for the generation of random data based on a supplied grammar.
|
5
|
+
|
6
|
+
module Grammar
|
7
|
+
|
8
|
+
# Returns simple sentences based on a supplied grammar, which must be a hash, the
|
9
|
+
# keys of which are symbols. The values are either an array of successive values or a grammar
|
10
|
+
# (i.e, hash with symbols as keys, and hashes or arrays as values. The arrays contain symbols
|
11
|
+
# referencing the keys in the present grammar, or strings to be output. The keys are always symbols.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
# Random.grammatical_construct({:story => [:man, " bites ", :dog], :man => { :bob => "Bob"}, :dog => {:a =>"Rex", :b =>"Rover"}}, :story)
|
15
|
+
# => "Bob bites Rover"
|
16
|
+
|
17
|
+
def grammatical_construct(grammar, what=nil)
|
18
|
+
output = ""
|
19
|
+
if what.nil?
|
20
|
+
case grammar
|
21
|
+
when Hash
|
22
|
+
a_key = grammar.keys.sort_by{rand}[0]
|
23
|
+
output += grammatical_construct(grammar, a_key)
|
24
|
+
when Array
|
25
|
+
grammar.each do |item|
|
26
|
+
output += grammatical_construct(item)
|
27
|
+
end
|
28
|
+
when String
|
29
|
+
output += grammar
|
30
|
+
end
|
31
|
+
else
|
32
|
+
rhs = grammar[what]
|
33
|
+
case rhs
|
34
|
+
when Array
|
35
|
+
rhs.each do |item|
|
36
|
+
case item
|
37
|
+
when Symbol
|
38
|
+
output += grammatical_construct(grammar,item)
|
39
|
+
when String
|
40
|
+
output += item
|
41
|
+
when Hash
|
42
|
+
output += grammatical_construct(item)
|
43
|
+
else
|
44
|
+
raise "#{item.inspect} must be a symbol or string or Hash"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
when Hash
|
48
|
+
output+= grammatical_construct(rhs)
|
49
|
+
when Symbol
|
50
|
+
output += grammatical_construct(rhs)
|
51
|
+
when String
|
52
|
+
output += rhs
|
53
|
+
else
|
54
|
+
raise "#{rhs.inspect} must be a symbol, string, Array or Hash"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
return output
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# coding:utf-8
|
2
|
+
|
3
|
+
module RandomData
|
4
|
+
|
5
|
+
# Defines methods to return random location data.
|
6
|
+
|
7
|
+
module Locations
|
8
|
+
|
9
|
+
|
10
|
+
trees = %w( Acacia Beech Birch Cedar Cherry Chestnut Elm Larch Laurel
|
11
|
+
Linden Maple Oak Pine Rose Walnut Willow)
|
12
|
+
people = %w( Adams Franklin Jackson Jefferson Lincoln
|
13
|
+
Madison Washington Wilson)
|
14
|
+
people_uk = %w( Churchill Tyndale Latimer Cranmer )
|
15
|
+
places = %w( Highland Hill Park Woodland Sunset Virginia)
|
16
|
+
numbers = %w( 1st 2nd 4th 5th 34th 42nd )
|
17
|
+
@@streetnames = trees + people + places + numbers
|
18
|
+
|
19
|
+
@@street_types = %w(St Ave Rd Blvd Trl Ter Rdg Pl Pkwy Ct Circle)
|
20
|
+
|
21
|
+
# Returns the first line of a US maiiling address (street number, street name, street type)
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
#
|
25
|
+
#Random.address_line_1 = "24317 Jefferson Blvd"
|
26
|
+
|
27
|
+
def address_line_1
|
28
|
+
"#{rand(40000)} #{@@streetnames.rand} #{@@street_types.rand}"
|
29
|
+
end
|
30
|
+
|
31
|
+
alias :us_address_line_1 :address_line_1
|
32
|
+
|
33
|
+
@@line2types = ["Apt", "Bsmt", "Bldg", "Dept", "Fl", "Frnt", "Hngr", "Lbby", "Lot", "Lowr", "Ofc", "Ph", "Pier", "Rear", "Rm", "Side", "Slip", "Spc", "Stop", "Ste", "Trlr", "Unit", "Uppr"]
|
34
|
+
|
35
|
+
# Returns the first line of a US maiiling address (street number, street name, street type)
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
#Random.address_line_1 = "24317 Jefferson Blvd"
|
40
|
+
|
41
|
+
def address_line_2
|
42
|
+
"#{@@line2types.rand} #{rand(999)}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a random 5-digit string, not guaranteed to be a legitimate zip code.
|
46
|
+
# Legal zip codes can have leading zeroes and thus they need to be strings.
|
47
|
+
|
48
|
+
def zipcode
|
49
|
+
"%05d" % rand(99999)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Returns a string providing something in the general form of a UK post code. Like the zip codes, this might
|
54
|
+
# not actually be valid. Doesn't cover London whose codes are like "SE1".
|
55
|
+
|
56
|
+
def uk_post_code
|
57
|
+
post_towns = %w(BM CB CV LE LI LS KT MK NE OX PL YO)
|
58
|
+
# Can't remember any othes at the moment
|
59
|
+
number_1 = rand(100).to_s
|
60
|
+
number_2 = rand(100).to_s
|
61
|
+
# Easier way to do this?
|
62
|
+
letters = ("AA".."ZZ").to_a.rand
|
63
|
+
|
64
|
+
return "#{post_towns.rand}#{number_1} #{number_2}#{letters}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# from technoweenie: http://svn.techno-weenie.net/projects/plugins/us_states/lib/us_states.rb
|
68
|
+
@@us_states = [["Alaska", "AK"], ["Alabama", "AL"], ["Arkansas", "AR"], ["Arizona", "AZ"],
|
69
|
+
["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["District of Columbia", "DC"],
|
70
|
+
["Delaware", "DE"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Iowa", "IA"],
|
71
|
+
["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Kansas", "KS"], ["Kentucky", "KY"],
|
72
|
+
["Louisiana", "LA"], ["Massachusetts", "MA"], ["Maryland", "MD"], ["Maine", "ME"], ["Michigan", "MI"],
|
73
|
+
["Minnesota", "MN"], ["Missouri", "MO"], ["Mississippi", "MS"], ["Montana", "MT"], ["North Carolina", "NC"],
|
74
|
+
["North Dakota", "ND"], ["Nebraska", "NE"], ["New Hampshire", "NH"], ["New Jersey", "NJ"],
|
75
|
+
["New Mexico", "NM"], ["Nevada", "NV"], ["New York", "NY"], ["Ohio", "OH"], ["Oklahoma", "OK"],
|
76
|
+
["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"],
|
77
|
+
["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Virginia", "VA"], ["Vermont", "VT"],
|
78
|
+
["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]]
|
79
|
+
|
80
|
+
# Returns a state 2-character abbreviation
|
81
|
+
# Random.state = "IL"
|
82
|
+
|
83
|
+
def state
|
84
|
+
@@us_states.rand[1]
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns a full state name
|
88
|
+
#Random.state_full = "Texas"
|
89
|
+
|
90
|
+
def state_full
|
91
|
+
@@us_states.rand[0]
|
92
|
+
end
|
93
|
+
|
94
|
+
# from http://siteresources.worldbank.org/DATASTATISTICS/Resources/CLASS.XLS
|
95
|
+
@@countries = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia",
|
96
|
+
"Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
|
97
|
+
"Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon",
|
98
|
+
"Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Channel Islands", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.",
|
99
|
+
"Congo, Rep.", "Costa Rica", "Côte d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
|
100
|
+
"Egypt, Arab Rep.", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", "Fiji", "Finland", "France", "French Polynesia",
|
101
|
+
"Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti",
|
102
|
+
"Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Rep.", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica",
|
103
|
+
"Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Kyrgyz Republic", "Lao PDR", "Latvia", "Lebanon", "Lesotho",
|
104
|
+
"Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao, China", "Macedonia, FYR", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta",
|
105
|
+
"Marshall Islands", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Fed. Sts.", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco",
|
106
|
+
"Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria",
|
107
|
+
"Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
|
108
|
+
"Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Samoa", "San Marino", "São Tomé and Principe", "Saudi Arabia", "Senegal", "Serbia",
|
109
|
+
"Seychelles", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "St. Kitts and Nevis",
|
110
|
+
"St. Lucia", "St. Vincent and the Grenadines", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Tajikistan", "Tanzania", "Thailand",
|
111
|
+
"Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
|
112
|
+
"United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela, RB", "Vietnam", "Virgin Islands (U.S.)", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe"]
|
113
|
+
|
114
|
+
# Returns a country name, as listed by the World Bank
|
115
|
+
#
|
116
|
+
#Random.country = "Kenya"
|
117
|
+
|
118
|
+
def country
|
119
|
+
@@countries.rand
|
120
|
+
end
|
121
|
+
|
122
|
+
@@cities = %w(Midway Mount\ Pleasant Greenwood Franklin Oak Grove Centerville Salem Georgetown Fairview Riverside Rotorua Tauranga Whakatane Taupo Wanganui
|
123
|
+
Nababeep Aggeneys Pofadder Polokwane Bela Bela Goukamma Karatara Tswane Prieska Upington Hoopstad Bultfontein Wesselsbron Bothaville Trompsburg
|
124
|
+
Henneman Musina Ogies Kgatlahong Tembisa Tekoza Sebokeng Muntaung Umnkomaaz)
|
125
|
+
|
126
|
+
# Returns a generic city name, with an attempt to have some internationl appeal
|
127
|
+
#
|
128
|
+
# Random.city = "Tekoza"
|
129
|
+
|
130
|
+
def city
|
131
|
+
@@cities.rand
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|