faker 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d19e0ae93b8e3a78433a69f98761d341068c3b4
4
+ data.tar.gz: 36db9a564fafae8bc5a93470dbe2204f5fdc63ea
5
+ SHA512:
6
+ metadata.gz: a3e8c0b6aaed5907213c3632fecc7c34d72fb4c38c4c28d67e11c1f2af5c9d205ffd91460ee03b7d8b17b55946394ba4a83b6a219ebdf49251c84608879abcaf
7
+ data.tar.gz: b27e7a2d35c183f968a313de2667850e75aff6f849f6846d48f892767b800a7dc788beceb2e462b3295dcccecf52d400342f75bcadb70429a49b46330ded0a1b
@@ -1,3 +1,6 @@
1
+ == 1.3.0 2014-03-08
2
+ * Many enhancements and few bugfixes
3
+
1
4
  == 1.2.0 2013-07-27
2
5
  * Many major and minor enhancements :)
3
6
 
data/README.md CHANGED
@@ -11,10 +11,10 @@ development.
11
11
  Installing
12
12
  ----------
13
13
  ```bash
14
- sudo gem install faker
14
+ gem install faker
15
15
  ```
16
16
 
17
- Usage
17
+ ##Usage
18
18
  -----
19
19
  ```ruby
20
20
  Faker::Name.name #=> "Christophe Bartell"
@@ -22,6 +22,283 @@ Faker::Name.name #=> "Christophe Bartell"
22
22
  Faker::Internet.email #=> "kirsten.greenholt@corkeryfisher.info"
23
23
  ```
24
24
 
