faker 2.17.0 → 2.20.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -2
  3. data/README.md +22 -4
  4. data/lib/faker/books/the_kingkiller_chronicle.rb +61 -0
  5. data/lib/faker/creature/bird.rb +203 -0
  6. data/lib/faker/default/code.rb +1 -1
  7. data/lib/faker/default/commerce.rb +28 -0
  8. data/lib/faker/default/company.rb +5 -7
  9. data/lib/faker/default/crypto.rb +13 -0
  10. data/lib/faker/default/emotion.rb +33 -0
  11. data/lib/faker/default/finance.rb +13 -0
  12. data/lib/faker/default/food.rb +13 -0
  13. data/lib/faker/default/hobby.rb +22 -0
  14. data/lib/faker/default/id_number.rb +34 -0
  15. data/lib/faker/default/internet.rb +40 -16
  16. data/lib/faker/default/lorem.rb +0 -4
  17. data/lib/faker/default/nation.rb +0 -3
  18. data/lib/faker/default/omniauth.rb +45 -1
  19. data/lib/faker/default/placeholdit.rb +9 -9
  20. data/lib/faker/default/religion.rb +6 -0
  21. data/lib/faker/default/science.rb +108 -0
  22. data/lib/faker/default/string.rb +0 -3
  23. data/lib/faker/default/tea.rb +41 -0
  24. data/lib/faker/default/time.rb +0 -2
  25. data/lib/faker/games/dota.rb +13 -0
  26. data/lib/faker/games/witcher.rb +39 -0
  27. data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +48 -0
  28. data/lib/faker/japanese_media/kamen_rider.rb +102 -0
  29. data/lib/faker/locations/australia.rb +47 -0
  30. data/lib/faker/music/hiphop.rb +3 -3
  31. data/lib/faker/music/music.rb +12 -0
  32. data/lib/faker/religion/bible.rb +50 -0
  33. data/lib/faker/tv_shows/brooklyn_nine_nine.rb +38 -0
  34. data/lib/faker/tv_shows/michael_scott.rb +0 -3
  35. data/lib/faker/tv_shows/supernatural.rb +48 -0
  36. data/lib/faker/tv_shows/the_office.rb +37 -0
  37. data/lib/faker/version.rb +2 -2
  38. data/lib/locales/ar.yml +5 -1
  39. data/lib/locales/de-AT.yml +2 -2
  40. data/lib/locales/de.yml +7 -3
  41. data/lib/locales/en/address.yml +2 -3
  42. data/lib/locales/en/animal.yml +1 -1
  43. data/lib/locales/en/australia.yml +108 -0
  44. data/lib/locales/en/bible.yml +90 -0
  45. data/lib/locales/en/bird.yml +1281 -0
  46. data/lib/locales/en/book.yml +487 -3
  47. data/lib/locales/en/brooklyn_nine_nine.yml +35 -0
  48. data/lib/locales/en/cat.yml +1 -1
  49. data/lib/locales/en/coffee.yml +1 -1
  50. data/lib/locales/en/commerce.yml +17 -0
  51. data/lib/locales/en/community.yml +17 -17
  52. data/lib/locales/en/dota.yml +7 -0
  53. data/lib/locales/en/dune.yml +266 -397
  54. data/lib/locales/en/emotion.yml +480 -0
  55. data/lib/locales/en/finance.yml +21 -0
  56. data/lib/locales/en/fma_brotherhood.yml +78 -0
  57. data/lib/locales/en/food.yml +1054 -10
  58. data/lib/locales/en/game.yml +12 -0
  59. data/lib/locales/en/hobby.yml +171 -0
  60. data/lib/locales/en/horse.yml +2 -2
  61. data/lib/locales/en/internet.yml +108 -3
  62. data/lib/locales/en/kamen_rider.yml +452 -0
  63. data/lib/locales/en/kpop.yml +7 -7
  64. data/lib/locales/en/lovecraft.yml +76 -6
  65. data/lib/locales/en/mountain.yml +14 -1
  66. data/lib/locales/en/music.yml +152 -142
  67. data/lib/locales/en/science.yml +481 -3
  68. data/lib/locales/en/space.yml +1 -1
  69. data/lib/locales/en/stranger_thing.yml +1 -1
  70. data/lib/locales/en/super_smash_bros.yml +5 -2
  71. data/lib/locales/en/supernatural.yml +141 -0
  72. data/lib/locales/en/tea.yml +172 -0
  73. data/lib/locales/en/the_kingkiller_chronicle.yml +56 -0
  74. data/lib/locales/en/the_office.yml +86 -0
  75. data/lib/locales/en/touhou.yml +1 -1
  76. data/lib/locales/en/witcher.yml +37 -0
  77. data/lib/locales/en-US.yml +2 -2
  78. data/lib/locales/es-AR.yml +1 -4
  79. data/lib/locales/fr/address.yml +21 -0
  80. data/lib/locales/fr/animal.yml +5 -0
  81. data/lib/locales/fr/appliance.yml +4 -0
  82. data/lib/locales/fr/book.yml +7 -0
  83. data/lib/locales/fr/color.yml +4 -0
  84. data/lib/locales/fr/company.yml +17 -0
  85. data/lib/locales/fr/compass.yml +23 -0
  86. data/lib/locales/fr/demographic.yml +4 -0
  87. data/lib/locales/fr/gender.yml +6 -0
  88. data/lib/locales/fr/internet.yml +5 -0
  89. data/lib/locales/fr/lorem.yml +5 -0
  90. data/lib/locales/fr/measurement.yml +7 -0
  91. data/lib/locales/fr/name.yml +21 -0
  92. data/lib/locales/fr/phone_number.yml +7 -0
  93. data/lib/locales/fr/pokemon.yml +7 -0
  94. data/lib/locales/fr.yml +0 -118
  95. data/lib/locales/ja/README.md +13 -0
  96. data/lib/locales/ja/address.yml +120539 -0
  97. data/lib/locales/ja/ancient.yml +4 -0
  98. data/lib/locales/ja/animal.yml +5 -0
  99. data/lib/locales/ja/bank.yml +4 -0
  100. data/lib/locales/ja/book.yml +7 -0
  101. data/lib/locales/ja/cat.yml +5 -0
  102. data/lib/locales/ja/coffee.yml +4 -0
  103. data/lib/locales/ja/color.yml +4 -0
  104. data/lib/locales/ja/commerce.yml +11 -0
  105. data/lib/locales/ja/company.yml +8 -0
  106. data/lib/locales/ja/dog.yml +5 -0
  107. data/lib/locales/ja/food.yml +4 -0
  108. data/lib/locales/ja/gender.yml +4 -0
  109. data/lib/locales/ja/lorem.yml +9 -0
  110. data/lib/locales/ja/name.yml +13 -0
  111. data/lib/locales/ja/overwatch.yml +5 -0
  112. data/lib/locales/ja/phone_number.yml +7 -0
  113. data/lib/locales/ja/pokemon.yml +7 -0
  114. data/lib/locales/ja/restaurant.yml +11 -0
  115. data/lib/locales/ja/space.yml +5 -0
  116. data/lib/locales/ja/studio_ghibli.yml +112 -0
  117. data/lib/locales/ja/subscription.yml +8 -0
  118. data/lib/locales/ja/super_mario.yml +9 -0
  119. data/lib/locales/ja/super_smash_bros.yml +8 -0
  120. data/lib/locales/ja/university.yml +9 -0
  121. data/lib/locales/ja/zelda.yml +5 -0
  122. data/lib/locales/lt.yml +35 -0
  123. data/lib/locales/lv.yml +1 -1
  124. data/lib/locales/mi-NZ.yml +281 -0
  125. data/lib/locales/pt-BR.yml +7 -1
  126. data/lib/locales/ru.yml +39 -0
  127. metadata +94 -20
  128. data/lib/locales/ja.yml +0 -118
