faker 1.5.0 → 1.6.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +5 -0
  3. data/README.md +80 -6
  4. data/lib/faker.rb +8 -1
  5. data/lib/faker/address.rb +0 -1
  6. data/lib/faker/avatar.rb +3 -2
  7. data/lib/faker/book.rb +5 -1
  8. data/lib/faker/code.rb +18 -0
  9. data/lib/faker/commerce.rb +3 -3
  10. data/lib/faker/company.rb +9 -1
  11. data/lib/faker/hipster.rb +59 -0
  12. data/lib/faker/id_number.rb +36 -0
  13. data/lib/faker/internet.rb +68 -27
  14. data/lib/faker/number.rb +24 -2
  15. data/lib/faker/placeholdit.rb +20 -0
  16. data/lib/faker/shakespeare.rb +83 -0
  17. data/lib/faker/time.rb +10 -1
  18. data/lib/faker/version.rb +1 -1
  19. data/lib/locales/de.yml +6 -0
  20. data/lib/locales/en-AU.yml +3 -1
  21. data/lib/locales/en-NEP.yml +11 -1
  22. data/lib/locales/en-NZ.yml +25 -0
  23. data/lib/locales/en-SG.yml +31 -0
  24. data/lib/locales/en-US.yml +16 -1
  25. data/lib/locales/en-au-ocker.yml +5 -3
  26. data/lib/locales/en.yml +11 -1
  27. data/lib/locales/es.yml +10 -0
  28. data/lib/locales/fr.yml +6 -1
  29. data/lib/locales/he.yml +25 -0
  30. data/lib/locales/it.yml +6 -6
  31. data/lib/locales/ja.yml +22 -4
  32. data/lib/locales/nb-NO.yml +4 -1
  33. data/lib/locales/pl.yml +1 -1
  34. data/lib/locales/pt-BR.yml +2 -2
  35. data/lib/locales/sk.yml +2 -2
  36. data/lib/locales/zh-CN.yml +2 -0
  37. data/test/test_avatar.rb +9 -5
  38. data/test/test_en_au_locale.rb +24 -0
  39. data/test/test_en_au_ocker_locale.rb +7 -5
  40. data/test/test_en_locale.rb +10 -0
  41. data/test/test_en_nz_locale.rb +33 -0
  42. data/test/test_en_us_locale.rb +10 -0
  43. data/test/test_faker_book.rb +5 -1
  44. data/test/test_faker_code.rb +4 -0
  45. data/test/test_faker_commerce.rb +12 -4
  46. data/test/test_faker_company.rb +5 -1
  47. data/test/test_faker_date.rb +4 -3
  48. data/test/test_faker_hipster.rb +78 -0
  49. data/test/test_faker_internet.rb +36 -3
  50. data/test/test_faker_lorem.rb +3 -3
  51. data/test/test_faker_number.rb +30 -0
  52. data/test/test_faker_shakespeare.rb +53 -0
  53. data/test/test_faker_time.rb +24 -5
  54. data/test/test_placeholdit.rb +92 -0
  55. metadata +19 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6c36a94960622277ebd5a4297ec2433f7e5fe2b
4
- data.tar.gz: ca8eee943c3f67e2201c695ac8f9e73d6129c913
3
+ metadata.gz: 16afea76964cc1fb1d8779296e32ed88e450ed42
4
+ data.tar.gz: 1470483a239699d09a0cf0c2e8133069f4a82b29
5
5
  SHA512:
6
- metadata.gz: bf565c6375b6e3dab4c7e6598f618c2bb2930d8d8bc70bb9202f886d65b9b5f9f4430ffc3554fc13e99a0739a9af4893eabbb452f9f7fbc0c7649f9f3a6bdcf7
7
- data.tar.gz: 09a408f05ef48d4aa320cb1c4a75ddf2f6d3da570430e81abb3cd888d5f27b3909e285654dbb458f64e03e3b2527b5790b6d9fbef6724978bfc41bb1c7c1e4a7
6
+ metadata.gz: e5940ec8586f709c265b428d64a11ab0e13ecdd91201a95b2213e4cc04bff2708f5441fba29fabfac9097328e4c3d516a2c2ef87dee41eef315fd662e3005624
7
+ data.tar.gz: b4b9b8e736b664fbc4e8974d1dd3dd38d1956763f48d8d21b2426d3fc9ace02547d0ba95fb0587cbce8379051a13d9303593b29363d4a746f254a32757bb73ea
@@ -1,3 +1,8 @@
1
+ == 1.6.0 2015-11-20
2
+ * Lots of bug fixes -- most notably, a fix for email addresses and domains in non-en locales
3
+ * Updated locales: de, en-AU, en-NZ, en-SG, en-US, en-au-ocker, en, es, fr, he, it, ja, nb-NO, pl, pt-BR, sk, and zh-CN
4
+ * Updated classes: Address, Avatar, Book, Code, Commerce, Company, Hipster, IDNumber, Internet, Number, Placeholdit, Shakespeare, and Time
5
+
1
6
  == 1.5.0 2015-08-17
2
7
  * Added logos
3
8
  * Added Slack Emoji
data/README.md CHANGED
@@ -141,10 +141,13 @@ Faker::Company.ein #=> "34-8488813"
141
141
  Faker::Company.duns_number #=> "08-341-3736"
142
142
 
143
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"
144
+ Faker::Company.logo #=> "https://pigment.github.com/fake-logos/logos/medium/color/5.png"
145
145
 
146
146
  Faker::Company.swedish_organisation_number #=> "7718797652"
147
147
 
148
+ # Get a random profession
149
+ Faker::Company.profession #=> "firefighter"
150
+
148
151
  ```
149
152
 
150
153
  ###Faker::Date
@@ -194,6 +197,10 @@ Faker::Internet.password(8) #=> "yfgjik0hgzdqs0"
194
197
 
195
198
  Faker::Internet.password(10, 20) #=> "eoc9shwd1hwq4vbgfw"
196
199
 
200
+ Faker::Internet.password(10, 20, true) #=> "3k5qS15aNmG"
201
+
202
+ Faker::Internet.password(10, 20, true, true) #=> "*%NkOnJsH4"
203
+
197
204
  Faker::Internet.domain_name #=> "effertz.info"
198
205
 
199
206
  Faker::Internet.fix_umlauts('äöüß') #=> "aeoeuess"
@@ -204,6 +211,10 @@ Faker::Internet.domain_suffix #=> "info"
204
211
 
205
212
  Faker::Internet.ip_v4_address #=> "24.29.18.175"
206
213
 
214
+ # Guaranteed not to be in 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16,
215
+ # 172.16.0.0/12, or 192.168.0.0/16
216
+ Faker::Internet.public_ip_v4_address #=> "24.29.18.175"
217
+
207
218
  Faker::Internet.ip_v6_address #=> "ac5f:d696:3807:1d72:2eb5:4e81:7d2b:e1df"
208
219
 
209
220
  # Optional argument prefix=''
@@ -289,15 +300,17 @@ Faker::Name.title #=> "Legacy Creative Director"
289
300
 
290
301
  ```ruby
291
302
 
292
- Faker::Avatar.image #=> "http://robohash.org/sitsequiquia.png?size=300x300"
303
+ Faker::Avatar.image #=> "https://robohash.org/sitsequiquia.png?size=300x300"
304
+
305
+ Faker::Avatar.image("my-own-slug") #=> "https://robohash.org/my-own-slug.png?size=300x300"
293
306
 
294
- Faker::Avatar.image("my-own-slug") #=> "http://robohash.org/my-own-slug.png?size=300x300"
307
+ Faker::Avatar.image("my-own-slug", "50x50") #=> "https://robohash.org/my-own-slug.png?size=50x50"
295
308
 