25
+ ###Faker::Address
26
+ -----------------
27
+
28
+ ```ruby
29
+ Faker::Address.city #=> "Imogeneborough"
30
+
31
+ Faker::Address.street_name #=> "Larkin Fork"
32
+
33
+ Faker::Address.street_address #=> "282 Kevin Brook"
34
+
35
+ Faker::Address.secondary_address #=> "Apt. 672"
36
+
37
+ Faker::Address.building_number #=> "7304"
38
+
39
+ Faker::Address.zip_code #=> "58517"
40
+
41
+ Faker::Address.zip #=> "58517"
42
+
43
+ Faker::Address.postcode #=> "58517"
44
+
45
+ Faker::Address.time_zone #=> "Asia/Yakutsk"
46
+
47
+ Faker::Address.street_suffix #=> "Street"
48
+
49
+ Faker::Address.city_suffix #=> "fort"
50
+
51
+ Faker::Address.city_prefix #=> "Lake"
52
+
53
+ Faker::Address.state_abbr #=> "AP"
54
+
55
+ Faker::Address.state #=> "California"
56
+
57
+ Faker::Address.country #=> "French Guiana"
58
+
59
+ Faker::Address.latitude #=> "-58.17256227443719"
60
+
61
+ Faker::Address.longitude #=> "-156.65548382095133"
62
+
63
+
64
+ ```
65
+
66
+ ###Faker::Bitcoin
67
+ -----------------
68
+
69
+ ```ruby
70
+
71
+ Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"
72
+
73
+ ```
74
+
75
+ ###Faker::Business
76
+ ------------------
77
+
78
+ ```ruby
79
+
80
+ Faker::Business.credit_card_number #=> "1228-1221-1221-1431"
81
+
82
+ Faker::Business.credit_card_expiry_date #=> <Date: 2015-11-11 ((2457338j,0s,0n),+0s,2299161j)>
83
+
84
+ Faker::Business.credit_card_type #=> "visa"
85
+
86
+ ```
87
+
88
+ ###Faker::Code
89
+ --------------
90
+
91
+ ```ruby
92
+
93
+ Faker::Code.isbn #=> "759021701-8"
94
+
95
+ ```
96
+
97
+ ###Faker::Commerce
98
+ ------------------
99
+
100
+ ```ruby
101
+
102
+ Faker::Commerce.color #=> "lavender"
103
+
104
+ Faker::Commerce.department #=> "Grocery, Health & Beauty"
105
+
106
+ Faker::Commerce.product_name #=> "Practical Granite Shirt"
107
+
108
+ ```
109
+
110
+ ###Faker::Company
111
+ -----------------
112
+
113
+ ```ruby
114
+
115
+ Faker::Company.name #=> "Hirthe-Ritchie"
116
+
117
+ Faker::Company.suffix #=> "Group"
118
+
119
+ # Generate a buzzword-laden catch phrase.
120
+ Faker::Company.catch_phrase #=> "Business-focused coherent parallelism"
121
+
122
+ # When a straight answer won't do, BS to the rescue!
123
+ Faker::Company.bs #=> "empower one-to-one web-readiness"
124
+
125
+ Faker::Company.duns_number #=> "08-341-3736"
126
+
127
+ ```
128
+
129
+
130
+ ###Faker::Internet
131
+ ---------------
132
+
133
+ ```ruby
134
+ # Optional argument name=nil
135
+ Faker::Internet.email #=> "eliza@mann.net"
136
+
137
+ Faker::Internet.email('Nancy') #=> "nancy@terry.biz"
138
+
139
+ # Optional argument name=nil
140
+ Faker::Internet.free_email #=> "freddy@gmail.com"
141
+
142
+ Faker::Internet.free_email('Nancy') #=> "nancy@yahoo.com"
143
+
144
+ # Optional argument name=nil
145
+ Faker::Internet.safe_email #=> "christelle@example.org"
146
+
147
+ Faker::Internet.safe_email('Nancy') #=> "nancy@example.net"
148
+
149
+ # Optional arguments specifier=nil, separators=%w(. _)
150
+ Faker::Internet.user_name #=> "alexie"
151
+
152
+ Faker::Internet.user_name('Nancy') #=> "nancy"
153
+
154
+ Faker::Internet.user_name('Nancy Johnson', %w(. _ -)) #=> "johnson-nancy"
155
+
156
+ # Optional argument min_length=0
157
+ Faker::Internet.password #=> "doloremquealiquidrerum"
158
+
159
+ Faker::Internet.password(8) #=> "consecteturadasperiores"
160
+
161
+ Faker::Internet.domain_name #=> "effertz.info"
162
+
163
+ Faker::Internet.fix_umlauts('äöüß') #=> "aeoeuess"
164
+
165
+ Faker::Internet.domain_word #=> "haleyziemann"
166
+
167
+ Faker::Internet.domain_suffix #=> "info"
168
+
169
+ Faker::Internet.ip_v4_address #=> "24.29.18.175"
170
+
171
+ Faker::Internet.ip_v6_address #=> "ac5f:d696:3807:1d72:2eb5:4e81:7d2b:e1df"
172
+
173
+ # Optional arguments: host=domain_name, path="/#{user_name}"
174
+ Faker::Internet.url #=> "http://thiel.com/chauncey_simonis"
175
+ Faker::Internet.url('example.com') #=> "http://example.com/clotilde.swift"
176
+ Faker::Internet.url('example.com', '/foobar.html') #=> "http://example.com/foobar.html"
177
+
178
+ # Optional arguments: words=nil, glue=nil
179
+ Faker::Internet.slug #=> "pariatur_laudantium"
180
+ Faker::Internet.slug('foo bar') #=> "foo.bar"
181
+ Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
182
+
183
+
184
+ ```
185
+
186
+ ###Faker::Lorem
187
+ ---------------
188
+
189
+ ```ruby
190
+
191
+ Faker::Lorem.word #=> "repellendus"
192
+
193
+ # Optional arguments: num=3, supplemental=false
194
+ Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
195
+ Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
196
+ Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]
197
+
198
+ # Optional arguments: char_count=255
199
+ Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
200
+ Faker::Lorem.characters(10) #=> "ang9cbhoa8"
201
+
202
+ # Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
203
+ Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
204
+ Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
205
+ Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
206
+ Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
207
+ Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."
208
+
209
+ # Optional arguments: sentence_count=3, supplemental=false
210
+ Faker::Lorem.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."]
211
+ Faker::Lorem.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."]
212
+ Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et ipsum."]
213
+
214
+ # Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
215
+ Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente."
216
+ Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum."
217
+ Faker::Lorem.paragraph(2, true) #=> ""
218
+ Faker::Lorem.paragraph(2, false, 4) #=> ""
219
+ Faker::Lorem.paragraph(2, true, 4) #=> ""
220
+
221
+ # Optional arguments: paragraph_count=3, supplemental=false
222
+ Faker::Lorem.paragraphs #=> ""
223
+ Faker::Lorem.paragraphs(1) #=> ""
224
+ Faker::Lorem.paragraphs(1, true) #=> ""
225
+
226
+ ```
227
+
228
+ ###Faker::Name
229
+ --------------
230
+
231
+ ```ruby
232
+
233
+ Faker::Name.name #=> "Tyshawn Johns Sr."
234
+
235
+ Faker::Name.first_name #=> "Kaci"
236
+
237
+ Faker::Name.last_name #=> "Ernser"
238
+
239
+ Faker::Name.prefix #=> "Mr."
240
+
241
+ Faker::Name.suffix #=> "IV"
242
+
243
+ Faker::Name.title #=> "Legacy Creative Director"
244
+
245
+ ```
246
+
247
+ ###Faker::Number
248
+ ----------------
249
+
250
+ ```ruby
251
+
252
+ # Required parameter: digits
253
+ Faker::Number.number(10) #=> "1968353479"
254
+
255
+ Faker::Number.digit #=> "1"
256
+
257
+ ```
258
+
259
+ ###Faker::PhoneNumber
260
+ ---------------------
261
+
262
+ Phone numbers may be in any of the following formats:
263
+
264
+ * 333-333-3333
265
+ * (333) 333-3333
266
+ * 1-333-333-3333
267
+ * 333.333.3333
268
+ * 333-333-3333
269
+ * 333-333-3333 x3333
270
+ * (333) 333-3333 x3333
271
+ * 1-333-333-3333 x3333
272
+ * 333.333.3333 x3333
273
+
274
+ (Don't let the example output below fool you - any format can be returned at random.)
275
+
276
+ ```ruby
277
+
278
+ Faker::PhoneNumber.phone_number #=> "397.693.1309"
279
+
280
+ Faker::PhoneNumber.cell_phone #=> "(186)285-7925"
281
+
282
+ # NOTE NOTE NOTE NOTE
283
+ # For the 'US only' methods below, first you must do the following:
284
+ Faker::Config.locale = 'en-us'
285
+
286
+ # US only
287
+ Faker::PhoneNumber.area_code #=> "201"
288
+
289
+ # US only
290
+ Faker::PhoneNumber.exchange_code #=> "208"
291
+
292
+ # Optional parameter: length=4
293
+ Faker::PhoneNumber.subscriber_number #=> "3873"
294
+
295
+ Faker::PhoneNumber.subscriber_number(2) #=> "39"
296
+
297
+ Faker::PhoneNumber.extension #=> "3764"
298
+
299
+ ```
300
+
301
+
25
302
  Customization
26
303
  ------------
27
304
  Since you may want to make addresses and other types of data look different
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  mydir = File.expand_path(File.dirname(__FILE__))
2
3
 
3
4
  begin
@@ -91,14 +92,18 @@ module Faker
91
92
  # into method calls that can be used to generate a
92
93
  # formatted translation: e.g., "#{first_name} #{last_name}".
93
94
  def parse(key)
94
- fetch(key).scan(/#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|kls, meth, etc|
95
+ fetch(key).scan(/(\(?)#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|prefix, kls, meth, etc|
95
96
  # If the token had a class Prefix (e.g., Name.first_name)
96
97
  # grab the constant, otherwise use self
97
98
  cls = kls ? Faker.const_get(kls.chop) : self
98
99
 
100
+ # If an optional leading parentheses is not present, prefix.should == "", otherwise prefix.should == "("
101
+ # In either case the information will be retained for reconstruction of the string.
102
+ text = prefix
103
+
99
104
  # If the class has the method, call it, otherwise
100
105
  # fetch the transation (i.e., faker.name.first_name)
101
- text = cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}")
106
+ text += cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}")
102
107
 
103
108
  # And tack on spaces, commas, etc. left over in the string
104
109
  text += etc.to_s
@@ -146,14 +151,18 @@ end
146
151
  require 'faker/address'
147
152
  require 'faker/code'
148
153
  require 'faker/company'
154
+ require 'faker/finance'
149
155
  require 'faker/internet'
150
156
  require 'faker/lorem'
151
157
  require 'faker/name'
158
+ require 'faker/team'
152
159
  require 'faker/phone_number'
153
160
  require 'faker/business'
154
161
  require 'faker/commerce'
155
162
  require 'faker/version'
156
163
  require 'faker/number'
164
+ require 'faker/bitcoin'
165
+ require 'faker/avatar'
157
166
 
158
167
  require 'extensions/array'
159
168
  require 'extensions/symbol'
@@ -0,0 +1,10 @@
1
+ module Faker
2
+ class Avatar < Base
3
+ class << self
4
+ def image(slug=nil)
5
+ slug ||= Faker::Lorem.words
6
+ "http://robohash.org/#{slug}"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,36 @@
1
+ require 'digest'
2
+
3
+ module Faker
4
+ class Bitcoin < Base
5
+ class << self
6
+
7
+ def address
8
+ hash = rand(2**160).to_s(16)
9
+ version = 0
10
+ packed = version.chr + [hash].pack("H*")
11
+ checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
12
+ base58(packed + checksum)
13
+ end
14
+
15
+ protected
16
+
17
+ def base58(str)
18
+ alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
19
+ base = alphabet.size
20
+
21
+ lv = 0
22
+ str.split('').reverse.each_with_index { |v,i| lv += v.unpack('C')[0] * 256**i }
23
+
24
+ ret = ''
25
+ while lv > 0 do
26
+ lv, mod = lv.divmod(base)
27
+ ret << alphabet[mod]
28
+ end
29
+
30
+ npad = str.match(/^#{0.chr}*/)[0].to_s.size
31
+ '1'*npad + ret.reverse
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -13,6 +13,11 @@ module Faker
13
13
  def product_name
14
14
  fetch('commerce.product_name.adjective') + ' ' + fetch('commerce.product_name.material') + ' ' + fetch('commerce.product_name.product')
15
15
  end
16
+
17
+ def price
18
+ random = Random.new
19
+ (random.rand(0..100.0) * 100).floor/100.0
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -6,16 +6,16 @@ module Faker
6
6
  def name
7
7
  parse('company.name')
8
8
  end
9
-
9
+
10
10
  def suffix
11
11
  fetch('company.suffix')
12
12
  end
13
-
13
+
14
14
  # Generate a buzzword-laden catch phrase.
15
15
  def catch_phrase
16
16
  translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
17
17
  end
18
-
18
+
19
19
  # When a straight answer won't do, BS to the rescue!
20
20
  def bs
21
21
  translate('faker.company.bs').collect {|list| list.sample }.join(' ')
@@ -25,6 +25,6 @@ module Faker
25
25
  ('%09d' % rand(10 ** 9)).gsub(/(\d\d)(\d\d\d)(\d\d\d\d)/, '\\1-\\2-\\3')
26
26
  end
27
27
  end
28
-
28
+
29
29
  end
30
30
  end
@@ -0,0 +1,26 @@
1
+ module Faker
2
+ class Finance < Base
3
+ CREDIT_CARD_TYPES = [ :visa, :mastercard, :discover, :american_express, :diners_club, :jcb, :switch, :solo, :dankort, :maestro, :forbrugsforeningen, :laser ]
4
+
5
+ class << self
6
+ def credit_card(*types)
7
+ types = CREDIT_CARD_TYPES if types.empty?
8
+ type = types.sample
9
+ template = numerify(fetch("credit_card.#{type}"))
10
+
11
+ # calculate the luhn checksum digit
12
+ multiplier = 1
13
+ luhn_sum = template.gsub(/[^0-9]/, '').split('').reverse.map(&:to_i).inject(0) do |sum, digit|
14
+ multiplier = (multiplier == 2 ? 1 : 2)
15
+ sum + (digit * multiplier).to_s.split('').map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
16
+ end
17
+ # the sum plus whatever the last digit is must be a multiple of 10. So, the
18
+ # last digit must be 10 - the last digit of the sum.
19
+ luhn_digit = (10 - (luhn_sum % 10)) % 10
20
+
21
+ template.gsub! 'L', luhn_digit.to_s
22
+ template
23
+ end
24
+ end
25
+ end
26
+ end