@@ -108,6 +108,19 @@ module Faker
108
108
  def metric_measurement
109
109
  fetch('food.metric_measurements')
110
110
  end
111
+
112
+ ##
113
+ # Retrieves ethnic category
114
+ #
115
+ # @return [String]
116
+ #
117
+ # @example
118
+ # Faker::Food.ethnic_category #=> "Indian cuisine"
119
+ #
120
+ # @faker.version next
121
+ def ethnic_category
122
+ fetch('food.ethnic_category')
123
+ end
111
124
  end
112
125
  end
113
126
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Hobby < Base
5
+ flexible :hobby
6
+
7
+ class << self
8
+ ##
9
+ # Retrieves a typical hobby activity.
10
+ #
11
+ # @return [String]
12
+ #
13
+ # @example
14
+ # Faker::Hobby.activity #=> "Cooking"
15
+ #
16
+ # @faker.version next
17
+ def activity
18
+ fetch('hobby.activity')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -200,8 +200,42 @@ module Faker
200
200
  "#{digits}-#{verification_code}"
201
201
  end
202
202
 
203
+ ##
204
+ # Produces a random Croatian ID number (OIB).
205
+ #
206
+ # @param international [Boolean] Specifies whether to add international prefix.
207
+ # @return [String]
208
+ #
209
+ # @example
210
+ # Faker::IDNumber.croatian_id #=> "88467617508"
211
+ # Faker::IDNumber.croatian_id(international: true) #=> "HR88467617508"
212
+ #
213
+ # @faker.version next
214
+ def croatian_id(international: false)
215
+ prefix = international ? 'HR' : ''
216
+ digits = Faker::Number.number(digits: 10).to_s
217
+ checksum_digit = croatian_id_checksum_digit(digits)
218
+
219
+ "#{prefix}#{digits}#{checksum_digit}"
220
+ end
221
+
203
222
  private
