Skip to content

Commit

Permalink
Add YARD docs to Faker::String (#2004)
Browse files Browse the repository at this point in the history
* Add YARD docs to Faker::String

* Disable rubocop to show UTF-8 characters in @examples
  • Loading branch information
danielTiringer committed May 23, 2020
1 parent 736b6d9 commit b77c6c0
Showing 1 changed file with 19 additions and 3 deletions.
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

0 comments on commit b77c6c0

Please sign in to comment.