faker 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +13 -0
  3. data/README.md +167 -11
  4. data/lib/faker.rb +6 -0
  5. data/lib/faker/avatar.rb +2 -2
  6. data/lib/faker/bitcoin.rb +17 -5
  7. data/lib/faker/book.rb +19 -0
  8. data/lib/faker/business.rb +1 -1
  9. data/lib/faker/code.rb +7 -0
  10. data/lib/faker/color.rb +49 -0
  11. data/lib/faker/commerce.rb +5 -1
  12. data/lib/faker/company.rb +42 -4
  13. data/lib/faker/internet.rb +18 -19
  14. data/lib/faker/slack_emoji.rb +43 -0
  15. data/lib/faker/team.rb +1 -1
  16. data/lib/faker/university.rb +20 -0
  17. data/lib/faker/version.rb +1 -1
  18. data/lib/helpers/char.rb +44 -0
  19. data/lib/locales/en-AU.yml +2 -0
  20. data/lib/locales/en-CA.yml +2 -2
  21. data/lib/locales/en-UG.yml +128 -0
  22. data/lib/locales/en-US.yml +1 -1
  23. data/lib/locales/en.yml +43 -9
  24. data/lib/locales/nb-NO.yml +1 -1
  25. data/lib/locales/nl.yml +15 -15
  26. data/lib/locales/pl.yml +2 -2
  27. data/lib/locales/ru.yml +4 -4
  28. data/lib/locales/sk.yml +1 -1
  29. data/lib/locales/sv.yml +4 -4
  30. data/lib/locales/uk.yml +75 -0
  31. data/lib/locales/zh-CN.yml +5 -5
  32. data/lib/locales/zh-TW.yml +27 -0
  33. data/test/test_avatar.rb +4 -1
  34. data/test/test_en_ca_locale.rb +18 -0
  35. data/test/test_en_ug_locale.rb +23 -0
  36. data/test/test_faker_bitcoin.rb +5 -0
  37. data/test/test_faker_book.rb +20 -0
  38. data/test/test_faker_business.rb +11 -10
  39. data/test/test_faker_code.rb +4 -0
  40. data/test/test_faker_color.rb +46 -0
  41. data/test/test_faker_commerce.rb +4 -0
  42. data/test/test_faker_company.rb +12 -1
  43. data/test/test_faker_internet.rb +4 -0
  44. data/test/test_faker_slack_emoji.rb +45 -0
  45. data/test/test_faker_team.rb +12 -0
  46. data/test/test_faker_time.rb +1 -1
  47. data/test/test_faker_university.rb +20 -0
  48. data/test/test_uk_locale.rb +44 -0
  49. metadata +26 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d9ae16e743b75883bfa74a32a7bf9e8d61003bb
4
- data.tar.gz: 14f3e9cf81df8486916540f7e87f4adb7c4510d1
3
+ metadata.gz: c6c36a94960622277ebd5a4297ec2433f7e5fe2b
4
+ data.tar.gz: ca8eee943c3f67e2201c695ac8f9e73d6129c913
5
5
  SHA512:
6
- metadata.gz: c2c98f8d6edc8c068b9671cdb1426b51e194e8e1f9648e4c0c1a62ece721457e0d53fefc449fa5006a8dc52985e6ae42c0f0318811190b0e1e5d1719d64d3fc2
7
- data.tar.gz: c8fd7c213d18954544d406d733c3c4304cbce9d9998dfe34f09d987e46b42682259ef20da2284f015fd53bfa54d9e18591240793b32ccdbc685776250b2e8aed
6
+ metadata.gz: bf565c6375b6e3dab4c7e6598f618c2bb2930d8d8bc70bb9202f886d65b9b5f9f4430ffc3554fc13e99a0739a9af4893eabbb452f9f7fbc0c7649f9f3a6bdcf7
7
+ data.tar.gz: 09a408f05ef48d4aa320cb1c4a75ddf2f6d3da570430e81abb3cd888d5f27b3909e285654dbb458f64e03e3b2527b5790b6d9fbef6724978bfc41bb1c7c1e4a7
@@ -1,3 +1,16 @@
1
+ == 1.5.0 2015-08-17
2
+ * Added logos
3
+ * Added Slack Emoji
4
+ * Updated image generators
5
+ * Updated Dutch Locale
6
+ * Added support for generating RGB values, HSL colors, alpha channel, and HSLA colors
7
+ * Added locale for Uganda
8
+ * Added basic Ukrainian support
9
+ * Added university name generator
10
+ * Updated documentation
11
+ * Updated a variety of locales
12
+ * Various fixes
13
+
1
14
  == 1.4.3 2014-08-15
