ffaker 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/History.txt +26 -0
- data/LICENSE +21 -0
- data/README.rdoc +37 -0
- data/README.txt +0 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/faker.rb +29 -0
- data/lib/faker/address.rb +143 -0
- data/lib/faker/company.rb +140 -0
- data/lib/faker/internet.rb +50 -0
- data/lib/faker/lorem.rb +59 -0
- data/lib/faker/name.rb +374 -0
- data/lib/faker/phone_number.rb +37 -0
- data/lib/faker/utils/array_utils.rb +44 -0
- data/lib/faker/utils/module_utils.rb +9 -0
- data/lib/faker/version.rb +9 -0
- data/lib/ffaker.rb +1 -0
- data/scripts/benchmark.rb +12 -0
- data/scripts/profile.sh +2 -0
- data/scripts/profiling.rb +7 -0
- data/test/helper.rb +11 -0
- data/test/test_address.rb +56 -0
- data/test/test_array_utils.rb +50 -0
- data/test/test_company.rb +19 -0
- data/test/test_faker.rb +15 -0
- data/test/test_faker_internet.rb +35 -0
- data/test/test_faker_name.rb +19 -0
- data/test/test_lorem.rb +24 -0
- data/test/test_module_utils.rb +12 -0
- data/test/test_phone_number.rb +11 -0
- metadata +97 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module Faker
|
2
|
+
module PhoneNumber
|
3
|
+
extend ModuleUtils
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def phone_number
|
7
|
+
Faker.numerify(FORMATS.rand)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.short_phone_number
|
11
|
+
Faker.numerify(FORMATS.first.dup)
|
12
|
+
end
|
13
|
+
|
14
|
+
FORMATS = k [
|
15
|
+
'###-###-####',
|
16
|
+
'(###)###-####',
|
17
|
+
'1-###-###-####',
|
18
|
+
'###.###.####',
|
19
|
+
'###-###-####',
|
20
|
+
'(###)###-####',
|
21
|
+
'1-###-###-####',
|
22
|
+
'###.###.####',
|
23
|
+
'###-###-#### x###',
|
24
|
+
'(###)###-#### x###',
|
25
|
+
'1-###-###-#### x###',
|
26
|
+
'###.###.#### x###',
|
27
|
+
'###-###-#### x####',
|
28
|
+
'(###)###-#### x####',
|
29
|
+
'1-###-###-#### x####',
|
30
|
+
'###.###.#### x####',
|
31
|
+
'###-###-#### x#####',
|
32
|
+
'(###)###-#### x#####',
|
33
|
+
'1-###-###-#### x#####',
|
34
|
+
'###.###.#### x#####'
|
35
|
+
]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Faker
|
2
|
+
module ArrayUtils
|
3
|
+
def self.const_array(argument)
|
4
|
+
array = argument.is_a?(Array) ? argument : argument.to_a
|
5
|
+
array.extend ArrayUtils
|
6
|
+
freeze_all(array)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.random_pick(array, n)
|
10
|
+
indexes = (0...array.length).sort_by{Kernel.rand}[0...n]
|
11
|
+
indexes.map { |n| array[n].dup }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.rand(array)
|
15
|
+
array[Kernel.rand(array.length)].dup
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.freeze_all(array)
|
19
|
+
array.each { |e| e.freeze }
|
20
|
+
array.freeze
|
21
|
+
array
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.shuffle(array)
|
25
|
+
array.sort_by{Kernel.rand}
|
26
|
+
end
|
27
|
+
|
28
|
+
def random_pick(n)
|
29
|
+
ArrayUtils.random_pick(self, n)
|
30
|
+
end
|
31
|
+
|
32
|
+
def rand
|
33
|
+
ArrayUtils.rand(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def freeze_all
|
37
|
+
ArrayUtils.freeze_all(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def shuffle
|
41
|
+
ArrayUtils.shuffle(self)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/ffaker.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'faker'
|
data/scripts/profile.sh
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
require 'ffaker'
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
def self.it(description, &block)
|
9
|
+
define_method("test_#{ description }", &block)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
|
4
|
+
class TestAddress < Test::Unit::TestCase
|
5
|
+
def test_city
|
6
|
+
assert_match /[ a-z]+/, Faker::Address.city
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_city_prefix
|
10
|
+
assert_match /[ a-z]/, Faker::Address.city_prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_city_suffix
|
14
|
+
assert_match /[ a-z]/, Faker::Address.city_suffix
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_secondary_address
|
18
|
+
assert_match /[ a-z]/, Faker::Address.secondary_address
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_street_address
|
22
|
+
assert_match /[ a-z]/, Faker::Address.street_address
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_street_name
|
26
|
+
assert_match /[ a-z]/, Faker::Address.street_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_street_suffix
|
30
|
+
assert_match /[ a-z]/, Faker::Address.street_suffix
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_uk_country
|
34
|
+
assert_match /[ a-z]/, Faker::Address.uk_country
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_uk_county
|
38
|
+
assert_match /[ a-z]/, Faker::Address.uk_county
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_uk_postcode
|
42
|
+
assert_match /[ a-z]/, Faker::Address.uk_postcode
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_us_state
|
46
|
+
assert_match /[ a-z]/, Faker::Address.us_state
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_us_state_abbr
|
50
|
+
assert_match /[A-Z]/, Faker::Address.us_state_abbr
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_zip_code
|
54
|
+
assert_match /[0-9]/, Faker::Address.zip_code
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
class TestArrayUtils < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@array = Faker::ArrayUtils.const_array("a".."c")
|
7
|
+
@elems = Set.new("a".."c")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "provides a way of freezing the elements and itself" do
|
11
|
+
assert @array.respond_to?(:freeze_all)
|
12
|
+
@array.freeze_all
|
13
|
+
assert @array.frozen?
|
14
|
+
@array.each { |e| assert e.frozen? }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "provides a way of getting a random element" do
|
18
|
+
set = Set.new
|
19
|
+
1000.times { set << @array.rand }
|
20
|
+
assert set == @elems
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a way of getting n random elements" do
|
24
|
+
assert_equal @array.random_pick(3).sort, @array.sort
|
25
|
+
|
26
|
+
1.upto(3) do |n|
|
27
|
+
1000.times do
|
28
|
+
new_arr = @array.random_pick(n)
|
29
|
+
assert_equal n, new_arr.length
|
30
|
+
new_arr.each do |e|
|
31
|
+
assert @elems.include? e
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "provides a way of shuffling the array" do
|
38
|
+
assert_equal @array.shuffle.sort, @array.sort
|
39
|
+
|
40
|
+
different_arrangements = 0
|
41
|
+
|
42
|
+
1000.times do
|
43
|
+
new_arr = @array.shuffle
|
44
|
+
assert new_arr.to_set == @elems
|
45
|
+
different_arrangements += 1 if new_arr != @array
|
46
|
+
end
|
47
|
+
|
48
|
+
assert different_arrangements > 0
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCompany < Test::Unit::TestCase
|
4
|
+
def test_bs
|
5
|
+
assert_match /[ a-z]+/, Faker::Company.bs
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_catch_phrase
|
9
|
+
assert_match /[ a-z]+/, Faker::Company.catch_phrase
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_name
|
13
|
+
assert_match /[ a-z]+/, Faker::Company.name
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_suffix
|
17
|
+
assert_match /[ a-z]+/, Faker::Company.suffix
|
18
|
+
end
|
19
|
+
end
|
data/test/test_faker.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestFaker < Test::Unit::TestCase
|
4
|
+
def test_numerify
|
5
|
+
assert Faker.numerify('###').match(/\d{3}/)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_letterify
|
9
|
+
assert Faker.letterify('???').match(/[a-z]{3}/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_bothify
|
13
|
+
assert Faker.bothify('???###').match(/[a-z]{3}\d{3}/)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestFakerInternet < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tester = Faker::Internet
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_email
|
9
|
+
assert @tester.email.match(/.+@.+\.\w+/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_free_email
|
13
|
+
assert @tester.free_email.match(/.+@(gmail|hotmail|yahoo)\.com/)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_user_name
|
17
|
+
assert @tester.user_name.match(/[a-z]+((_|\.)[a-z]+)?/)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_user_name_with_arg
|
21
|
+
assert @tester.user_name('bo peep').match(/(bo(_|\.)peep|peep(_|\.)bo)/)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_domain_name
|
25
|
+
assert @tester.domain_name.match(/\w+\.\w+/)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_domain_word
|
29
|
+
assert @tester.domain_word.match(/^\w+$/)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_domain_suffix
|
33
|
+
assert @tester.domain_suffix.match(/^\w+(\.\w+)?/)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestFakerName < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tester = Faker::Name
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_name
|
9
|
+
assert @tester.name.match(/(\w+\.? ?){2,3}/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_prefix
|
13
|
+
assert @tester.prefix.match(/[A-Z][a-z]+\.?/)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_suffix
|
17
|
+
assert @tester.suffix.match(/[A-Z][a-z]*\.?/)
|
18
|
+
end
|
19
|
+
end
|
data/test/test_lorem.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestLorem < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_paragraph
|
6
|
+
assert_match /[ a-z]+/, Faker::Lorem.paragraph
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_sentence
|
10
|
+
assert_match /[ a-z]+/, Faker::Lorem.sentence
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_paragraphs
|
14
|
+
assert_match /[ a-z]+/, Faker::Lorem.paragraphs.join(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_sentences
|
18
|
+
assert_match /[ a-z]+/, Faker::Lorem.sentences.join(" ")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_words
|
22
|
+
assert_match /[ a-z]+/, Faker::Lorem.words.join(" ")
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestModuleUtils < Test::Unit::TestCase
|
4
|
+
it "provides a k method for generating constant arrays" do
|
5
|
+
obj = Object.new
|
6
|
+
obj.extend Faker::ModuleUtils
|
7
|
+
result = obj.k ["1","2","3"]
|
8
|
+
|
9
|
+
assert result.frozen?
|
10
|
+
result.each {|e| assert e.frozen? }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPhoneNumer < Test::Unit::TestCase
|
4
|
+
def test_phone_number
|
5
|
+
assert_match /\d{3}[. -]\d{3}/, Faker::PhoneNumber.phone_number
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_short_phone_number
|
9
|
+
assert_match /\d{3}-\d{3}-\d{4}/, Faker::PhoneNumber.short_phone_number
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emmanuel Oga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-15 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Faker refactored
|
17
|
+
email: EmmanuelOga@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
- README.txt
|
26
|
+
files:
|
27
|
+
- .document
|
28
|
+
- .gitignore
|
29
|
+
- History.txt
|
30
|
+
- LICENSE
|
31
|
+
- README.rdoc
|
32
|
+
- README.txt
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- lib/faker.rb
|
36
|
+
- lib/faker/address.rb
|
37
|
+
- lib/faker/company.rb
|
38
|
+
- lib/faker/internet.rb
|
39
|
+
- lib/faker/lorem.rb
|
40
|
+
- lib/faker/name.rb
|
41
|
+
- lib/faker/phone_number.rb
|
42
|
+
- lib/faker/utils/array_utils.rb
|
43
|
+
- lib/faker/utils/module_utils.rb
|
44
|
+
- lib/faker/version.rb
|
45
|
+
- lib/ffaker.rb
|
46
|
+
- scripts/benchmark.rb
|
47
|
+
- scripts/profile.sh
|
48
|
+
- scripts/profiling.rb
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_address.rb
|
51
|
+
- test/test_array_utils.rb
|
52
|
+
- test/test_company.rb
|
53
|
+
- test/test_faker.rb
|
54
|
+
- test/test_faker_internet.rb
|
55
|
+
- test/test_faker_name.rb
|
56
|
+
- test/test_lorem.rb
|
57
|
+
- test/test_module_utils.rb
|
58
|
+
- test/test_phone_number.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/EmmanuelOga/ffaker
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Faker, only cleaner and faster
|
87
|
+
test_files:
|
88
|
+
- test/test_faker_name.rb
|
89
|
+
- test/test_lorem.rb
|
90
|
+
- test/test_phone_number.rb
|
91
|
+
- test/test_array_utils.rb
|
92
|
+
- test/test_address.rb
|
93
|
+
- test/test_faker_internet.rb
|
94
|
+
- test/test_faker.rb
|
95
|
+
- test/test_module_utils.rb
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_company.rb
|