204
223
 
224
+ def croatian_id_checksum_digit(digits)
225
+ control_sum = 10
226
+
227
+ digits.chars.map(&:to_i).each do |digit|
228
+ control_sum += digit
229
+ control_sum %= 10
230
+ control_sum = 10 if control_sum.zero?
231
+ control_sum *= 2
232
+ control_sum %= 11
233
+ end
234
+
235
+ control_sum = 11 - control_sum
236
+ control_sum % 10
237
+ end
238
+
205
239
  def chilean_verification_code(digits)
206
240
  # First digit is multiplied by 3, second by 2, and so on
207
241
  multiplication_rule = [3, 2, 7, 6, 5, 4, 3, 2]
@@ -2,6 +2,18 @@
2
2
 
3
3
  module Faker
4
4
  class Internet < Base
5
+ # Private, Host, and Link-Local network address blocks as defined in https://en.wikipedia.org/wiki/IPv4#Special-use_addresses
6
+ PRIVATE_IPV4_ADDRESS_RANGES = [
7
+ [10..10, 0..255, 0..255, 1..255], # 10.0.0.0/8 - Used for local communications within a private network
8
+ [100..100, 64..127, 0..255, 1..255], # 100.64.0.0/10 - Shared address space for communications between an ISP and its subscribers
9
+ [127..127, 0..255, 0..255, 1..255], # 127.0.0.0/8 - Used for loopback addresses to the local host
10
+ [169..169, 254..254, 0..255, 1..255], # 169.254.0.0/16 - Used for link-local addresses between two hosts on a single link when
11
+ [172..172, 16..31, 0..255, 1..255], # 172.16.0.0/12 - Used for local communications within a private network
12
+ [192..192, 0..0, 0..0, 1..255], # 192.0.0.0/24 - IETF Protocol Assignments
13
+ [192..192, 168..168, 0..255, 1..255], # 192.168.0.0/16 - Used for local communications within a private network
14
+ [198..198, 18..19, 0..255, 1..255] # 198.18.0.0/15 - Used for benchmark testing of inter-network communications between subnets
15
+ ].each(&:freeze).freeze
16
+
5
17
  class << self