296
- Faker::Avatar.image("my-own-slug", "50x50") #=> "http://robohash.org/my-own-slug.png?size=50x50"
309
+ Faker::Avatar.image("my-own-slug", "50x50", "jpg") #=> "https://robohash.org/my-own-slug.jpg?size=50x50"
297
310
 
298
- Faker::Avatar.image("my-own-slug", "50x50", "jpg") #=> "http://robohash.org/my-own-slug.jpg?size=50x50"
311
+ Faker::Avatar.image("my-own-slug", "50x50", "bmp") #=> "https://robohash.org/my-own-slug.bmp?size=50x50"
299
312
 
300
- Faker::Avatar.image("my-own-slug", "50x50", "bmp") #=> "http://robohash.org/my-own-slug.bmp?size=50x50"
313
+ Faker::Avatar.image("my-own-slug", "50x50", "bmp", "set1", "bg1") #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1&bgset=bg1"
301
314
  ```
302
315
 
303
316
  ###Faker::Number
@@ -498,6 +511,9 @@ Faker::Book.author #=> "Alysha Olsen"
498
511
  # Random Publisher
499
512
  Faker::Book.publisher #=> "Opus Reader"
500
513
 
514
+ # Random Genre
515
+ Faker::Book.genre #=> "Mystery"
516
+
501
517
  ```
502
518
 
503
519
  ###Faker::University
@@ -510,6 +526,64 @@ Faker::University.name #=> "South Texas College"
510
526
 
