sixarm_ruby_fab 1.0.0

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gemtest +0 -0
  5. data/CONTRIBUTING.md +28 -0
  6. data/README.md +91 -0
  7. data/Rakefile +8 -0
  8. data/VERSION +1 -0
  9. data/lib/sixarm_ruby_fab.rb +40 -0
  10. data/lib/sixarm_ruby_fab/agent.rb +20 -0
  11. data/lib/sixarm_ruby_fab/basic.rb +26 -0
  12. data/lib/sixarm_ruby_fab/company.rb +21 -0
  13. data/lib/sixarm_ruby_fab/date.rb +45 -0
  14. data/lib/sixarm_ruby_fab/datetime.rb +44 -0
  15. data/lib/sixarm_ruby_fab/email.rb +12 -0
  16. data/lib/sixarm_ruby_fab/files.rb +113 -0
  17. data/lib/sixarm_ruby_fab/forgery/geo.rb +56 -0
  18. data/lib/sixarm_ruby_fab/forgery/uri.rb +12 -0
  19. data/lib/sixarm_ruby_fab/geo.rb +21 -0
  20. data/lib/sixarm_ruby_fab/id.rb +28 -0
  21. data/lib/sixarm_ruby_fab/internet.rb +12 -0
  22. data/lib/sixarm_ruby_fab/locale.rb +34 -0
  23. data/lib/sixarm_ruby_fab/mime.rb +29 -0
  24. data/lib/sixarm_ruby_fab/names.rb +30 -0
  25. data/lib/sixarm_ruby_fab/password.rb +16 -0
  26. data/lib/sixarm_ruby_fab/phone.rb +12 -0
  27. data/lib/sixarm_ruby_fab/postal.rb +39 -0
  28. data/lib/sixarm_ruby_fab/text.rb +58 -0
  29. data/lib/sixarm_ruby_fab/time.rb +44 -0
  30. data/lib/sixarm_ruby_fab/twitter.rb +119 -0
  31. data/lib/sixarm_ruby_fab/username.rb +16 -0
  32. data/lib/sixarm_ruby_fab/uuid.rb +27 -0
  33. data/test/sixarm_ruby_fab_test.rb +32 -0
  34. data/test/sixarm_ruby_fab_test/agent_test.rb +40 -0
  35. data/test/sixarm_ruby_fab_test/basic_test.rb +35 -0
  36. data/test/sixarm_ruby_fab_test/company_test.rb +34 -0
  37. data/test/sixarm_ruby_fab_test/date_test.rb +67 -0
  38. data/test/sixarm_ruby_fab_test/datetime_test.rb +66 -0
  39. data/test/sixarm_ruby_fab_test/email_test.rb +22 -0
  40. data/test/sixarm_ruby_fab_test/files_test.rb +106 -0
  41. data/test/sixarm_ruby_fab_test/forgery/geo_test.rb +0 -0
  42. data/test/sixarm_ruby_fab_test/forgery/uri_test.rb +0 -0
  43. data/test/sixarm_ruby_fab_test/geo_test.rb +34 -0
  44. data/test/sixarm_ruby_fab_test/id_test.rb +34 -0
  45. data/test/sixarm_ruby_fab_test/internet_test.rb +23 -0
  46. data/test/sixarm_ruby_fab_test/locale_test.rb +51 -0
  47. data/test/sixarm_ruby_fab_test/mime_test.rb +41 -0
  48. data/test/sixarm_ruby_fab_test/names_test.rb +47 -0
  49. data/test/sixarm_ruby_fab_test/password_test.rb +26 -0
  50. data/test/sixarm_ruby_fab_test/phone_test.rb +22 -0
  51. data/test/sixarm_ruby_fab_test/postal_test.rb +58 -0
  52. data/test/sixarm_ruby_fab_test/text_test.rb +58 -0
  53. data/test/sixarm_ruby_fab_test/time_test.rb +66 -0
  54. data/test/sixarm_ruby_fab_test/twitter_test.rb +98 -0
  55. data/test/sixarm_ruby_fab_test/username_test.rb +58 -0
  56. data/test/sixarm_ruby_fab_test/uuid_test.rb +34 -0
  57. metadata +159 -0
  58. metadata.gz.sig +3 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cfd05a4915d109badc07b3de31b368a094764e4