6
18
  ##
7
19
  # Returns the email address
@@ -34,7 +46,7 @@ module Faker
34
46
  end
35
47
 
36
48
  ##
37
- # Returns the email address with doamin either gmail.com, yahoo.com or hotmail.com
49
+ # Returns the email address with domain either gmail.com, yahoo.com or hotmail.com
38
50
  #
39
51
  # @return [String]
40
52
  #
@@ -80,10 +92,10 @@ module Faker
80
92
  #
81
93
  # @return [String]
82
94
  #
83
- # @param specifier [Integer, Range] When int value passed it returns the username longer than specifier. Max value can be 10^6
84
- # @param separator [Array]
95
+ # @param specifier [Integer, Range, String] When int value passed it returns the username longer than specifier. Max value can be 10^6
96
+ # @param separators [Array]
85
97
  #
86
- # @wxample
98
+ # @example
87
99
  # Faker::Internet.username(specifier: 10) #=> "lulu.goodwin"
88
100
  # Faker::Internet.username(specifier: 5..10) #=> "morris"
89
101
  # Faker::Internet.username(specifier: 5..10) #=> "berryberry"
@@ -227,8 +239,6 @@ module Faker
227
239
  end
228
240
  end
229
241
 
230
- # rubocop:disable Style/AsciiComments
231
-
232
242
  ##
233
243
  # Fixes ä, ö, ü, ß characters in string passed with ae, oe, ue, ss resp.
234
244
  #
@@ -247,7 +257,6 @@ module Faker
247
257
 
248
258
  Char.fix_umlauts(string)
249
259
  end
250
- # rubocop:enable Style/AsciiComments
251
260
 
252
261
  ##
253
262
  # Returns the domain word for internet
@@ -264,7 +273,7 @@ module Faker
264
273
  #
265
274
  # @return [String]
266
275
  #
267
- # @wxample
276
+ # @example
268
277
  # Faker::Internet.domain_suffix #=> "com"
269
278
  # Faker::Internet.domain_suffix #=> "biz"
270
279
  def domain_suffix
@@ -311,12 +320,7 @@ module Faker
311
320
  # @example
312
321
  # Faker::Internet.private_ip_v4_address #=> "127.120.80.42"
313
322
  def private_ip_v4_address
314
- addr = nil
315
- loop do
316
- addr = ip_v4_address
317
- break if private_net_checker[addr]
318
- end
319
- addr
323
+ sample(PRIVATE_IPV4_ADDRESS_RANGES).map { |range| rand(range) }.join('.')
320
324
  end
321
325
 
322
326
  ##
@@ -387,7 +391,7 @@ module Faker
387
391
  end
388
392
 
389
393
  ##
390
- # Returns lambda function to check address passed is reserverd or not
394
+ # Returns lambda function to check address passed is reserved or not
391
395
  #
392
396
  # @return [Lambda]
393
397
  #
@@ -479,7 +483,9 @@ module Faker
479
483
  end
480
484
 
481
485
  glue ||= sample(%w[- _])