2
15
  * Updated Russian locale
3
16
  * Added EIN generator
data/README.md CHANGED
@@ -8,6 +8,8 @@ for the creation of this gem), having real-looking test data, and having your
8
8
  database populated with more than one or two records while you're doing
9
9
  development.
10
10
 
11
+ NOTE: While Faker generates data at random, returned values are not guaranteed to be unique.
12
+
11
13
  Installing
12
14
  ----------
13
15
  ```bash
@@ -50,12 +52,14 @@ Faker::Address.city_suffix #=> "fort"
50
52
 
51
53
  Faker::Address.city_prefix #=> "Lake"
52
54
 
53
- Faker::Address.state_abbr #=> "AP"
54
-
55
55
  Faker::Address.state #=> "California"
56
56
 
57
+ Faker::Address.state_abbr #=> "AP"
58
+
57
59
  Faker::Address.country #=> "French Guiana"
58
60
 
61
+ Faker::Address.country_code #=> "IT"
62
+
59
63
  Faker::Address.latitude #=> "-58.17256227443719"
60
64
 
61
65
  Faker::Address.longitude #=> "-156.65548382095133"
@@ -69,6 +73,7 @@ Faker::Address.longitude #=> "-156.65548382095133"
69
73
  ```ruby
70
74
 
71
75
  Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"
76
+ Faker::Bitcoin.testnet_address #=> ""msHGunDvoEwmVFXvd2Bub1SNw5RP1YHJaf""
72
77
 
73
78
  ```
74
79
 
@@ -126,6 +131,8 @@ Faker::Company.suffix #=> "Group"
126
131
  # Generate a buzzword-laden catch phrase.
127
132
  Faker::Company.catch_phrase #=> "Business-focused coherent parallelism"
128
133
 
134
+ Faker::Company.buzzword #=> "Business-focused"
135
+
129
136
  # When a straight answer won't do, BS to the rescue!
130
137
  Faker::Company.bs #=> "empower one-to-one web-readiness"
131
138
 
@@ -133,11 +140,26 @@ Faker::Company.ein #=> "34-8488813"
133
140
 
134
141
  Faker::Company.duns_number #=> "08-341-3736"
135
142
 
136
- # Get a random company logo url in GIF format.
137
- Faker::Company.logo #=> "http://www.biz-logo.com/examples/007.gif"
143
+ # Get a random company logo url in PNG format.
144
+ Faker::Company.logo #=> "http://pigment.github.com/fake-logos/logos/medium/color/5.png"
145
+
146
+ Faker::Company.swedish_organisation_number #=> "7718797652"
138
147
 
139
148
  ```
140
149
 
150
+ ###Faker::Date
151
+ ---------------------
152
+
153
+ ```ruby
154
+ # Random date between dates
155
+ Faker::Date.between(2.days.ago, Date.today) #=> "Wed, 24 Sep 2014"
156
+
157
+ # Random date in the future (up to maximum of N days)
158
+ Faker::Date.forward(23) # => "Fri, 03 Oct 2014"
159
+
160
+ # Random date in the past (up to maximum of N days)
161
+ Faker::Date.backward(14) #=> "Fri, 19 Sep 2014"
162
+ ```
141
163
 
142
164
  ###Faker::Internet
143
165
  ---------------
@@ -232,14 +254,14 @@ Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et
232
254
  # Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
233
255
  Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente."
234
256
  Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum."
235
- Faker::Lorem.paragraph(2, true) #=> ""
236
- Faker::Lorem.paragraph(2, false, 4) #=> ""
237
- Faker::Lorem.paragraph(2, true, 4) #=> ""
257
+ Faker::Lorem.paragraph(2, true) #=> "Cedo vero adipisci. Theatrum crustulum coaegresco tonsor crastinus stabilis. Aliqua crur consequatur amor una tolero sum."
258
+ Faker::Lorem.paragraph(2, false, 4) #=> "Neque aut et nemo aut incidunt voluptates. Dolore cum est sint est. Vitae assumenda porro odio dolores fugiat. Est voluptatum quia rerum."
259
+ Faker::Lorem.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum."
238
260
 
239
261
  # Optional arguments: paragraph_count=3, supplemental=false
