sixarm_ruby_fab 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,56 @@
1
+ require 'forgery'
2
+
3
+ # Generates random geographic information.
4
+ class Forgery::Geo < Forgery
5
+
6
+ # Return a latitude in the range -90.0 to +90.0 as a float.
7
+ def self.latitude
8
+ rand * 180.0 - 90.0
9
+ end
10
+
11
+ # Return a latitude's degrees component in the range -180 to +180 as an integer.
12
+ def self.latitude_degrees
13
+ rand(360)-180
14
+ end
15
+
16
+ # Return a latitude's minutes component in the range 0 to 60 as an integer.
17
+ def self.latitude_minutes
18
+ rand(60)
19
+ end
20
+
21
+ # Return a latitude's seconds component in the range 0 to 60 as an integer.
22
+ def self.latitude_seconds
23
+ rand(60)
24
+ end
25
+
26
+ # Return a latitude's direction component, either "N" (north) or "S" (south)
27
+ def self.latitude_direction
28
+ ['N','S'].sample
29
+ end
30
+
31
+ # Return a longitude in the range -180.0 to +180.0 as a float.
32
+ def self.longitude
33
+ rand * 360.0 - 180.0
34
+ end
35
+
36
+ # Return a longitude's degrees component in the range -180 to +180 as an integer.
37
+ def self.longitude_degrees
38
+ rand(360)-180
39
+ end
40
+
41
+ # Return a longitude's minutes component in the range 0 to 60 as an integer.
42
+ def self.longitude_minutes
43
+ rand(60)
44
+ end
45
+
46
+ # Return a longitude's seconds component in the range 0 to 60 as an integer.
47
+ def self.longitude_seconds
48
+ rand(60)
49
+ end
50
+
51
+ # Return a longitude's direction component, either "E" (east) or "W" (west)
52
+ def self.longitude_direction
53
+ ["E","W"].sample
54
+ end
55
+
56
+ end
@@ -0,0 +1,12 @@
1
+ require 'forgery'
2
+ # Generates random Interet URI information.
3
+ class Forgery::Internet < Forgery
4
+
5
+ # Return a latitude in the range -90.0 to +90.0 as a float.
6
+ def self.uri
7
+ ext = ['com','net','org','edu','gov','mil','au','br','cn','in','it','mx','jp','com.uk','com.au','com.ca'].sample
8
+ host = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'].sample(rand(5)+15).join
9
+ return "http://#{host}.#{ext}"
10
+ end
11
+
12
+ end
@@ -0,0 +1,21 @@
1
+ class Fab
2
+
3
+ # Fab a random latitude.
4
+ # Delegate to Forgery::Geo.latitude.
5
+ #
6
+ # @returns [Float] a random latitude
7
+ #
8
+ def latitude
9
+ Forgery::Geo.latitude
10
+ end
11
+
12
+ # Fab a random longitude.
13
+ # Delegate to Forgery::Geo.longitude.
14
+ #
15
+ # @returns [Float] a random longitude
16
+ #
17
+ def longitude
18
+ Forgery::Geo.longitude
19
+ end
20
+
21
+ end
@@ -0,0 +1,28 @@
1
+ class Fab
2
+
3
+ # Fab a random id.
4
+ #
5
+ # Options:
6
+ #
7
+ # * min: 1
8
+ # * max: 30000
9
+ #
10
+ # @returns [Fixnum] a random id
11
+ #
12
+ def id(options = {})
13
+ rand((options[:min] || 1)..(options[:max] || 30000))
14
+ end
15
+
16
+ # Fab a list of random ids.
17
+ #
18
+ # Options:
19
+ #
20
+ # * size: 3
21
+ #
22
+ # @returns [Array[Fixnum]] a list of random ids
23
+ #
24
+ def ids(options = {})
25
+ (options[:size] || 3).times.map{ id(options) }
26
+ end
27
+
28
+ end
@@ -0,0 +1,12 @@
1
+ class Fab
2
+
3
+ # Fab a random URI.
4
+ # Delegates to Forgery::Internet.uri.
5
+ #
6
+ # @returns [String] a URI
7
+ #
8
+ def uri
9
+ Forgery::Internet.uri
10
+ end
11
+
12
+ end
@@ -0,0 +1,34 @@
1
+ class Fab
2
+
3
+ LANGUAGE_CODE_ISO6391_LIST = [
4
+ 'en', # English
5
+ 'fr', # French
6
+ 'de', # German
7
+ 'ja', # Japanese
8
+ ]
9
+
10
+ attr_accessor :language_code_iso6391_list
11
+
12
+ # Fab a language code e.g. "en" for English.
13
+ # Delegates to #language_code_iso6391
14
+ #
15
+ # @returns [String] a random language code
16
+ #
17
+ def language_code(options = {})
18
+ language_code_iso6391(options)
19
+ end
20
+
21
+ # Fab a language code e.g. "en" for English.
22
+ # Samples from LANGUAGE_CODE_ISO6391_LIST.
23
+ #
24
+ # @returns [String] a random language code
25
+ #
26
+ def language_code_iso6391(options = {})
27
+ LANGUAGE_CODE_ISO6391_LIST.sample
28
+ end
29
+
30
+ def language_code_iso6391_list
31
+ @language_code_iso6391_list ||= LANGUAGE_CODE_ISO6391_LIST
32
+ end
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ class Fab
2
+
3
+ # Fab a random content type part e.g. "image/jpeg".
4
+ #
5
+ # Options:
6
+ #
7
+ # * chars: a..z
8
+ # * size: rand(1..20) [per part]
9
+ #
10
+ # @returns [String] a content type
11
+ #
12
+ def content_type(options = {})
13
+ "#{content_type_part(options)}/#{content_type_part(options)}"
14
+ end
15
+
16
+ # Fab a random content type part e.g. "image".
17
+ #
18
+ # Options:
19
+ #
20
+ # * chars: a..z
21
+ # * size: rand(1..20)
22
+ #
23
+ # @returns [String] a content type part
24
+ #
25
+ def content_type_part(options = {})
26
+ (options[:chars] || AZ).sample(options[:size] || rand(1..20)).join
27
+ end
28
+
29
+ end
@@ -0,0 +1,30 @@
1
+ class Fab
2
+
3
+ # Fab a random given name.
4
+ # Delegates to Forgery::Name.first_name
5
+ #
6
+ # @returns [String] a random given name
7
+ #
8
+ def given_name
9
+ Forgery::Name.first_name
10
+ end
11
+
12
+ # Fab a random middle name.
13
+ # Delegates to Forgery::Name.first_name
14
+ #
15
+ # @returns [String] a random middle name
16
+ #
17
+ def middle_name
18
+ Forgery::Name.first_name
19
+ end
20
+
21
+ # Fab a random last name.
22
+ # Delegates to Forgery::Name.last_name
23
+ #
24
+ # @returns [String] a random last name
25
+ #
26
+ def family_name
27
+ Forgery::Name.last_name
28
+ end
29
+
30
+ end
@@ -0,0 +1,16 @@
1
+ class Fab
2
+
3
+ # Fab a random password.
4
+ #
5
+ # Options:
6
+ #
7
+ # * chars: a..z
8
+ # * size: rand(9..40)
9
+ #
10
+ # @returns [String] a random password
11
+ #
12
+ def password(options = {})
13
+ (options[:chars] || AZ).sample(options[:size] || rand(9..40)).join
14
+ end
15
+
16
+ end
@@ -0,0 +1,12 @@
1
+ class Fab
2
+
3
+ # Fab a random phone number string.
4
+ # Delegates to Forgery::Address.phone.
5
+ #
6
+ # @returns [String] a random phone number string
7
+ #
8
+ def phone(options = {})
9
+ Forgery::Address.phone
10
+ end
11
+
12
+ end
@@ -0,0 +1,39 @@
1
+ class Fab
2
+
3
+ # Fab a random street address.
4
+ # Delegates to Forgery::Address.street_address.
5
+ #
6
+ # @returns [String] a random street address
7
+ #
8
+ def street_address
9
+ Forgery::Address.street_address
10
+ end
11
+
12
+ # Fab a random city string.
13
+ # Delegates to Forgery::Address.city
14
+ #
15
+ # @returns [String] a random city
16
+ #
17
+ def city
18
+ Forgery::Address.city
19
+ end
20
+
21
+ # Fab a random US state abbreviation.
22
+ # Delegates to Forgery::Address.state_abbrev.
23
+ #
24
+ # @returns [String] a random US state abbreviation
25
+ #
26
+ def usstate
27
+ Forgery::Address.state_abbrev
28
+ end
29
+
30
+ # Fab a random US zip code.
31
+ # Delegates to Forgery::Address.zip.
32
+ #
33
+ # @returns [String] a random US zip code
34
+ #
35
+ def uszip
36
+ Forgery::Address.zip
37
+ end
38
+
39
+ end
@@ -0,0 +1,58 @@
1
+ class Fab
2
+
3
+ NAME_CHARS = "aabcdeeefghiijklmnoopqrrssttuuvwxyz".split(//)
4
+ NOTE_CHARS = "aabcdeeefghiijklmnoopqrrssttuuvwxyz ..,,;;-+'*".split(//)
5
+
6
+ # Fab a random name.
7
+ #
8
+ # Options:
9
+ #
10
+ # * chars: NAME_CHARS
11
+ # * size: rand(10..30) [actual size may be less because we strip the string]
12
+ #
13
+ # @returns [String] a random name
14
+ #
15
+ def name(options = {})
16
+ (options[:chars] || NAME_CHARS).sample(options[:size] || rand(10..30)).join.strip
17
+ end
18
+
19
+ # Fab a random note.
20
+ #
21
+ # Options:
22
+ #
23
+ # * chars: NOTE_CHARS
24
+ # * size: rand(1..200) [actual size may be less because we strip the string]
25
+ #
26
+ # @returns [String] a random name
27
+ #
28
+ def note(options = {})
29
+ (options[:chars] || NOTE_CHARS).sample(options[:size] || rand(1..200)).join.strip
30
+ end
31
+
32
+ # Fab a random note.
33
+ #
34
+ # Options:
35
+ #
36
+ # * chars: NOTE_CHARS
37
+ # * size: rand(20..200) [actual size may be less because we strip the string]
38
+ #
39
+ # @returns [String] a random description
40
+ #
41
+ def description(options = {})
42
+ (options[:chars] || NOTE_CHARS).sample(options[:size] || rand(20..200)).join.strip
43
+ end
44
+
45
+ # Fab a random lorem ipsum string.
46
+ #
47
+ # Options:
48
+ #
49
+ # * chars: NOTE_CHARS
50
+ # * size: rand(20..200) [actual size may be less because we strip the string]
51
+ #
52
+ # @returns [String] a random description
53
+ #
54
+ def lorem(options = {})
55
+ (options[:chars] || NOTE_CHARS).sample(options[:size] || rand(20..200)).join.strip
56
+ end
57
+
58
+ end
@@ -0,0 +1,44 @@
1
+ class Fab
2
+
3
+ # Fab a random time.
4
+ #
5
+ # Options:
6
+ #
7
+ # * min: now - 1000
8
+ # * max: now + 1000
9
+ #
10
+ # @returns [Time] a random time min..max
11
+ #
12
+ def time(options = {})
13
+ rand((options[:min] || Time.now - 1000)..(options[:max] || Time.now + 1000))
14
+ end
15
+
16
+ # Fab a random start time.
17
+ # Delegates to #time.
18
+ #
19
+ # @returns [Time] a random time min..max
20
+ #
21
+ def start_time(options = {})
22
+ time(options)
23
+ end
24
+
25
+ # Fab a random stop time.
26
+ # Delegates to #time.
27
+ #
28
+ # @returns [Time] a random time min..max
29
+ #
30
+ def stop_time(options = {})
31
+ time(options)
32
+ end
33
+
34
+ # Fab a random start time and stop time.
35
+ # The start is less than or equal to the stop.
36
+ # Delegates to #start_time and #stop_time.
37
+ #
38
+ # @returns [Time,Time] a random [start time, stop time] from min..max
39
+ #
40
+ def start_time_and_stop_time(options = {})
41
+ [start_time(options), stop_time(options)].sort
42
+ end
43
+
44
+ end
@@ -0,0 +1,119 @@
1
+ class Fab
2
+
3
+ # Fab a Twitter screen name.
4
+ # This delegates to Fab.username.
5
+ #
6
+ # Options:
7
+ #
8
+ # * none
9
+ #
10
+ # @return [Fixnum] a screen name
11
+ #
12
+ def twitter_screen_name(options = {})
13
+ username(options)
14
+ end
15
+
16
+ # Fab a Twitter user id.
17
+ #
18
+ # Options:
19
+ #
20
+ # * min
21
+ # * max
22
+ #
23
+ # @return [Fixnum] a user id
24
+ #
25
+ def twitter_user_id(options = {})
26
+ rand((options[:min] || 10000000)..(options[:max] || 100000000))
27
+ end
28
+
29
+ # Fab a Twitter user hash.
30
+ #
31
+ # Options:
32
+ #
33
+ # * any; merge this hash into the user hash.
34
+ #
35
+ # @return [Hash] a Twitter user hash
36
+ #
37
+ def twitter_user_hash(options = {})
38
+ id = options[:id] || options["id"] || twitter_user_id
39
+ {
40
+ "id" => id.to_i,
41
+ "id_str" => id.to_s
42
+ }.merge(options)
43
+ end
44
+
45
+ # Fab a Twitter retweet count.
46
+ #
47
+ # Options:
48
+ #
49
+ # * min: 0
50
+ # * max: 999
51
+ #
52
+ # @return [Fixnum] a retweet count
53
+ #
54
+ def twitter_retweet_count(options = {})
55
+ rand((options[:min] || 0)..(options[:max] || 999))
56
+ end
57
+
58
+ # Fab a Twitter favorite count.
59
+ #
60
+ # Options:
61
+ #
62
+ # * min: 0
63
+ # * max: 999
64
+ #
65
+ # @return [Fixnum] a favorite count
66
+ #
67
+ def twitter_favorite_count(options = {})
68
+ rand((options[:min] || 0)..(options[:max] || 999))
69
+ end
70
+
71
+ # Fab a Twitter tweet id.
72
+ #
73
+ # Options:
74
+ #
75
+ # * min: 1000000000
76
+ # * max: 9000000000
77
+ #
78
+ # @return [Fixnum] a tweet id
79
+ #
80
+ def twitter_tweet_id(options = {})
81
+ rand((options[:min] || 1000000000)..(options[:max] || 9000000000))
82
+ end
83
+
84
+ # Fab a Twitter tweet hash.
85
+ #
86
+ # Options:
87
+ #
88
+ # * any; merge this hash into the tweet hash.
89
+ #
90
+ # @return [Hash] a tweet hash
91
+ #
92
+ def twitter_tweet_hash(options={})
93
+ id = options[:id] || options["id"] || Fab.twitter_tweet_id
94
+ {
95
+ "created_at" => Fab.time.httpdate,
96
+ "id" => id.to_i,
97
+ "id_str" => id.to_s,
98
+ "text" => Fab.lorem,
99
+ "source" => "web",
100
+ "truncated" => false,
101
+ "in_reply_to_status_id" => nil,
102
+ "in_reply_to_status_id_str" => nil,
103
+ "in_reply_to_user_id" => nil,
104
+ "in_reply_to_user_id_str" => nil,
105
+ "in_reply_to_screen_name" => nil,
106
+ "user" => Fab.twitter_user_hash,
107
+ "geo" => nil,
108
+ "coordinates" => nil,
109
+ "place" => nil,
110
+ "contributors" => nil,
111
+ "retweet_count" => Fab.twitter_retweet_count,
112
+ "favorite_count" => Fab.twitter_favorite_count,
113
+ "favorited" => Fab.boolean,
114
+ "retweeted" => Fab.boolean,
115
+ "lang" => Fab.language_code
116
+ }.merge(options)
117
+ end
118
+
119
+ end