482
- (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
486
+ return words.delete(',.').gsub(' ', glue).downcase unless words.nil?
487
+
488
+ sample(translate('faker.internet.slug'), 2).join(glue)
483
489
  end
484
490
 
485
491
  ##
@@ -559,6 +565,24 @@ module Faker
559
565
  s
560
566
  end
561
567
 
568
+ ##
569
+ # Produces a randomized hash of internet user details
570
+ # @example
571
+ # Faker::Internet.user #=> { username: 'alexie', email: 'alexie@example.net' }
572
+ #
573
+ # @example
574
+ # Faker::Internet.user('username', 'email', 'password') #=> { username: 'alexie', email: 'alexie@example.net', password: 'DtEf9P8wS31iMyC' }
575
+ #
576
+ # @return [hash]
577
+ #
578
+ # @faker.version next
579
+ def user(*args)
580
+ user_hash = {}
581
+ args = %w[username email] if args.empty?
582
+ args.each { |arg| user_hash[:"#{arg}"] = send(arg) }
583
+ user_hash
584
+ end
585
+
562
586
  alias user_name username
563
587
 
564
588
  private
@@ -82,8 +82,6 @@ module Faker
82
82
  Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric)
83
83
  end
84
84
 
85
- # rubocop:disable Style/AsciiComments
86
-
87
85
  ##
88
86
  # Generates the emoji
89
87
  #
@@ -97,8 +95,6 @@ module Faker
97
95
  def multibyte
98
96
  sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8')
99
97
  end
100
- # rubocop:enable Style/AsciiComments
101
-
102
98
  # rubocop:disable Metrics/ParameterLists
103
99
 
104
100
  ##
@@ -17,8 +17,6 @@ module Faker
17
17
  fetch('nation.nationality')
18
18
  end
19
19
 
20
- # rubocop:disable Style/AsciiComments
21
-
22
20
  ##
23
21
  # Produces a random national flag emoji.
24
22
  #
@@ -31,7 +29,6 @@ module Faker
31
29
  def flag
32
30
  sample(translate('faker.nation.flag')).pack('C*').force_encoding('utf-8')
33
31
  end
34
- # rubocop:enable Style/AsciiComments
35
32
 
36
33
  ##
37
34
  # Produces a random national language.
@@ -65,7 +65,7 @@ module Faker
65
65
  picture: image,
66
66
  gender: gender,
67
67
  birthday: Date.backward(days: 36_400).strftime('%Y-%m-%d'),
68
- local: 'en',
68
+ locale: 'en',
69
69
  hd: "#{Company.name.downcase}.com"
70
70
  },
71
71
  id_info: {
@@ -431,6 +431,50 @@ module Faker
431
431
  }
432
432
  end
433
433
 
434
+ ##
435
+ # Generate a mock Omniauth response from Auth0.
436
+ #
437
+ # @param name [String] A specific name to return in the response.
438
+ # @param email [String] A specific email to return in the response.
439
+ # @param uid [String] A specific UID to return in the response.
440
+ #
441
+ # @return [Hash] An auth hash in the format provided by omniauth-auth0.
442
+ #
443
+ # @faker.version next
444
+ def auth0(name: nil, email: nil, uid: nil)
445
+ uid ||= "auth0|#{Number.hexadecimal(digits: 24)}"
446
+ auth = Omniauth.new(name: name, email: email)
447
+ {
448
+ provider: 'auth0',
449
+ uid: uid,
450
+ info: {
451
+ name: uid,
452
+ nickname: auth.name,
453
+ email: auth.email,
454
+ image: image
455
+ },
456
+ credentials: {
457
+ expires_at: Time.forward.to_i,
458
+ expires: true,
459
+ token_type: 'Bearer',
460
+ id_token: Crypto.sha256,
461
+ token: Crypto.md5,
462
+ refresh_token: Crypto.md5
463
+ },
464
+ extra: {
465
+ raw_info: {
466
+ email: auth.email,
467
+ email_verified: true,
468
+ iss: 'https://auth0.com/',
469
+ sub: uid,
470
+ aud: 'Auth012345',
471
+ iat: Time.forward.to_i,
472
+ exp: Time.forward.to_i
473
+ }
474
+ }
475
+ }
476
+ end
477
+
434
478
  private
435
479
 
436
480
  def gender
@@ -8,7 +8,7 @@ module Faker
8
8
  # rubocop:disable Metrics/ParameterLists