4
+ data.tar.gz: b1308a6558b30ddd6f44f7003d93302ae5ddbc19
5
+ SHA512:
6
+ metadata.gz: 9ce73304f967d12d5a7e24b37c8dd5a0666581fae01ff4b6a41b5ac7ed05b12704b497e90a325c53b542004e9b30c472f1070acec5464b1f5e5cdca64036895e
7
+ data.tar.gz: 747bde33626df662131b4661c1df943890bd67fa175f35368c81e99ee49149b64e45475a1d2343211189d5dec69c3350596773d86b6c657bec5098d4f31a3573
@@ -0,0 +1 @@
1
+ ��*�j�������n�@��x�sR`��rX’�Q֍B
Binary file
File without changes
@@ -0,0 +1,28 @@
1
+ # Contributing
2
+
3
+ Thank you for contributing!
4
+
5
+ If you would like to contribute a donation, an easy way is to use PayPal to sixarm@sixarm.com.
6
+
7
+ If you would like to contribute help, the next section is for you.
8
+
9
+
10
+ ## Contributing to the source
11
+
12
+ We love pull requests for improvments to the source code and documentation.
13
+
14
+ There are three easy steps:
15
+
16
+ 1. Fork the repo.
17
+
18
+ * Before you do any work please run our existing tests to make sure the code runs cleanly.
19
+
20
+ 2. Work as you like.
21
+
22
+ * Please create tests. This helps us know that all your code runs cleanly.
23
+
24
+ 3. Push to your fork and submit a pull request.
25
+
26
+ * We'll take a look as soon as we can; this is typically within a business day.
27
+
28
+ Thank you again!
@@ -0,0 +1,91 @@
1
+ # SixArm.com » Ruby » <br> Fab gem for fabricated sample data for testing
2
+
3
+ * Doc: <http://sixarm.com/sixarm_ruby_fab/doc>
4
+ * Gem: <http://rubygems.org/gems/sixarm_ruby_fab>
5
+ * Repo: <http://github.com/sixarm/sixarm_ruby_fab>
6
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
7
+
8
+ ## Introduction
9
+
10
+ Fabricate sample data suitable for testing.
11
+
12
+ Requires the Forgery gem.
13
+
14
+ For docs go to <http://sixarm.com/sixarm_ruby_fab/doc>
15
+
16
+ Want to help? We're happy to get pull requests.
17
+
18
+
19
+ ## Install quickstart
20
+
21
+ Install:
22
+
23
+ gem install sixarm_ruby_fab
24
+
25
+ Bundler:
26
+
27
+ gem "sixarm_ruby_fab", "~>1.0.0"
28
+
29
+ Require:
30
+
31
+ require "sixarm_ruby_fab"
32
+
33
+
34
+ ## Install with security (optional)
35
+
36
+ To enable high security for all our gems:
37
+
38
+ wget http://sixarm.com/sixarm.pem
39
+ gem cert --add sixarm.pem
40
+ gem sources --add http://sixarm.com
41
+
42
+ To install with high security:
43
+
44
+ gem install sixarm_ruby_fab --test --trust-policy HighSecurity
45
+
46
+
47
+ ## Examples
48
+
49
+ Create a fab:
50
+
51
+ require "sixarm_ruby_fab"
52
+ fab = Fab.new
53
+
54
+ Use it:
55
+
56
+ fab.email_address #=> "foo@bar.com"
57
+ fab.street_address #=> "123 Main Street"
58
+
59
+
60
+ ## Changes
61
+
62
+ * 2013-08-01 1.0.0 Publish.
63
+
64
+
65
+ ## License
66
+
67
+ You may choose any of these open source licenses:
68
+
69
+ * Apache License
70
+ * BSD License
71
+ * CreativeCommons License, Non-commercial Share Alike
72
+ * GNU General Public License Version 2 (GPL 2)
73
+ * GNU Lesser General Public License (LGPL)
74
+ * MIT License
75
+ * Perl Artistic License
76
+ * Ruby License
77
+
78
+ The software is provided "as is", without warranty of any kind,
79
+ express or implied, including but not limited to the warranties of
80
+ merchantability, fitness for a particular purpose and noninfringement.
81
+
82
+ In no event shall the authors or copyright holders be liable for any
83
+ claim, damages or other liability, whether in an action of contract,
84
+ tort or otherwise, arising from, out of or in connection with the
85
+ software or the use or other dealings in the software.
86
+
87
+ This license is for the included software that is created by SixArm;
88
+ some of the included software may have its own licenses, copyrights,
89
+ authors, etc. and these do take precedence over the SixArm license.
90
+
91
+ Copyright (c) 2005-2013 Joel Parker Henderson
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+ require 'pathname'
7
+ require 'securerandom'
8
+ require 'forgery' # gem
9
+ require 'sixarm_ruby_fab/forgery/geo'
10
+ require 'sixarm_ruby_fab/forgery/uri'
11
+
12
+ class Fab
13
+ AZ = ('a'..'z').to_a
14
+ end
15
+
16
+ [
17
+ 'agent',
18
+ 'basic',
19
+ 'company',
20
+ 'date',
21
+ 'datetime',
22
+ 'email',
23
+ 'files',
24
+ 'geo',
25
+ 'id',
26
+ 'internet',
27
+ 'locale',
28
+ 'mime',
29
+ 'names',
30
+ 'password',
31
+ 'phone',
32
+ 'postal',
33
+ 'text',
34
+ 'time',
35
+ 'twitter',
36
+ 'username',
37
+ 'uuid'
38
+ ].each{|x|
39
+ require "sixarm_ruby_fab/#{x}.rb"
40
+ }
@@ -0,0 +1,20 @@
1
+ class Fab
2
+
3
+ AGENT_LIST = [
4
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405",
5
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B179",
6
+ "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; SCH-I500 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
7
+ "Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; EVO Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
8
+ ]
9
+
10
+ attr_accessor :agent_list
11
+
12
+ def agent
13
+ agent_list.sample
14
+ end
15
+
16
+ def agent_list
17
+ @agent_list ||= AGENT_LIST
18
+ end
19
+
20
+ end
@@ -0,0 +1,26 @@
1
+ class Fab
2
+
3
+ # Fab a boolean, either true or false.
4
+ #
5
+ # @return [boolean] either true or false.
6
+ #
7
+ def boolean
8
+ [true, false].sample
9
+ end
10
+
11
+ # Fab a rating, such as 1 to 5 stars.
12
+ #
13
+ # Options:
14
+ #
15
+ # * min: 1
16
+ # * max: 5
17
+ #
18
+ # @return [Fixnum] a random number
19
+ #
20
+ def rating(options = {})
21
+ rand((options[:min] || 1)..(options[:max] || 5))
22
+ end
23
+
24
+ end
25
+
26
+
@@ -0,0 +1,21 @@
1
+ class Fab
2
+
3
+ # Fab a company name.
4
+ # Delegates to Forgery::Name.company_name.
5
+ #
6
+ # @returns [String] a random company name
7
+ #
8
+ def company_name(options = {})
9
+ Forgery::Name.company_name
10
+ end
11
+
12
+ # Fab a job title.
13
+ # Delegates to Forgery::Name.job_title.
14
+ #
15
+ # @returns [String] a random company name
16
+ #
17
+ def job_title(options = {})
18
+ Forgery::Name.job_title
19
+ end
20
+
21
+ end
@@ -0,0 +1,45 @@
1
+ class Fab
2
+
3
+ # Fab a random date.
4
+ #
5
+ # Options:
6
+ #
7
+ # * min: today - 1000
8
+ # * max: today + 1000
9
+ #
10
+ # @returns [Date] a random date min..max
11
+ #
12
+ def date(options = {})
13
+ rand((options[:min] || Date.today - 1000)..(options[:max] || Date.today + 1000))
14
+ end
15
+
16
+ # Fab a random start date.
17
+ # Delegates to #date.
18
+ #
19
+ # @returns [Date] a random date min..max
20
+ #
21
+ def start_date(options = {})
22
+ date(options)
23
+ end
24
+
25
+ # Fab a random stop date.
26
+ # Delegates to #date.
27
+ #
28
+ # @returns [Date] a random date min..max
29
+ #
30
+ def stop_date(options = {})
31
+ date(options)
32
+ end
33
+
34
+ # Fab a random start date and stop date.
35
+ # The start is less than or equal to the stop.
36
+ # Delegates to #start_date and #stop_date.
37
+ #
38
+ # @returns [Date,Date] a random [start date, stop date] from min..max
39
+ #
40
+ def start_date_and_stop_date(options = {})
41
+ [start_date(options), stop_date(options)].sort
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,44 @@
1
+ class Fab
2
+
3
+ # Fab a random datetime.
4
+ #
5
+ # Options:
6
+ #
7
+ # * min: now - 1000
8
+ # * max: now + 1000
9
+ #
10
+ # @returns [DateTime] a random datetime min..max
11
+ #
12
+ def datetime(options = {})
13
+ rand((options[:min] || DateTime.now - 1000)..(options[:max] || DateTime.now + 1000))
14
+ end
15
+
16
+ # Fab a random start datetime.
17
+ # Delegates to #datetime.
18
+ #
19
+ # @returns [DateTime] a random datetime min..max
20
+ #
21
+ def start_datetime(options = {})
22
+ datetime(options)
23
+ end
24
+
25
+ # Fab a random stop datetime.
26
+ # Delegates to #datetime.
27
+ #
28
+ # @returns [DateTime] a random datetime min..max
29
+ #
30
+ def stop_datetime(options = {})
31
+ datetime(options)
32
+ end
33
+
34
+ # Fab a random start datetime and stop datetime.
35
+ # The start is less than or equal to the stop.
36
+ # Delegates to #start_datetime and #stop_datetime.
37
+ #
38
+ # @returns [DateTime,DateTime] a random [start datetime, stop datetime] from min..max
39
+ #
40
+ def start_datetime_and_stop_datetime(options = {})
41
+ [start_datetime(options), stop_datetime(options)].sort
42
+ end
43
+
44
+ end
@@ -0,0 +1,12 @@
1
+ class Fab
2
+
3
+ # Fab an email address.
4
+ # Delegate to Forgery::Email.address
5
+ #
6
+ # @returns [String] an email address
7
+ #
8
+ def email_address
9
+ Forgery::Email.address
10
+ end
11
+
12
+ end
@@ -0,0 +1,113 @@
1
+ class Fab
2
+
3
+ CHARS = ('a'..'z').to_a
4
+
5
+ # Fab a path e.g. "/mydir1/mydir2/myfile.txt"
6
+ #
7
+ # @returns [String] a path
8
+ #
9
+ def path(options = {})
10
+ (Pathname.new("") + dirname(options) + basename(options)).to_s
11
+ end
12
+
13
+ # Fab a base name e.g. "myfile.txt"
14
+ #
15
+ # The base name has two parts:
16
+ #
17
+ # * The "intension" e.g. "myfile"
18
+ # * The "extension" e.g. "txt"
19
+ #
20
+ # Options:
21
+ #
22
+ # * chars: a..z
23
+ # * intension_length: [sent to #basename_intension as :length]
24
+ # * extension_length: [sent to #basename_extension as :length]
25
+ #
26
+ # @returns [String] a base name
27
+ #
28
+ def basename(options = {})
29
+ intention = basename_intension(options[:intension_length] ? options.merge(length: intension_length) : options)
30
+ extention = basename_extension(options[:extension_length] ? options.merge(length: extension_length) : options)
31
+ "#{basename_intension}.#{basename_extension}"
32
+ end
33
+
34
+ # Fab a file base name intension e.g. "myfile"
35
+ #
36
+ # Options:
37
+ #
38
+ # * chars: a..z
39
+ # * length: rand(1..30)
40
+ #
41
+ # @returns [String] a base name intension
42
+ #
43
+ def basename_intension(options = {})
44
+ (options[:chars] || AZ).sample(options[:size] || rand(1..30)).join
45
+ end
46
+
47
+ # Fab a file base name extension e.g. "txt"
48
+ #
49
+ # Options:
50
+ #
51
+ # * chars: a..z
52
+ # * length: rand(1..5)
53
+ #
54
+ # @returns [String] a base name extension
55
+ #
56
+ def basename_extension(options = {})
57
+ (options[:chars] || AZ).sample(options[:size] || rand(1..5)).join
58
+ end
59
+
60
+ # Fab a directory name e.g. "/mydir1/mydir2".
61
+ # This calls #dirname_part +rand+ times.
62
+ #
63
+ # Options:
64
+ #
65
+ # * parts: rand(2..6) [how many parts to use]
66
+ # * chars: a..z [sent to #dirname_part]
67
+ # * length: 1..20 per part [sent to #dirname_part]
68
+ #
69
+ # @returns [String] a directory name
70
+ #
71
+ def dirname(options = {})
72
+ pathname = Pathname.new("/")
73
+ parts = options[:parts] || rand(2..6)
74
+ parts.times.each{ pathname += dirname_part(options) }
75
+ pathname.to_s
76
+ end
77
+
78
+ # Fab a directory path part e.g. "mydir".
79
+ #
80
+ # Options:
81
+ #
82
+ # * chars: a..z
83
+ # * size: rand(1..20)
84
+ #
85
+ # @returns [String] a directory name part
86
+ #
87
+ def dirname_part(options = {})
88
+ (options[:chars] || AZ).sample(options[:size] || rand(1..20)).join
89
+ end
90
+
91
+ # Fab a file extension.
92
+ # Delegates to #basename_extension.
93
+ #
94
+ # @returns [String] a file extension e.g. "txt"
95
+ #
96
+ # TODO refactor this to streamline it
97
+ #
98
+ def file_extension(options = {})
99
+ basename_extension(options)
100
+ end
101
+
102
+ # Fab a file path.
103
+ # Delegates to #path.
104
+ #
105
+ # @returns [String] a file path e.g. "/mydir1/mydir2/myfile.txt"
106
+ #
107
+ # TODO refactor this to streamline it
108
+ #
109
+ def file_path(options = {})
110
+ path(options)
111
+ end
112
+
113
+ end