faker 2.10.0 → 2.13.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 (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +265 -0
  3. data/README.md +14 -2
  4. data/lib/faker.rb +20 -10
  5. data/lib/faker/default/address.rb +31 -1
  6. data/lib/faker/default/bank.rb +79 -0
  7. data/lib/faker/default/blood.rb +48 -0
  8. data/lib/faker/default/business.rb +1 -1
  9. data/lib/faker/default/cannabis.rb +80 -0
  10. data/lib/faker/default/chile_rut.rb +44 -1
  11. data/lib/faker/default/commerce.rb +73 -10
  12. data/lib/faker/default/company.rb +276 -7
  13. data/lib/faker/default/compass.rb +135 -0
  14. data/lib/faker/default/computer.rb +63 -0
  15. data/lib/faker/default/construction.rb +54 -0
  16. data/lib/faker/default/cosmere.rb +90 -0
  17. data/lib/faker/default/crypto_coin.rb +45 -0
  18. data/lib/faker/default/date.rb +16 -12
  19. data/lib/faker/default/dc_comics.rb +45 -0
  20. data/lib/faker/default/driving_licence.rb +42 -0
  21. data/lib/faker/default/file.rb +51 -2
  22. data/lib/faker/default/finance.rb +24 -0
  23. data/lib/faker/default/funny_name.rb +45 -0
  24. data/lib/faker/default/gender.rb +1 -1
  25. data/lib/faker/default/hipster.rb +94 -0
  26. data/lib/faker/default/id_number.rb +86 -0
  27. data/lib/faker/default/internet.rb +64 -7
  28. data/lib/faker/default/internet_http.rb +48 -0
  29. data/lib/faker/default/invoice.rb +32 -5
  30. data/lib/faker/default/json.rb +55 -0
  31. data/lib/faker/default/lorem.rb +1 -1
  32. data/lib/faker/default/lorem_flickr.rb +65 -0
  33. data/lib/faker/default/lorem_pixel.rb +22 -0
  34. data/lib/faker/default/markdown.rb +89 -0
  35. data/lib/faker/default/measurement.rb +90 -0
  36. data/lib/faker/default/name.rb +98 -0
  37. data/lib/faker/default/nhs.rb +19 -0
  38. data/lib/faker/default/number.rb +5 -7
  39. data/lib/faker/default/omniauth.rb +105 -52
  40. data/lib/faker/default/phone_number.rb +88 -5
  41. data/lib/faker/default/placeholdit.rb +21 -0
  42. data/lib/faker/default/slack_emoji.rb +81 -0
  43. data/lib/faker/default/south_africa.rb +90 -0
  44. data/lib/faker/default/string.rb +19 -3
  45. data/lib/faker/default/stripe.rb +61 -0
  46. data/lib/faker/default/twitter.rb +35 -0
  47. data/lib/faker/default/types.rb +80 -0
  48. data/lib/faker/default/university.rb +45 -0
  49. data/lib/faker/default/vehicle.rb +184 -4
  50. data/lib/faker/default/verb.rb +45 -0
  51. data/lib/faker/default/world_cup.rb +4 -4
  52. data/lib/faker/games/control.rb +113 -0
  53. data/lib/faker/games/dnd.rb +61 -0
  54. data/lib/faker/games/heroes_of_the_storm.rb +16 -5
  55. data/lib/faker/games/minecraft.rb +48 -0
  56. data/lib/faker/games/warhammer_fantasy.rb +74 -0
  57. data/lib/faker/movies/departed.rb +49 -0
  58. data/lib/faker/movies/movie.rb +13 -0
  59. data/lib/faker/music/pearl_jam.rb +50 -0
  60. data/lib/faker/music/phish.rb +27 -1
  61. data/lib/faker/music/prince.rb +64 -0
  62. data/lib/faker/music/rush.rb +37 -0
  63. data/lib/faker/music/show.rb +49 -0
  64. data/lib/faker/quotes/chiquito.rb +80 -0
  65. data/lib/faker/quotes/quote.rb +54 -1
  66. data/lib/faker/quotes/rajnikanth.rb +26 -0
  67. data/lib/faker/quotes/shakespeare.rb +36 -0
  68. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
  69. data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
  70. data/lib/faker/tv_shows/dr_who.rb +1 -1
  71. data/lib/faker/tv_shows/futurama.rb +65 -0
  72. data/lib/faker/tv_shows/simpsons.rb +14 -0
  73. data/lib/faker/tv_shows/suits.rb +37 -0
  74. data/lib/faker/version.rb +1 -1
  75. data/lib/helpers/base58.rb +1 -1
  76. data/lib/helpers/char.rb +22 -27
  77. data/lib/helpers/unique_generator.rb +4 -0
  78. data/lib/locales/bg.yml +2 -2
  79. data/lib/locales/ca.yml +0 -8
  80. data/lib/locales/da-DK.yml +3 -3
  81. data/lib/locales/de-CH.yml +1693 -0
  82. data/lib/locales/en-AU.yml +44 -10
  83. data/lib/locales/en-CA.yml +2 -0
  84. data/lib/locales/en-GB.yml +1 -1
  85. data/lib/locales/en-NEP.yml +1 -1
  86. data/lib/locales/en-NZ.yml +2 -0
  87. data/lib/locales/en-US.yml +29 -3
  88. data/lib/locales/en-ZA.yml +1 -1
  89. data/lib/locales/en/address.yml +2 -0
  90. data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
  91. data/lib/locales/en/bank.yml +1 -1
  92. data/lib/locales/en/big_bang_theory.yml +38 -0
  93. data/lib/locales/en/blood.yml +13 -0
  94. data/lib/locales/en/chiquito.yml +64 -0
  95. data/lib/locales/en/color.yml +1 -1
  96. data/lib/locales/en/computer.yml +36 -0
  97. data/lib/locales/en/control.yml +247 -0
  98. data/lib/locales/en/departed.yml +50 -0
  99. data/lib/locales/en/dnd.yml +54 -0
  100. data/lib/locales/en/futurama.yml +344 -0
  101. data/lib/locales/en/heroes_of_the_storm.yml +2 -2
  102. data/lib/locales/en/house.yml +1 -1
  103. data/lib/locales/en/minecraft.yml +390 -0
  104. data/lib/locales/en/movie.yml +192 -1
  105. data/lib/locales/en/name.yml +4 -3
  106. data/lib/locales/en/one_piece.yml +2 -2
  107. data/lib/locales/en/pearl_jam.yml +213 -0
  108. data/lib/locales/en/phish.yml +392 -1
  109. data/lib/locales/en/prince.yml +227 -0
  110. data/lib/locales/en/rajnikanth.yml +77 -0
  111. data/lib/locales/en/rush.yml +32 -0
  112. data/lib/locales/en/shakespeare.yml +3 -3
  113. data/lib/locales/en/show.yml +597 -0
  114. data/lib/locales/en/simpsons.yml +668 -0
  115. data/lib/locales/en/star_wars.yml +568 -220
  116. data/lib/locales/en/stripe.yml +3 -3
  117. data/lib/locales/en/suits.yml +45 -0
  118. data/lib/locales/en/warhammer_fantasy.yml +582 -0
  119. data/lib/locales/es-MX.yml +3 -0
  120. data/lib/locales/fr-CA.yml +7 -4
  121. data/lib/locales/fr-CH.yml +1 -1
  122. data/lib/locales/fr.yml +5 -4
  123. data/lib/locales/hy.yml +1 -6
  124. data/lib/locales/id.yml +2 -1
  125. data/lib/locales/ja.yml +1 -1
  126. data/lib/locales/ko.yml +82 -0
  127. data/lib/locales/pt-BR.yml +1 -0
  128. data/lib/locales/pt.yml +2 -2
  129. data/lib/locales/uk.yml +5 -5
  130. data/lib/locales/zh-CN.yml +1 -1
  131. data/lib/locales/zh-TW.yml +1 -1
  132. metadata +52 -19
@@ -9,11 +9,14 @@ module Faker
9
9
  keywords << :separators if legacy_separators != NOT_GIVEN
10
10
  end
11
11
 
12
- if separators
13
- [username(specifier: name, separators: separators), domain_name(domain: domain)].join('@')
14
- else
15
- [username(specifier: name), domain_name(domain: domain)].join('@')
16
- end
12
+ local_part = if separators
13
+ username(specifier: name, separators: separators)
14
+ else
15
+ username(specifier: name)
16
+ end
17
+
18
+ sanitized_local_part = sanitize_email_local_part(local_part)
19
+ construct_email(sanitized_local_part, domain_name(domain: domain))
17
20
  end
18
21
 
19
22
  def free_email(legacy_name = NOT_GIVEN, name: nil)
@@ -21,7 +24,10 @@ module Faker
21
24
  keywords << :name if legacy_name != NOT_GIVEN
22
25
  end
23
26
 
24
- [username(specifier: name), fetch('internet.free_email')].join('@')
27
+ construct_email(
28
+ sanitize_email_local_part(username(specifier: name)),
29
+ fetch('internet.free_email')
30
+ )
25
31
  end
26
32
 
27
33
  def safe_email(legacy_name = NOT_GIVEN, name: nil)
@@ -29,7 +35,10 @@ module Faker
29
35
  keywords << :name if legacy_name != NOT_GIVEN
30
36
  end
31
37
 
32
- [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
38
+ construct_email(
39
+ sanitize_email_local_part(username(specifier: name)),
40
+ 'example.' + sample(%w[org com net])
41
+ )
33
42
  end
34
43
 
35
44
  def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
@@ -295,7 +304,55 @@ module Faker
295
304
  '%08x-%04x-%04x-%04x-%04x%08x' % ary # rubocop:disable Style/FormatString
296
305
  end
297
306
 
307
+ ##
308
+ # Produces a random string of alphabetic characters, (no digits)
309
+ #
310
+ # @param length [Integer] The length of the string to generate
311
+ # @param padding [Boolean] Toggles if a final equal '=' will be added.
312
+ # @param urlsafe [Boolean] Toggles charset to '-' and '_' instead of '+' and '/'.
313
+ #
314
+ # @return [String]
315
+ #
316
+ # @example
317
+ # Faker::Internet.base64
318
+ # #=> "r_hbZ2DSD-ZACzZT"
319
+ # @example
320
+ # Faker::Internet.base64(length: 4, padding: true, urlsafe: false)
321
+ # #=> "x1/R="
322
+ #
323
+ # @faker.version 2.11.0
324
+ def base64(length: 16, padding: false, urlsafe: true)
325
+ char_range = [
326
+ Array('0'..'9'),
327
+ Array('A'..'Z'),
328
+ Array('a'..'z'),
329
+ urlsafe ? %w[- _] : %w[+ /]
330
+ ].flatten
331
+ s = Array.new(length) { sample(char_range) }.join
332
+ s += '=' if padding
333
+ s
334
+ end
335
+
298
336
  alias user_name username
337
+
338
+ private
339
+
340
+ def sanitize_email_local_part(local_part)
341
+ char_range = [
342
+ Array('0'..'9'),
343
+ Array('A'..'Z'),
344
+ Array('a'..'z'),
345
+ "!#$%&'*+-/=?^_`{|}~.".split(//)
346
+ ].flatten
347
+
348
+ local_part.split(//).map do |char|
349
+ char_range.include?(char) ? char : '#'
350
+ end.join
351
+ end
352
+
353
+ def construct_email(local_part, domain_name)
354
+ [local_part, domain_name].join('@')
355
+ end
299
356
  end
300
357
  end
301
358
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Internet
5
+ class HTTP < Base
6
+ STATUS_CODES = {
7
+ information: [100, 101, 102, 103],
8
+ successful: [200, 201, 202, 203, 204, 205, 206, 207, 208, 226],
9
+ redirect: [300, 301, 302, 303, 304, 305, 306, 307, 308],
10
+ client_error: [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412,
11
+ 413, 414, 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428,
12
+ 429, 431, 451],
13
+ server_error: [500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511]
14
+ }.freeze
15
+
16
+ STATUS_CODES_GROUPS = STATUS_CODES.keys.freeze
17
+
18
+ class << self
19
+ ##
20
+ # Produces an HTTP status code
21
+ #
22
+ # @return [Integer]
23
+ #
24
+ # @example
25
+ # Faker::Internet::HTTP.status_code #=> 418
26
+ # @example
27
+ # Faker::Internet::HTTP.status_code(group: :information) #=> 102
28
+ # @example
29
+ # Faker::Internet::HTTP.status_code(group: :successful) #=> 200
30
+ # @example
31
+ # Faker::Internet::HTTP.status_code(group: :redirect) #=> 306
32
+ # @example
33
+ # Faker::Internet::HTTP.status_code(group: :client_error) #=> 451
34
+ # @example
35
+ # Faker::Internet::HTTP.status_code(group: :server_error) #=> 502
36
+ #
37
+ # @faker.version 2.13.0
38
+ def status_code(group: nil)
39
+ return STATUS_CODES[STATUS_CODES_GROUPS.sample].sample unless group
40
+
41
+ raise ArgumentError, 'Invalid HTTP status code group' unless STATUS_CODES_GROUPS.include?(group)
42
+
43
+ STATUS_CODES[group].sample
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -5,7 +5,18 @@ module Faker
5
5
  flexible :invoice
6
6
 
7
7
  class << self
8
- # Generate random amount between values with 2 decimals
8
+ ##
9
+ # Produces a random amount between values with 2 decimals
10
+ #
11
+ # @param from [Integer] Specifies lower limit.
12
+ # @param to [Integer] Specifies upper limit.
13
+ # @return [Integer]
14
+ #
15
+ # @example
16
+ # Faker::Finance.amount_between #=> 0
17
+ # Faker::Finance.amount_between(0, 10) #=> 4.33
18
+ #
19
+ # @faker.version 1.9.0
9
20
  def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0)
10
21
  warn_for_deprecated_arguments do |keywords|
11
22
  keywords << :from if legacy_from != NOT_GIVEN
@@ -15,8 +26,16 @@ module Faker
15
26
  Faker::Base.rand_in_range(from, to).round(2)
16
27
  end
17
28
 
18
- # International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
19
- # ref is optional so that we can create unit tests
29
+ ##
30
+ # Produces a random valid reference accoring to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
31
+ #
32
+ # @param ref [String] Specifies reference base.
33
+ # @return [String]
34
+ #
35
+ # @example
36
+ # Faker::Invoice.creditor_reference #=> "RF34118592570724925498"
37
+ #
38
+ # @faker.version 1.9.0
20
39
  def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
21
40
  warn_for_deprecated_arguments do |keywords|
22
41
  keywords << :ref if legacy_ref != NOT_GIVEN
@@ -27,8 +46,16 @@ module Faker
27
46
  'RF' + iban_checksum('RF', ref) + ref
28
47
  end
29
48
 
30
- # Payment references have some rules in certain countries
31
- # ref is optional so that we can create unit tests
49
+ ##
50
+ # Produces a random valid reference.
51
+ #
52
+ # @param ref [String] Specifies reference base.
53
+ # @return [String]
54
+ #
55
+ # @example
56
+ # Faker::Invoice.reference #=> "45656646957845"
57
+ #
58
+ # @faker.version 1.9.0
32
59
  def reference(legacy_ref = NOT_GIVEN, ref: '')
33
60
  warn_for_deprecated_arguments do |keywords|
34
61
  keywords << :ref if legacy_ref != NOT_GIVEN
@@ -3,6 +3,23 @@ module Faker
3
3
  require 'json'
4
4
 
5
5
  class << self
6
+ ##
7
+ # Produces a random simple JSON formatted string.
8
+ #
9
+ # @param width [Integer] Specifies the number of key-value pairs.
10
+ # @param options [Hash] Specifies a Faker gem class to use for keys and for values, respectably. options_hash = {key: Class.method, value: Class.method}
11
+ # @return [Hash{String => String}]
12
+ #
13
+ # @example
14
+ # Faker::Json.shallow_json(width: 3, options: { key: 'RockBand.name', value: 'Seinfeld.quote' }) # =>
15
+ # {"Parliament Funkadelic":"They're real, and they're spectacular.",
16
+ # "Fleetwood Mac":"I'm not a lesbian. I hate men, but I'm not a lesbian.",
17
+ # "The Roots":"It became very clear to me sitting out there today that every decision
18
+ # I've made in my entire life has been wrong. My life is the complete opposite of everything
19
+ # I want it to be. Every instinct I have, in every aspect of life, be it something to wear,
20
+ # something to eat - it's all been wrong."}
21
+ #
22
+ # @faker.version 1.9.2
6
23
  def shallow_json(legacy_width = NOT_GIVEN, legacy_options = NOT_GIVEN, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
7
24
  warn_for_deprecated_arguments do |keywords|
8
25
  keywords << :width if legacy_width != NOT_GIVEN
@@ -16,6 +33,44 @@ module Faker
16
33
  JSON.generate(hash)
17
34
  end
18
35
 
36
+ ##
37
+ # Produces a random nested JSON formatted string that can take JSON as an additional argument.
38
+ #
39
+ # @param json [Hash{String => String}] Specifies a Json.shallow_json and uses its keys as keys of the nested JSON.
40
+ # @param width [Integer] Specifies the number of nested key-value pairs.
41
+ # @param options [Hash] Specifies a Faker gem class to use for nested keys and for values, respectably. options_hash = {key: Class.method, value: Class.method}
42
+ # @return [Hash{String => String}]
43
+ #
44
+ # @example
45
+ # json = Faker::Json.shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.last_name' })
46
+ # puts json # =>
47
+ # {"Alisha":"Olson","Everardo":"DuBuque","Bridgette":"Turner"}
48
+ #
49
+ # json2 = Faker::Json.add_depth_to_json(json: json, width: 2, options: { key: 'Name.first_name', value: 'Name.last_name' })
50
+ # puts json2 # =>
51
+ # {"Alisha":{"Daisy":"Trantow","Oda":"Haag"},
52
+ # "Everardo":{"Javier":"Marvin","Eliseo":"Schuppe"},
53
+ # "Bridgette":{"Jorge":"Kertzmann","Lelah":"MacGyver"}}
54
+ #
55
+ # json3 = Faker::Json.add_depth_to_json(json: json2, width: 4, options: { key: 'Name.first_name', value: 'Name.last_name' })
56
+ # puts json3 # =>
57
+ # {"Alisha":
58
+ # {"Daisy":
59
+ # {"Bulah":"Wunsch","Cristian":"Champlin","Lester":"Bartoletti","Greg":"Jacobson"},
60
+ # "Oda":
61
+ # {"Salvatore":"Kuhlman","Aubree":"Okuneva","Larry":"Schmitt","Velva":"Gibson"}},
62
+ # "Everardo":
63
+ # {"Javier":
64
+ # {"Eduardo":"Orn","Laila":"Kub","Thad":"Legros","Dion":"Wilderman"},
65
+ # "Eliseo":
66
+ # {"Olin":"Hilpert","Marisa":"Greenfelder","Karlee":"Schmitt","Judd":"Larkin"}},
67
+ # "Bridgette":
68
+ # {"Jorge":
69
+ # {"Eloy":"Pfeffer","Kody":"Hansen","Paxton":"Lubowitz","Abe":"Lesch"},
70
+ # "Lelah":
71
+ # {"Rick":"Wiza","Bonita":"Bayer","Gardner":"Auer","Felicity":"Abbott"}}}
72
+ #
73
+ # @faker.version 1.9.2
19
74
  # rubocop:disable Metrics/ParameterLists
20
75
  def add_depth_to_json(legacy_json = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_options = NOT_GIVEN, json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
21
76
  # rubocop:enable Metrics/ParameterLists
@@ -64,7 +64,7 @@ module Faker
64
64
  keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN
65
65
  end
66
66
 
67
- words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(' ').capitalize + locale_period
67
+ words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(locale_space).capitalize + locale_period
68
68
  end
69
69
 
70
70
  def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
@@ -5,6 +5,22 @@ module Faker
5
5
  class << self
6
6
  SUPPORTED_COLORIZATIONS = %w[red green blue].freeze
7
7
 
8
+ ##
9
+ # Produces a random image URL from loremflickr.com.
10
+ #
11
+ # @param size [String] Specifies the size of image to generate.
12
+ # @param search_terms [Array<String>] Adds search terms to the image URL.
13
+ # @param match_all [Boolean] Add "all" as part of the URL.
14
+ # @return [String]
15
+ #
16
+ # @example
17
+ # Faker::LoremFlickr.image #=> "https://loremflickr.com/300/300"
18
+ # Faker::LoremFlickr.image(size: "50x60") #=> "https://loremflickr.com/50/60"
19
+ # Faker::LoremFlickr.image(size: "50x60", search_terms: ['sports']) #=> "https://loremflickr.com/50/60/sports"
20
+ # Faker::LoremFlickr.image(size: "50x60", search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/50/60/sports,fitness"
21
+ # Faker::LoremFlickr.image(size: "50x60", search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/50/60/sports,fitness/all"
22
+ #
23
+ # @faker.version 1.9.0
8
24
  # rubocop:disable Metrics/ParameterLists
9
25
  def image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: [], match_all: false)
10
26
  # rubocop:enable Metrics/ParameterLists
@@ -17,6 +33,22 @@ module Faker
17
33
  build_url(size, nil, search_terms, match_all)
18
34
  end
19
35
 
36
+ ##
37
+ # Produces a random grayscale image URL from loremflickr.com.
38
+ #
39
+ # @param size [String] Specifies the size of image to generate.
40
+ # @param search_terms [Array<String>] Adds search terms to the image URL.
41
+ # @param match_all [Boolean] Add "all" as part of the URL.
42
+ # @return [String]
43
+ #
44
+ # @example
45
+ # Faker::LoremFlickr.grayscale_image #=> "https://loremflickr.com/g/300/300/all"
46
+ # Faker::LoremFlickr.grayscale_image(size: "50x60") #=> "https://loremflickr.com/g/50/60/all"
47
+ # Faker::LoremFlickr.grayscale_image(size: "50x60", search_terms: ['sports']) #=> "https://loremflickr.com/g/50/60/sports"
48
+ # Faker::LoremFlickr.grayscale_image(size: "50x60", search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/50/60/g/sports,fitness"
49
+ # Faker::LoremFlickr.grayscale_image(size: "50x60", search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/g/50/60/sports,fitness/all"
50
+ #
51
+ # @faker.version 1.9.0
20
52
  # rubocop:disable Metrics/ParameterLists
21
53
  def grayscale_image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: ['all'], match_all: false)
22
54
  # rubocop:enable Metrics/ParameterLists
@@ -31,6 +63,22 @@ module Faker
31
63
  build_url(size, 'g', search_terms, match_all)
32
64
  end
33
65
 
66
+ ##
67
+ # Produces a random pixelated image URL from loremflickr.com.
68
+ #
69
+ # @param size [String] Specifies the size of image to generate.
70
+ # @param search_terms [Array<String>] Adds search terms to the image URL.
71
+ # @param match_all [Boolean] Add "all" as part of the URL.
72
+ # @return [String]
73
+ #
74
+ # @example
75
+ # Faker::LoremFlickr.pixelated_image #=> "https://loremflickr.com/p/300/300/all"
76
+ # Faker::LoremFlickr.pixelated_image(size: "50x60") #=> "https://loremflickr.com/p/50/60/all"
77
+ # Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports']) #=> "https://loremflickr.com/p/50/60/sports"
78
+ # Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/p/50/60/sports,fitness"
79
+ # Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/p/50/60/sports,fitness/all"
80
+ #
81
+ # @faker.version 1.9.0
34
82
  # rubocop:disable Metrics/ParameterLists
35
83
  def pixelated_image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: ['all'], match_all: false)
36
84
  # rubocop:enable Metrics/ParameterLists
@@ -45,6 +93,23 @@ module Faker
45
93
  build_url(size, 'p', search_terms, match_all)
46
94
  end
47
95
 
96
+ ##
97
+ # Produces a random colorized image URL from loremflickr.com.
98
+ #
99
+ # @param size [String] Specifies the size of image to generate.
100
+ # @param color [String] Specifies the color of image to generate.
101
+ # @param search_terms [Array<String>] Adds search terms to the image URL.
102
+ # @param match_all [Boolean] Add "all" as part of the URL.
103
+ # @return [String]
104
+ #
105
+ # @example
106
+ # Faker::LoremFlickr.image #=> "https://loremflickr.com/red/300/300/all"
107
+ # Faker::LoremFlickr.image(size: "50x60", color: 'blue') #=> "https://loremflickr.com/blue/50/60/all"
108
+ # Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports']) #=> "https://loremflickr.com/blue/50/60/sports"
109
+ # Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/blue/50/60/sports,fitness"
110
+ # Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/blue/50/60/sports,fitness/all"
111
+ #
112
+ # @faker.version 1.9.0
48
113
  # rubocop:disable Metrics/ParameterLists
49
114
  def colorized_image(legacy_size = NOT_GIVEN, legacy_color = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', color: 'red', search_terms: ['all'], match_all: false)
50
115
  # rubocop:enable Metrics/ParameterLists
@@ -17,6 +17,28 @@ module Faker
17
17
  technics
18
18
  transport].freeze
19
19
 
20
+ ##
21
+ # Produces a random image URL from lorempixel.com.
22
+ #
23
+ # @param size [String] Specifies the size of image to generate.
24
+ # @param is_gray [Boolean] Determines if the image is gray.
25
+ # @param category [Symbol] Adds the category of the generated image to the URL.
26
+ # @param number [Integer] Adds a number as part of the URL.
27
+ # @param text [Integer] Adds dummy text as part of the URL.
28
+ # @param secure [Boolean] Changes the image URL between http and https.
29
+ # @return [String]
30
+ #
31
+ # @example
32
+ # Faker::LoremPixel.image #=> "https://lorempixel.com/300/300"
33
+ # Faker::LoremPixel.image(size: "50x60") #=> "https://lorempixel.com/50/60"
34
+ # Faker::LoremPixel.image(size: "50x60", is_gray: true) #=> "https://lorempixel.com/g/50/60"
35
+ # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports') #=> "https://lorempixel.com/50/60/sports"
36
+ # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3) #=> "https://lorempixel.com/50/60/sports/3"
37
+ # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: 3, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/3/Dummy-text"
38
+ # Faker::LoremPixel.image(size: "50x60", is_gray: false, category: 'sports', number: nil, text: 'Dummy-text') #=> "https://lorempixel.com/50/60/sports/Dummy-text"
39
+ # Faker::LoremPixel.image(secure: false) #=> "http://lorempixel.com/300/300"
40
+ #
41
+ # @faker.version 1.7.0
20
42
  # rubocop:disable Metrics/ParameterLists
21
43
  def image(legacy_size = NOT_GIVEN, legacy_is_gray = NOT_GIVEN, legacy_category = NOT_GIVEN, legacy_number = NOT_GIVEN, legacy_text = NOT_GIVEN, legacy_secure = NOT_GIVEN, size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true)
22
44
  warn_for_deprecated_arguments do |keywords|
@@ -3,10 +3,28 @@
3
3
  module Faker
4
4
  class Markdown < Base
5
5
  class << self
6
+ ##
7
+ # Produces a random header format.
8
+ #
9
+ # @return [String]
10
+ #
11
+ # @example
12
+ # Faker::Markdown.headers #=> "##### Autem"
13
+ #
14
+ # @faker.version 1.8.0
6
15
  def headers
7
16
  "#{fetch('markdown.headers')} #{Lorem.word.capitalize}"
8
17
  end
9
18
 
19
+ ##
20
+ # Produces a random emphasis formatting on a random word in two sentences.
21
+ #
22
+ # @return [String]
23
+ #
24
+ # @example
25
+ # Faker::Markdown.emphasis #=> "_Incidunt atque quis repellat id impedit. Quas numquam quod incidunt dicta non. Blanditiis delectus laudantium atque reiciendis qui._"
26
+ #
27
+ # @faker.version 1.8.0
10
28
  def emphasis
11
29
  paragraph = Faker::Lorem.paragraph(sentence_count: 3)
12
30
  words = paragraph.split(' ')
@@ -16,6 +34,15 @@ module Faker
16
34
  words.join(' ')
17
35
  end
18
36
 
37
+ ##
38
+ # Produces a random ordered list of items between 1 and 10 randomly.
39
+ #
40
+ # @return [String]
41
+ #
42
+ # @example
43
+ # Faker::Markdown.ordered_list #=> "1. Qui reiciendis non consequatur atque.\n2. Quo doloremque veritatis tempora aut.\n3. Aspernatur.\n4. Ea ab.\n5. Qui.\n6. Sit pariatur nemo eveniet.\n7. Molestiae aut.\n8. Nihil molestias iure placeat.\n9. Dolore autem quisquam."
44
+ #
45
+ # @faker.version 1.8.0
19
46
  def ordered_list
20
47
  number = rand(1..10)
21
48
 
@@ -26,6 +53,15 @@ module Faker
26
53
  result.join('')
27
54
  end
28
55
 
56
+ ##
57
+ # Produces a random unordered list of items between 1 and 10 randomly.
58
+ #
59
+ # @return [String]
60
+ #
61
+ # @example
62
+ # Faker::Markdown.unordered_list #=> "* Voluptatum aliquid tempora molestiae facilis non sed.\n* Nostrum omnis iste impedit voluptatum dolor.\n* Esse quidem et facere."
63
+ #
64
+ # @faker.version 1.8.0
29
65
  def unordered_list
30
66
  number = rand(1..10)
31
67
 
@@ -36,14 +72,41 @@ module Faker
36
72
  result.join('')
37
73
  end
38
74
 
75
+ ##
76
+ # Produces a random inline code snippet between two sentences.
77
+ #
78
+ # @return [String]
79
+ #
80
+ # @example
81
+ # Faker::Markdown.inline_code #=> "Aut eos quis suscipit. `Dignissimos voluptatem expedita qui.` Quo doloremque veritatis tempora aut."
82
+ #
83
+ # @faker.version 1.8.0
39
84
  def inline_code
40
85
  "`#{Faker::Lorem.sentence(word_count: 1)}`"
41
86
  end
42
87
 
88
+ ##
89
+ # Produces a random code block formatted in Ruby.
90
+ #
91
+ # @return [String]
92
+ #
93
+ # @example
94
+ # Faker::Markdown.block_code #=> "```ruby\nEos quasi qui.\n```"
95
+ #
96
+ # @faker.version 1.8.0
43
97
  def block_code
44
98
  "```ruby\n#{Lorem.sentence(word_count: 1)}\n```"
45
99
  end
46
100
 
101
+ ##
102
+ # Produces a random 3x4 table with a row of headings, a row of hyphens and two rows of data
103
+ #
104
+ # @return [String]
105
+ #
106
+ # @example
107
+ # Faker::Markdown.table #=> "ad | similique | voluptatem\n---- | ---- | ----\ncorrupti | est | rerum\nmolestiae | quidem | et"
108
+ #
109
+ # @faker.version 1.8.0
47
110
  def table
48
111
  table = []
49
112
  3.times do
@@ -53,12 +116,38 @@ module Faker
53
116
  table.join("\n")
54
117
  end
55
118
 
119
+ ##
120
+ # Produces a random method from the methods above or the methods listed in the arguments.
121
+ #
122
+ # @param methods [Symbol] Specify which methods to use.
123
+ # @return [String, Array<String>]
124
+ #
125
+ # @example
126
+ # Faker::Markdown.random #=> returns output from a single method outlined above
127
+ # Faker::Markdown.random("table") #=> returns output from any single method outlined above except for "table"
128
+ # Faker::Markdown.random("ordered_list", "unordered_list") #=> returns output from any single method outlined above except for either ordered_list and unordered_list
129
+ #
130
+ # @faker.version 1.8.0
56
131
  def random(*args)
57
132
  method_list = available_methods
58
133
  args&.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
59
134
  send(method_list[rand(0..method_list.length - 1)])
60
135
  end
61
136
 
137
+ ##
138
+ # Produces a simulated blog-esque text-heavy block in markdown
139
+ #
140
+ # Keyword arguments: sentences, repeat
141
+ # @param sentences [Integer] Specifies how many sentences make a text block.
142
+ # @param repeat [Integer] Specifies how many times the text block repeats.
143
+ # @return [String]
144
+ #
145
+ # @example
146
+ # Faker::Markdown.sandwich #=> returns newline separated content of 1 header, 1 default lorem paragraph, and 1 random markdown element
147
+ # Faker::Markdown.sandwich(sentences: 5) #=> returns newline separated content of 1 header, 1 5-sentence lorem paragraph, and 1 random markdown element
148
+ # Faker::Markdown.sandwich(sentences: 6, repeat: 3) #=> returns newline separated content of 1 header, and then 3 sections consisting of, here, 1 6-sentence lorem paragraph and 1 random markdown element. The random markdown element is chosen at random in each iteration of the paragraph-markdown pairing.
149
+ #
150
+ # @faker.version 1.8.0
62
151
  def sandwich(legacy_sentences = NOT_GIVEN, legacy_repeat = NOT_GIVEN, sentences: 3, repeat: 1)
63
152
  warn_for_deprecated_arguments do |keywords|
64
153
  keywords << :sentences if legacy_sentences != NOT_GIVEN