9
9
 
10
10
  ##
11
- # Produces a random placeholder image from https://placehold.it.
11
+ # Produces a random placeholder image from https://via.placeholder.com.
12
12
  #
13
13
  # @param size [String] Specifies the image's size, dimensions separated by 'x'.
14
14
  # @param format [String] Specifies the image's extension.
@@ -19,13 +19,13 @@ module Faker
19
19
  #
20
20
  # @example
21
21
  # # Keyword arguments: size, format, background_color, text_color, text
22
- # Faker::Placeholdit.image #=> "https://placehold.it/300x300.png"
23
- # Faker::Placeholdit.image(size: '50x50') #=> "https://placehold.it/50x50.png"
24
- # Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://placehold.it/50x50.jpg"
25
- # Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://placehold.it/50x50.gif/ffffff"
26
- # Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://placehold.it/50x50.jpeg/39eba7"
27
- # Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://placehold.it/50x50.jpeg/ffffff/000"
28
- # Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://placehold.it/50x50.jpg/ffffff/000?text=Some Custom Text"
22
+ # Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
23
+ # Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
24
+ # Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
25
+ # Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
26
+ # Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
27
+ # Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
28
+ # Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://via.placeholder.com/50x50.jpg/ffffff/000?text=Some Custom Text"
29
29
  #
30
30
  # @faker.version 1.6.0
31
31
  def image(legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_background_color = NOT_GIVEN, legacy_text_color = NOT_GIVEN, legacy_text = NOT_GIVEN, size: '300x300', format: 'png', background_color: nil, text_color: nil, text: nil)
@@ -45,7 +45,7 @@ module Faker
45
45
  raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
46
46
  raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
47
47
 
48
- image_url = "https://placehold.it/#{size}.#{format}"
48
+ image_url = "https://via.placeholder.com/#{size}.#{format}"
49
49
  image_url += "/#{background_color}" if background_color
50
50
  image_url += "/#{text_color}" if text_color
51
51
  image_url += "?text=#{text}" if text
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ module Religion
5
+ end
6
+ end
@@ -3,6 +3,47 @@
3
3
  module Faker
4
4
  class Science < Base
5
5
  class << self
6
+ BRANCHES = {
7
+ empirical: %i[empirical_natural_basic empirical_natural_applied empirical_social_basic empirical_social_applied],
8
+ formal: %i[formal_basic formal_applied],
9
+ natural: %i[empirical_natural_basic empirical_natural_applied],
10
+ social: %i[empirical_social_basic empirical_social_applied],
11
+ basic: %i[empirical_natural_basic empirical_social_basic formal_basic],
12
+ applied: %i[empirical_natural_applied empirical_social_applied formal_applied]
13
+ }.freeze
14
+
15
+ ##
16
+ # Produces a name of a science
17
+ # You can optionally filter by specifying one or more of the following:
18
+ # `:empirical, :formal, :natural, :social, :basic, :applied`
19
+ # @see https://en.wikipedia.org/wiki/Science#Branches_of_science
20
+ # @see Faker::Educator.subject
21
+ #
22
+ # @param branches [Array<Symbol>]
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faker::Science.science #=> "Space science"
27
+ # Faker::Science.science(:natural, :applied) #=> "Engineering"
28
+ # Faker::Science.science(:formal, :applied) #=> "Computer Science"
29
+ #
30
+ # @faker.version next
31
+ def science(*branches)
32
+ selected = BRANCHES.values.flatten.uniq
33
+ branches.each do |branch|
34
+ selected &= BRANCHES[branch] if BRANCHES.key? branch
35
+ end
36
+
37
+ raise ArgumentError, 'Filters do not match any sciences' if selected.empty?
38
+
39
+ sciences = []
40
+ selected.each do |branch|
41
+ sciences += translate("faker.science.branch.#{branch}")
42
+ end
43
+
44
+ sample(sciences)
45
+ end
46
+
6
47
  ##
