Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YARD docs to Faker::String #2004

Merged
merged 2 commits into from May 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/faker/default/string.rb
Expand Up @@ -3,6 +3,22 @@
module Faker
class String < Base
class << self
##
# Produces a random UTF-8 string with optional nested length selectors.
#
# @param length [Integer, Range, Array<Integer, Range, nil>] The length of produced string and/or specific UTF-8 characters to use.
# @return [String]
#
# @example
# rubocop:disable Style/AsciiComments
# Faker::String.random #=> "3 뇦\u0017&y\u{3A109}$8^4* 녹豿4좘툢ꔾ쉙6ɉ\uA6 8TN畀챵|\"3쇤Ŵ"
# Faker::String.random(length: 4) #=> "⼨%0*"
# Faker::String.random(length: 3..12) #=> "\u{69FDC};秨툫"
# Faker::String.random(length: [0, 6]) #=> "I轤𣴒P溟L"
# Faker::String.random(length: [1, (2..5), [3, 6], nil]) #=> "葓L#ћ"
# rubocop:enable Style/AsciiComments
#
# @faker.version 1.9.0
def random(legacy_length = NOT_GIVEN, length: 32)
warn_for_deprecated_arguments do |keywords|
keywords << :length if legacy_length != NOT_GIVEN
Expand Down Expand Up @@ -38,9 +54,9 @@ def char_space_ratio

def utf8character
sample([
rand(32..90), # latin alphabet
rand(128), # 7-bit ASCII
rand(0xd800), # utf-8 codepoints below utf-16 surrogate halves
rand(32..90), # latin alphabet
rand(128), # 7-bit ASCII
rand(0xd800), # utf-8 codepoints below utf-16 surrogate halves
rand(57_344..1_114_111) # utf-8 codepoints above utf-16 surrogate halves
]).chr(Encoding::UTF_8)
end
Expand Down