511
527
  ```
512
528
 
529
+ ###Faker::Placeholdit
530
+ ----------------
531
+
532
+ ```ruby
533
+
534
+ Faker::Placeholdit.image #=> "http://placehold.it/300x300.png/000"
535
+
536
+ Faker::Placeholdit.image("50x50") #=> "http://placehold.it/50x50.png/000"
537
+
538
+ Faker::Placeholdit.image("50x50", 'jpg') #=> "http://placehold.it/50x50.jpg/000"
539
+
540
+ Faker::Placeholdit.image("50x50", 'gif', 'ffffff') #=> "http://placehold.it/50x50.gif/ffffff"
541
+
542
+ Faker::Placeholdit.image("50x50", 'jpeg', 'ffffff', '000') #=> "http://placehold.it/50x50.jpeg/ffffff/000"
543
+
544
+ Faker::Placeholdit.image("50x50", 'jpg', 'ffffff', '000', 'Some Custom Text') #=> "http://placehold.it/50x50.jpg/ffffff/000?text='Some Custom Text'"
545
+
546
+ ```
547
+
548
+ ###Faker::Hipster
549
+ ----------------
550
+ Adapted from [Hipster Ipsum](http://hipsum.co/)
551
+
552
+ ```ruby
553
+
554
+ Faker::Hipster.word #=> "irony"
555
+
556
+ # Optional arguments: num=3, supplemental=false, spaces_allowed = false
557
+ Faker::Hipster.words #=> ["pug", "pitchfork", "chia"]
558
+ Faker::Hipster.words(4) #=> ["ugh", "cardigan", "poutine", "stumptown"]
559
+ Faker::Hipster.words(4, true) #=> ["iste", "seitan", "normcore", "provident"]
560
+ Faker::Hipster.words(4, true, true) #=> ["qui", "magni", "craft beer", "est"]
561
+
562
+ # Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
563
+ Faker::Hipster.sentence #=> "Park iphone leggings put a bird on it."
564
+ Faker::Hipster.sentence(3) #=> "Pour-over swag godard."
565
+ Faker::Hipster.sentence(3, true) #=> "Beard laboriosam sequi celiac."
566
+ Faker::Hipster.sentence(3, false, 4) #=> "Bitters retro mustache aesthetic biodiesel 8-bit."
567
+ Faker::Hipster.sentence(3, true, 4) #=> "Occaecati deleniti messenger bag meh crucifix autem."
568
+
569
+ # Optional arguments: sentence_count=3, supplemental=false
570
+ Faker::Hipster.sentences #=> ["Godard pitchfork vinegar chillwave everyday 90's whatever.", "Pour-over artisan distillery street waistcoat.", "Salvia yr leggings franzen blue bottle."]
571
+ Faker::Hipster.sentences(1) #=> ["Before they sold out pinterest venmo umami try-hard ugh hoodie artisan."]
572
+ Faker::Hipster.sentences(1, true) #=> ["Et sustainable optio aesthetic et."]
573
+
574
+ # Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
575
+ Faker::Hipster.paragraph #=> "Migas fingerstache pbr&b tofu. Polaroid distillery typewriter echo tofu actually. Slow-carb fanny pack pickled direct trade scenester mlkshk plaid. Banjo venmo chambray cold-pressed typewriter. Fap skateboard intelligentsia."
576
+ Faker::Hipster.paragraph(2) #=> "Yolo tilde farm-to-table hashtag. Lomo kitsch disrupt forage +1."
577
+ Faker::Hipster.paragraph(2, true) #=> "Typewriter iste ut viral kombucha voluptatem. Sint voluptates saepe. Direct trade irony chia excepturi yuccie. Biodiesel esse listicle et quam suscipit."
578
+ Faker::Hipster.paragraph(2, false, 4) #=> "Selvage vhs chartreuse narwhal vinegar. Authentic vinyl truffaut carry vhs pop-up. Hammock everyday iphone locavore thundercats bitters vegan goth. Fashion axe banh mi shoreditch whatever artisan."
579
+ Faker::Hipster.paragraph(2, true, 4) #=> "Deep v gluten-free unde waistcoat aperiam migas voluptas dolorum. Aut drinking illo sustainable sapiente. Direct trade fanny pack kale chips ennui semiotics."
580
+
581
+ # Optional arguments: paragraph_count=3, supplemental=false
582
+ Faker::Hipster.paragraphs #=> ["Tilde microdosing blog cliche meggings. Intelligentsia five dollar toast forage yuccie. Master kitsch knausgaard. Try-hard everyday trust fund mumblecore.", "Normcore viral pickled. Listicle humblebrag swag tote bag. Taxidermy street hammock neutra butcher cred kale chips. Blog portland humblebrag trust fund irony.", "Single-origin coffee fixie cleanse tofu xoxo. Post-ironic tote bag ramps gluten-free locavore mumblecore hammock. Umami loko twee. Ugh kitsch before they sold out."]
583
+ Faker::Hipster.paragraphs(1) #=> ["Skateboard cronut synth +1 fashion axe. Pop-up polaroid skateboard asymmetrical. Ennui fingerstache shoreditch before they sold out. Tattooed pitchfork ramps. Photo booth yr messenger bag raw denim bespoke locavore lomo synth."]
584
+ Faker::Hipster.paragraphs(1, true) #=> ["Quae direct trade pbr&b quo taxidermy autem loko. Umami quas ratione migas cardigan sriracha minima. Tenetur perspiciatis pickled sed eum doloribus truffaut. Excepturi dreamcatcher meditation."]
585
+ ```
586
+
513
587
  Customization
514
588
  ------------
515
589
  Since you may want to make addresses and other types of data look different
@@ -122,10 +122,13 @@ module Faker
122
122
  opts[:raise] = true
123
123
  I18n.translate(*(args.push(opts)))
124
124
  rescue I18n::MissingTranslationData
125
+ opts = args.last.is_a?(Hash) ? args.pop : {}
126
+ opts[:locale] = :en
127
+
125
128
  # Super-simple fallback -- fallback to en if the
126
129
  # translation was missing. If the translation isn't
127
130
  # in en either, then it will raise again.
128
- I18n.translate(*(args.push(opts.merge(:locale => :en))))
131
+ I18n.translate(*(args.push(opts)))
129
132
  end
130
133
 
131
134
  def flexible(key)
@@ -174,13 +177,17 @@ require 'faker/version'
174
177
  require 'faker/number'
175
178
  require 'faker/bitcoin'
176
179
  require 'faker/avatar'
180
+ require 'faker/placeholdit'
177
181
  require 'faker/date'
178
182
  require 'faker/time'
179
183
  require 'faker/number'
180
184
  require 'faker/hacker'
181
185
  require 'faker/app'
186
+ require 'faker/id_number'
182
187
  require 'faker/slack_emoji'
183
188
  require 'faker/book'
189
+ require 'faker/hipster'
190
+ require 'faker/shakespeare'
184
191
 
185
192
  require 'extensions/array'
186
193
  require 'extensions/symbol'
@@ -53,7 +53,6 @@ module Faker
53
53
  def longitude
54
54
  ((rand * 360) - 180).to_s
55
55
  end
56
-
57
56
  end
58
57
  end
59
58
  end
@@ -3,11 +3,12 @@ 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', set = 'set1')
6
+ def image(slug = nil, size = '300x300', format = 'png', set = 'set1', bgset = nil)
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}&set=#{set}"
10
+ bgset_query = "&bgset=#{bgset}" if bgset
11
+ "https://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}#{bgset_query}"
11
12
  end
12
13
  end
13
14
  end
@@ -8,12 +8,16 @@ module Faker
8
8
  end
9
9
 
10
10
  def author
11
- fetch('book.author')
11
+ parse('book.author')
12
12
  end
13
13
 
14
14
  def publisher
15
15
  fetch('book.publisher')
16
16
  end
17
+
18
+ def genre
19
+ fetch('book.genre')
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -26,6 +26,17 @@ module Faker
26
26
  value << "-#{vd}"
27
27
  end
28
28
 
29
+ # By default generates a Singaporean NRIC ID for someone
30
+ # who is born between the age of 18 and 65.
31
+ def nric(min_age = 18, max_age = 65)
32
+ birthyear = Date.birthday(min_age, max_age).year
33
+ prefix = birthyear < 2000 ? 'S' : 'T'
34
+ values = birthyear.to_s[-2..-1]
35
+ values << regexify(/\d{5}/)
36
+ check_alpha = generate_nric_check_alphabet(values, prefix)
37
+ "#{prefix}#{values}#{check_alpha}"
38
+ end
39
+
29
40
  private
30
41
 
31
42
  def generate_base10_isbn
@@ -65,6 +76,13 @@ module Faker
65
76
  total = rut.to_s.rjust(8, '0').split(//).zip(%w(3 2 7 6 5 4 3 2)).collect{|a, b| a.to_i * b.to_i}.inject(:+)
66
77
  (11 - total % 11).to_s.gsub(/10/, 'k').gsub(/11/, '0')
67
78
  end
79
+
80
+ def generate_nric_check_alphabet(values, prefix)
81
+ weight = %w(2 7 6 5 4 3 2)
82
+ total = values.split(//).zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
83
+ total = total + 4 if prefix == 'T'
84
+ %w(A B C D E F G H I Z J)[10 - total % 11]
85
+ end
68
86
  end
69
87
  end
70
88
  end
@@ -27,9 +27,9 @@ module Faker
27
27
  fetch('commerce.product_name.material')
28
28
  end
29
29
 
30
- def price
31
- random = Random.new
32
- (random.rand(0..100.0) * 100).floor/100.0
30
+ def price(range=0..100.0)
31
+ random = Random::DEFAULT
32
+ (random.rand(range) * 100).floor/100.0
33
33
  end
34
34
 
35
35
  private
@@ -11,6 +11,10 @@ module Faker
11
11
  fetch('company.suffix')
12
12
  end
13
13
 
14
+ def industry
15
+ fetch('company.industry')
16
+ end
17
+
14
18
  # Generate a buzzword-laden catch phrase.
15
19
  def catch_phrase
16
20
  translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
@@ -36,7 +40,7 @@ module Faker
36
40
  # Get a random company logo url in PNG format.
37
41
  def logo
38
42
  rand_num = Random.rand(13) + 1
39
- "http://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
43
+ "https://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
40
44
  end
41
45
 
42
46
  def swedish_organisation_number
@@ -44,6 +48,10 @@ module Faker
44
48
  base + luhn_algorithm(base).to_s
45
49
  end
46
50
 
51
+ def profession
52
+ fetch('company.profession')
53
+ end
54
+
47
55
  private
48
56
 
49
57
  def luhn_algorithm(number)
@@ -0,0 +1,59 @@
1
+ module Faker
2
+ class Hipster < Base
3
+ class << self
4
+ def word
5
+ random_word = translate('faker.hipster.words').sample
6
+ random_word.match(/\s/) ? word : random_word
7
+ end
8
+
9
+ def words(num = 3, supplemental = false, spaces_allowed = false)
10
+ resolved_num = resolve(num)
11
+ word_list = (
12
+ translate('faker.hipster.words') +
13
+ (supplemental ? translate('faker.lorem.words') : [])
14
+ )
15
+ word_list = word_list * ((resolved_num / word_list.length) + 1)
16
+
17
+ return word_list.shuffle[0, resolved_num] if spaces_allowed
18
+ words = word_list.shuffle[0, resolved_num]
19
+ words.each_with_index { |w, i| words[i] = word if w.match(/\s/) }
20
+ end
21
+
22
+ def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
23
+ words(word_count + rand(random_words_to_add.to_i).to_i, supplemental, true).join(' ').capitalize + '.'
24
+ end
25
+
26
+ def sentences(sentence_count = 3, supplemental = false)
27
+ [].tap do |sentences|
28
+ 1.upto(resolve(sentence_count)) do
29
+ sentences << sentence(3, supplemental)
30
+ end
31
+ end
32
+ end
33
+
34
+ def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
35
+ sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ')
36
+ end
37
+
38
+ def paragraphs(paragraph_count = 3, supplemental = false)
39
+ [].tap do |paragraphs|
40
+ 1.upto(resolve(paragraph_count)) do
41
+ paragraphs << paragraph(3, supplemental)
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ # If an array or range is passed, a random value will be selected.
49
+ # All other values are simply returned.
50
+ def resolve(value)
51
+ case value
52
+ when Array then value[rand(value.size)]
53
+ when Range then rand((value.last+1) - value.first) + value.first
54
+ else value
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,36 @@
1
+ module Faker
2
+ class IDNumber < Base
3
+ INVALID_SSN = [
4
+ /0{3}-\d{2}-\d{4}/,
5
+ /\d{3}-0{2}-\d{4}/,
6
+ /\d{3}-\d{2}-0{4}/,
7
+ /666-\d{2}-\d{4}/,
8
+ /9\d{2}-\d{2}-\d{4}/
9
+ ]
10
+ class << self
11
+
12
+ def valid
13
+ _translate 'valid'
14
+ end
15
+
16
+ def invalid
17
+ _translate 'invalid'
18
+ end
19
+
20
+ def ssn_valid
21
+ ssn = regexify(/[0-8]\d{2}-\d{2}-\d{4}/)
22
+ # We could still have all 0s in one segment or another
23
+ INVALID_SSN.any? { |regex| regex =~ ssn } ? ssn_valid : ssn
24
+ end
25
+
26
+ private
27
+ def _translate key
28
+ if parse("id_number.#{key}") == ''
29
+ numerify(fetch("id_number.#{key}"))
30
+ else
31
+ parse("id_number.#{key}")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -15,36 +15,38 @@ module Faker
15
15
  end
16
16
 
17
17
  def user_name(specifier = nil, separators = %w(. _))
18
- if specifier.kind_of? String
19
- return specifier.scan(/\w+/).shuffle.join(separators.sample).downcase
20
- elsif specifier.kind_of? Integer
21
- tries = 0 # Don't try forever in case we get something like 1_000_000.
22
- begin
23
- result = user_name nil, separators
24
- tries += 1
25
- end while result.length < specifier and tries < 7
26
- until result.length >= specifier
27
- result = result * 2
18
+ I18n.with_locale(:en) do
19
+ if specifier.kind_of? String
20
+ return specifier.scan(/\w+/).shuffle.join(separators.sample).downcase
21
+ elsif specifier.kind_of? Integer
22
+ tries = 0 # Don't try forever in case we get something like 1_000_000.
23
+ begin
24
+ result = user_name nil, separators
25
+ tries += 1
26
+ end while result.length < specifier and tries < 7
27
+ until result.length >= specifier
28
+ result = result * 2
29
+ end
30
+ return result
31
+ elsif specifier.kind_of? Range
32
+ tries = 0
33
+ begin
34
+ result = user_name specifier.min, separators
35
+ tries += 1
36
+ end while not specifier.include? result.length and tries < 7
37
+ return result[0...specifier.max]
28
38
  end
29
- return result
30
- elsif specifier.kind_of? Range
31
- tries = 0
32
- begin
33
- result = user_name specifier.min, separators
34
- tries += 1
35
- end while not specifier.include? result.length and tries < 7
36
- return result[0...specifier.max]
37
- end
38
39
 
39
- [
40
- Char.prepare(Name.first_name),
41
- [Name.first_name, Name.last_name].map{ |name|
42
- Char.prepare name
43
- }.join(separators.sample)
44
- ].sample
40
+ [
41
+ Char.prepare(Name.first_name),
42
+ [Name.first_name, Name.last_name].map{ |name|
43
+ Char.prepare name
44
+ }.join(separators.sample)
45
+ ].sample
46
+ end
45
47
  end
46
48
 
47
- def password(min_length = 8, max_length = 16)
49
+ def password(min_length = 8, max_length = 16, mix_case = true, special_chars = false)
48
50
  temp = Lorem.characters(min_length)
49
51
  diff_length = max_length - min_length
50
52
  if diff_length > 0
@@ -52,11 +54,25 @@ module Faker
52
54
  temp += Lorem.characters(diff_rand)
53
55
  end
54
56
  temp = temp[0..min_length] if min_length > 0
57
+
58
+ if mix_case
59
+ temp.chars.each_with_index do |char, index|
60
+ temp[index] = char.upcase if index % 2 == 0
61
+ end
62
+ end
63
+
64
+ if special_chars
65
+ chars = %w(! @ # $ % ^ & *)
66
+ Random.rand(min_length).times do |i|
67
+ temp[i] = chars[Random.rand(chars.length)]
68
+ end
69
+ end
70
+
55
71
  return temp
56
72
  end
57
73
 
58
74
  def domain_name
59
- [Char.prepare(domain_word), domain_suffix].join('.')
75
+ I18n.with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
60
76
  end
61
77
 
62
78
  def fix_umlauts(string)
@@ -88,12 +104,37 @@ module Faker
88
104
  ary.sample].join('.')
89
105
  end
90
106
 
107
+ def public_ip_v4_address
108
+ private_nets = [
109
+ /^10\./,
110
+ /^127\./,
111
+ /^169\.254\./,
112
+ /^172\.(16|17|18|19|2\d|30|31)\./,
113
+ /^192\.168\./
114
+ ]
115
+
116
+ is_private = lambda {|addr| private_nets.any?{|net| net =~ addr}}
117
+ addr = nil
118
+ begin
119
+ addr = ip_v4_address
120
+ end while is_private[addr]
121
+ addr
122
+ end
123
+
124
+ def ip_v4_cidr
125
+ "#{ip_v4_address}/#{[1..32].sample}"
126
+ end
127
+
91
128
  def ip_v6_address
92
129
  @@ip_v6_space ||= (0..65535).to_a
93
130
  container = (1..8).map{ |_| @@ip_v6_space.sample }
94
131
  container.map{ |n| n.to_s(16) }.join(':')
95
132
  end
96
133
 
134
+ def ip_v6_cidr
135
+ "#{ip_v6_address}/#{[1..128].sample}"
136
+ end
137
+
97
138
  def url(host = domain_name, path = "/#{user_name}")
98
139
  "http://#{host}#{path}"
99
140
  end