7
48
  # Produces the name of a element.
8
49
  #
@@ -29,6 +70,32 @@ module Faker
29
70
  fetch('science.element_symbol')
30
71
  end
31
72
 
73
+ ##
74
+ # Produces the state of an element.
75
+ #
76
+ # @return [String]
77
+ #
78
+ # @example
79
+ # Faker::Science.element_state #=> "Liquid"
80
+ #
81
+ # @faker.version next
82
+ def element_state
83
+ fetch('science.element_state')
84
+ end
85
+
86
+ ##
87
+ # Produces the subcategory of an element.
88
+ #
89
+ # @return [String]
90
+ #
91
+ # @example
92
+ # Faker::Science.element_subcategory #=> "Reactive nonmetal"
93
+ #
94
+ # @faker.version next
95
+ def element_subcategory
96
+ fetch('science.element_subcategory')
97
+ end
98
+
32
99
  ##
33
100
  # Produces the name of a scientist.
34
101
  #
@@ -41,6 +108,47 @@ module Faker
41
108
  def scientist
42
109
  fetch('science.scientist')
43
110
  end
111
+
112
+ ##
113
+ # Produces a scientifically sounding word
114
+ #
115
+ # @return [String]
116
+ #
117
+ # @example
118
+ # Faker::Science.modifier #=> "Quantum"
119
+ # Faker::Science.modifier #=> "Superconductive"
120
+ #
121
+ # @faker.version next
122
+ def modifier
123
+ fetch('science.modifier')
124
+ end
125
+
126
+ ##
127
+ # Produces the name of a scientific tool.
128
+ # By default it uses a science word modifier to generate more diverse data, which can be disabled.
129
+ #
130
+ # @param simple [Boolean] Whether to generate simple realistic tool names, (no Q-word).
131
+ # @return [String]
132
+ #
133
+ # @example
134
+ # Faker::Science.tool #=> "Superconductive Microcentrifuge"
135
+ # Faker::Science.tool #=> "Portable Cryostat"
136
+ # Faker::Science.tool #=> "Quantum Spectrophotometer"
137
+ # Faker::Science.tool(simple: true) #=> "Microcentrifuge"
138
+ #
139
+ # @faker.version next
140
+ def tool(simple: false)
141
+ tool = fetch('science.tool')
142
+ return tool if simple
143
+
144
+ # Makes sure the modifier are different
145
+ loop do
146
+ modifier = self.modifier
147
+ break unless tool.start_with?(modifier)
148
+ end
149
+
150
+ "#{modifier} #{tool}"
151
+ end
44
152
  end
45
153
  end
46
154
  end
@@ -3,8 +3,6 @@
3
3
  module Faker
4
4
  class String < Base
5
5
  class << self
6
- # rubocop:disable Style/AsciiComments
7
-
8
6
  ##
9
7
  # Produces a random UTF-8 string with optional nested length selectors.
10
8
  #
@@ -26,7 +24,6 @@ module Faker
26
24
 
27
25
  utf8string select_a length
28
26
  end
29
- # rubocop:enable Style/AsciiComments
30
27
 
31
28
  private
32
29
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Tea < Base
5
+ flexible :tea
6
+
7
+ class << self
8
+ ##
9
+ # Produces a random variety or blend of tea.
10
+ #
11
+ # @param type [String, nil] the type of tea to query for (valid types: 'Black', 'Green', 'Oolong', 'White', and 'Herbal')
12
+ # @return [String] a variety of tea
13
+ #
14
+ # @example
15
+ # Faker::Tea.variety
16
+ # #=> "Earl Grey"
17
+ #
18
+ # @example
19
+ # Faker::Tea.variety(type: 'Green')
20
+ # #=> "Jasmine"
21
+ # @faker.version next
22
+ def variety(type: nil)
23
+ type ||= fetch('tea.type')
24
+ fetch "tea.variety.#{type.downcase}"
25
+ end
26
+
27
+ ##
28
+ # Produces a random type of tea.
29
+ #
30
+ # @return [String] a type of tea
31
+ #
32
+ # @example
33
+ # Faker::Tea.type
34
+ # #=> "Green"
35
+ # @faker.version next
36
+ def type
37
+ fetch 'tea.type'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -14,7 +14,6 @@ module Faker
14
14
 