240
- Faker::Lorem.paragraphs #=> ""
241
- Faker::Lorem.paragraphs(1) #=> ""
242
- Faker::Lorem.paragraphs(1, true) #=> ""
262
+ Faker::Lorem.paragraphs #=> ["Dolores quis quia ad quo voluptates. Maxime delectus totam numquam. Necessitatibus vel atque qui dolore.", "Id neque nemo. Dolores iusto facere est ad. Accusamus ipsa dolor ut.", "Et officiis ut hic. Sunt asperiores minus distinctio debitis ipsa dolor. Minima eos deleniti."]
263
+ Faker::Lorem.paragraphs(1) #=> ["Labore voluptas sequi. Ratione nulla eaque quia molestiae fugit. At quam laboriosam aut ut dignissimos."]
264
+ Faker::Lorem.paragraphs(1, true) #=> ["Depulso animi cunctatio amicitia adficio. Vester viduo qui despirmatio voluptas. Validus laudantium adopto ut agnitio venustas. Aer arcus odio esse."]
243
265
 
244
266
  ```
245
267
 
@@ -262,6 +284,22 @@ Faker::Name.title #=> "Legacy Creative Director"
262
284
 
263
285
  ```
264
286
 
287
+ ###Faker::Avatar
288
+ ----------------
289
+
290
+ ```ruby
291
+
292
+ Faker::Avatar.image #=> "http://robohash.org/sitsequiquia.png?size=300x300"
293
+
294
+ Faker::Avatar.image("my-own-slug") #=> "http://robohash.org/my-own-slug.png?size=300x300"
295
+
296
+ Faker::Avatar.image("my-own-slug", "50x50") #=> "http://robohash.org/my-own-slug.png?size=50x50"
297
+
298
+ Faker::Avatar.image("my-own-slug", "50x50", "jpg") #=> "http://robohash.org/my-own-slug.jpg?size=50x50"
299
+
300
+ Faker::Avatar.image("my-own-slug", "50x50", "bmp") #=> "http://robohash.org/my-own-slug.bmp?size=50x50"
301
+ ```
302
+
265
303
  ###Faker::Number
266
304
  ----------------
267
305
 
@@ -270,6 +308,20 @@ Faker::Name.title #=> "Legacy Creative Director"
270
308
  # Required parameter: digits
271
309
  Faker::Number.number(10) #=> "1968353479"
272
310
 
311
+ # Required parameter: l_digits
312
+ Faker::Number.decimal(2) #=> "11.88"
313
+
314
+ Faker::Number.decimal(2, 3) #=> "18.843"
315
+
316
+ # Required parameter: digits
317
+ Faker::Number.hexadecimal(3) #=> "e74"
318
+
319
+ Faker::Number.between(1, 10) #=> 7
320
+
321
+ Faker::Number.positive #=> 235.59238499107653
322
+
323
+ Faker::Number.negative #=> -4480.042585669558
324
+
273
325
  Faker::Number.digit #=> "1"
274
326
 
275
327
  ```
@@ -316,6 +368,31 @@ Faker::PhoneNumber.extension #=> "3764"
316
368
 
317
369
  ```
318
370
 
371
+ ###Faker::Time
372
+ ---------------------
373
+
374
+ ```ruby
375
+ # Random date between dates
376
+ Faker::Time.between(DateTime.now - 1, DateTime.now) #=> "2014-09-18 12:30:59 -0700"
377
+
378
+ # Random date between dates (within specified part of the day)
379
+ # You can install the active_support gem to facilitate time manipulation like 45.minutes + 2.hours
380
+ require "as-duration"
381
+ Faker::Time.between(2.days.ago, Time.now, :all) #=> "2014-09-19 07:03:30 -0700"
382
+ Faker::Time.between(2.days.ago, Time.now, :day) #=> "2014-09-18 16:28:13 -0700"
383
+ Faker::Time.between(2.days.ago, Time.now, :night) #=> "2014-09-20 19:39:38 -0700"
384
+ Faker::Time.between(2.days.ago, Time.now, :morning) #=> "2014-09-19 08:07:52 -0700"
385
+ Faker::Time.between(2.days.ago, Time.now, :afternoon) #=> "2014-09-18 12:10:34 -0700"
386
+ Faker::Time.between(2.days.ago, Time.now, :evening) #=> "2014-09-19 20:21:03 -0700"
387
+ Faker::Time.between(2.days.ago, Time.now, :midnight) #=> "2014-09-20 00:40:14 -0700"
388
+
389
+ # Random time in the future (up to maximum of N days)
390
+ Faker::Time.forward(23, :morning) # => "2014-09-26 06:54:47 -0700"
391
+
392
+ # Random time in the past (up to maximum of N days)
393
+ Faker::Time.backward(14, :evening) #=> "2014-09-17 19:56:33 -0700"
394
+ ```
395
+
319
396
  ###Faker::Hacker