15
15
  class << self
16
16
  # rubocop:disable Metrics/ParameterLists
17
- # rubocop:disable Style/AsciiComments
18
17
 
19
18
  ##
20
19
  # Produce a random time between two times.
@@ -51,7 +50,6 @@ module Faker
51
50
  time = Faker::Base.rand_in_range(from, to)
52
51
  time_with_format(time, format)
53
52
  end
54
- # rubocop:enable Style/AsciiComments
55
53
 
56
54
  ##
57
55
  # Produce a random time between two dates.
@@ -4,6 +4,19 @@ module Faker
4
4
  class Games
5
5
  class Dota < Base
6
6
  class << self
7
+ ##
8
+ # Produces the name of a building from Dota.
9
+ #
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::Games::Dota.building #=> "Tower"
14
+ #
15
+ # @faker.version 1.9.0
16
+ def building
17
+ fetch('games.dota.building')
18
+ end
19
+
7
20
  ##
8
21
  # Produces the name of a hero from Dota.
9
22
  #
@@ -81,6 +81,45 @@ module Faker
81
81
  def monster
82
82
  fetch('games.witcher.monsters')
83
83
  end
84
+
85
+ ##
86
+ # Produces the name of a sign from The Witcher.
87
+ #
88
+ # @return [String]
89
+ #
90
+ # @example
91
+ # Faker::Games::Witcher.sign #=> "Igni"
92
+ #
93
+ # @faker.version 2.18.0
94
+ def sign
95
+ fetch('games.witcher.signs')
96
+ end
97
+
98
+ ##
99
+ # Produces the name of a potion from The Witcher.
100
+ #
101
+ # @return [String]
102
+ #
103
+ # @example
104
+ # Faker::Games::Witcher.potion #=> "Gadwall"
105
+ #
106
+ # @faker.version 2.18.0
107
+ def potion
108
+ fetch('games.witcher.potions')
109
+ end
110
+
111
+ ##
112
+ # Produces the name of a book from The Witcher.
113
+ #
114
+ # @return [String]
115
+ #
116
+ # @example
117
+ # Faker::Games::Witcher.book #=> "Sword of Destiny"
118
+ #
119
+ # @faker.version 2.18.0
120
+ def book
121
+ fetch('games.witcher.books')
122
+ end
84
123
  end
85
124
  end
86
125
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class JapaneseMedia
5
+ class FmaBrotherhood < Base
6
+ class << self
7
+ ##
8
+ # Produces a character from FmaBrotherhood.
9
+ #
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::JapaneseMedia::FmaBrotherhood.character #=> "Edward Elric"
14
+ #
15
+ # @faker.version next
16
+ def character
17
+ fetch('fma_brotherhood.characters')
18
+ end
19
+
20
+ ##
21
+ # Produces a cities from FmaBrotherhood.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faker::JapaneseMedia::FmaBrotherhood.city #=> "Central City"
27
+ #
28
+ # @faker.version next
29
+ def city
30
+ fetch('fma_brotherhood.cities')
31
+ end
32
+
33
+ ##
34
+ # Produces a country from FmaBrotherhood.
35
+ #
36
+ # @return [String]
37
+ #
38
+ # @example
39
+ # Faker::JapaneseMedia::FmaBrotherhood.country #=> "Xing"
40
+ #
41
+ # @faker.version next
42
+ def country
43
+ fetch('fma_brotherhood.countries')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end