320
397
  ---------------------
321
398
  Are you having trouble writing tech-savvy dialogue for your latest screenplay?
@@ -354,6 +431,85 @@ Faker::App.author #=> "Daphne Swift"
354
431
 
355
432
  ```
356
433
 
434
+ ###Faker::SlackEmoji
435
+ -----------------
436
+
437
+ ```ruby
438
+
439
+ # Random Slack Emoji from people category
440
+ Faker::SlackEmoji.people #=> ":sleepy:"
441
+
442
+ # Random Slack Emoji from nature category
443
+ Faker::SlackEmoji.nature #=> ":chestnut:"
444
+
445
+ # Random Slack Emoji from food and drink category
446
+ Faker::SlackEmoji.food_and_drink #=> ":tangerine:"
447
+
448
+ # Random Slack Emoji from celebration category
449
+ Faker::SlackEmoji.celebration #=> ":ribbon:"
450
+
451
+ # Random Slack Emoji from activity category
452
+ Faker::SlackEmoji.activity #=> ":performing_arts:"
453
+
454
+ # Random Slack Emoji from travel and places category
455
+ Faker::SlackEmoji.travel_and_places #=> ":truck:"
456
+
457
+ # Random Slack Emoji from objects & symbols category
458
+ Faker::SlackEmoji.objects_and_symbols #=> ":alarm_clock:"
459
+
460
+ # Random Slack Emoji from custom category
461
+ Faker::SlackEmoji.custom #=> ":suspect:"
462
+
463
+ # Random Slack Emoji from any category
464
+ Faker::SlackEmoji.emoji #=> ":last_quarter_moon:"
465
+
466
+ ```
467
+
468
+ ###Faker::Team
469
+ -----------------
470
+
471
+ ```ruby
472
+
473
+ # Random Team Creature
474
+ Faker::Team.creature #=> "gooses"
475
+
476
+ # Random Team Name created from random US State (Faker::Address.state) prepended to a random Team Creature
477
+ Faker::Team.name #=> "Oregon vixens"
478
+
479
+ # Random Team State
480
+ Faker::Team.state #=> "Oregon"
481
+
482
+ # Random Team Sport
483
+ Faker::Team.sport #=> "lacrosse"
484
+
485
+ ```
486
+
487
+ ###Faker::Book
488
+ ------------------
489
+
490
+ ```ruby
491
+
492
+ # Random Book Title
493
+ Faker::Book.title #=> "The Odd Sister"
494
+
495
+ # Random Author
496
+ Faker::Book.author #=> "Alysha Olsen"
497
+
498
+ # Random Publisher
499
+ Faker::Book.publisher #=> "Opus Reader"
500
+
501
+ ```
502
+
503
+ ###Faker::University
504
+ ------------------
505
+
506
+ ```ruby
507
+
508
+ # Random University Name
509
+ Faker::University.name #=> "South Texas College"
510
+
511
+ ```
512
+
357
513
  Customization
358
514
  ------------
359
515
  Since you may want to make addresses and other types of data look different
@@ -372,7 +528,7 @@ and you can then override or add elements to suit
372
528
  en-au-ocker:
373
529
  faker:
374
530
  name:
375
- # Exiting faker field, new data
531
+ # Existing faker field, new data
376
532
  first_name: [Charlotte, Ava, Chloe, Emily]
377
533
 
378
534
  # New faker fields
@@ -159,7 +159,9 @@ end
159
159
 
160
160
  require 'faker/address'
161
161
  require 'faker/code'
162
+ require 'faker/color'
162
163
  require 'faker/company'
164
+ require 'faker/university'
163
165
  require 'faker/finance'
164
166
  require 'faker/internet'
165
167
  require 'faker/lorem'
@@ -177,6 +179,10 @@ require 'faker/time'
177
179
  require 'faker/number'
178
180
  require 'faker/hacker'
179
181
  require 'faker/app'
182
+ require 'faker/slack_emoji'
183
+ require 'faker/book'
180
184
 
181
185
  require 'extensions/array'
182
186
  require 'extensions/symbol'
187
+
188
+ require 'helpers/char'
@@ -3,11 +3,11 @@ module Faker
3
3
  class << self
4
4
  SUPPORTED_FORMATS = %w(png jpg bmp)
5
5
 
6
- def image(slug = nil, size = '300x300', format = 'png')
6
+ def image(slug = nil, size = '300x300', format = 'png', set = 'set1')
7
7
  raise ArgumentError, "Size should be specified in format 300x300" unless size.match(/^[0-9]+x[0-9]+$/)
8
8
  raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
9
9
  slug ||= Faker::Lorem.words.join
10
- "http://robohash.org/#{slug}.#{format}?size=#{size}"
10
+ "http://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}"
11
11
  end
12
12
  end
13
13
  end
@@ -5,12 +5,17 @@ module Faker
5
5
  class Bitcoin < Base
6
6
  class << self
7
7
 
8
+ PROTOCOL_VERSIONS = {
9
+ main: 0,
10
+ testnet: 111
11
+ }
12
+
8
13
  def address
9
- hash = SecureRandom.hex(20)
10
- version = 0
11
- packed = version.chr + [hash].pack("H*")
12
- checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
13
- base58(packed + checksum)
14
+ address_for(:main)
15
+ end
16
+
17
+ def testnet_address
18
+ address_for(:testnet)
14
19
  end
15
20
 
16
21
  protected
@@ -32,6 +37,13 @@ module Faker
32
37
  '1'*npad + ret.reverse
33
38
  end
34
39
 
40
+ def address_for(network)
41
+ version = PROTOCOL_VERSIONS.fetch(network)
42
+ hash = SecureRandom.hex(20)
43
+ packed = version.chr + [hash].pack("H*")
44
+ checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
45
+ base58(packed + checksum)
46
+ end
35
47
  end
36
48
  end
37
49
  end
@@ -0,0 +1,19 @@
1
+ module Faker
2
+ class Book < Base
3
+ flexible :book
4
+
5
+ class << self
6
+ def title
7
+ fetch('book.title')
8
+ end
9
+
10
+ def author
11
+ fetch('book.author')
12
+ end
13
+
14
+ def publisher
15
+ fetch('book.publisher')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -10,7 +10,7 @@ module Faker
10
10
  end
11
11
 
12
12
  def credit_card_expiry_date
13
- ::Date.parse(fetch('business.credit_card_expiry_dates'))
13
+ ::Date.today + (365 * (rand(4) + 1))
14
14
  end
15
15
 
16
16
  def credit_card_type
@@ -1,6 +1,13 @@
1
1
  module Faker
2
2
  class Code < Base
3
3
  class << self
4
+
5
+ # Generates a 10 digit NPI (National Provider Identifier
6
+ # issued to health care providers in the United States)
7
+ def npi
8
+ Random.new.rand(10 ** 10).to_s.rjust(10, '0')
9
+ end
10
+
4
11
  # By default generates 10 sign isbn code in format 123456789-X
5
12
  # You can pass 13 to generate new 13 sign code
6
13
  def isbn(base = 10)
@@ -0,0 +1,49 @@
1
+ module Faker
2
+ class Color < Base
3
+ class << self
4
+ def hex_color
5
+ @hex_color = "#%06x" % (rand * 0xffffff)
6
+ end
7
+
8
+ def single_rgb_color
9
+ @single_rgb_color = (0..255).to_a.sample
10
+ @single_rgb_color
11
+ end
12
+
13
+ def rgb_color
14
+ @rgb_colors = []
15
+ 3.times do
16
+ @rgb_colors.push single_rgb_color
17
+ end
18
+ @rgb_colors
19
+ end
20
+
21
+ def single_hsl_color
22
+ @single_hsla_color = Faker::Base::rand_in_range(0.0, 360.00).round(2)
23
+ @single_hsla_color
24
+ end
25
+
26
+ def alpha_channel
27
+ @alpha_channel = rand
28
+ @alpha_channel
29
+ end
30
+
31
+ def hsl_color
32
+ @hsl_colors = []
33
+ 3.times do
34
+ @hsl_colors.push single_hsl_color
35
+ end
36
+ @hsl_colors
37
+ end
38
+
39
+ def hsla_color
40
+ @hsla_colors = []
41
+ 3.times do
42
+ @hsla_colors.push single_hsl_color
43
+ end
44
+ @hsla_colors.push alpha_channel
45
+ @hsla_colors
46
+ end
47
+ end
48
+ end
49
+ end