Faker v0.10.0 Faker.Util View Source
Collection of useful functions for your fake data. Functions aware of locale.
Link to this section Summary
Functions
Cycle randomly through the given list with guarantee every element of the list is used once before elements are being picked again. This is done by keeping a list of remaining elements that have not been picked yet. The list of remaining element is returned, as well as the randomly picked element
Start a cycle. See cycle/1
Get a random digit as a string; one of 0-9
Format a string with randomly generated data. Format specifiers are replaced by random values. A format specifier follows this prototype
Execute fun n times with the index as first param and join the results with joiner
Get a random alphabet character as a string; one of a-z or A-Z
Execute fun n times with the index as first param and return the results as a list
Get a random lowercase character as a string; one of a-z
Pick a random element from the list
Converts a list to a string, with “and” before the last item. Uses an Oxford comma
Get a random uppercase character as a string; one of A-Z
Link to this section Functions
Cycle randomly through the given list with guarantee every element of the list is used once before elements are being picked again. This is done by keeping a list of remaining elements that have not been picked yet. The list of remaining element is returned, as well as the randomly picked element.
Example
my_cycle = cycle_start ~w(1 2 3)
cycle my_cycle #=> 2
cycle my_cycle #=> 3
cycle my_cycle #=> 1
Start a cycle. See cycle/1
Get a random digit as a string; one of 0-9
Format a string with randomly generated data. Format specifiers are replaced by random values. A format specifier follows this prototype:
%[length]specifier
The following specifier rules are present by default:
- d: digits 0-9
- a: lowercase letter a-z
- A: uppercase letter A-Z
- b: anycase letter a-z, A-Z
The specifier rules can be overriden using the second argument.
Examples
format("%2d-%3d %a%A %2d%%") #=> "74-381 sK 32%"
format("%8nBATMAN", n: fn() -> "nana " end) #=> "nana nana nana nana nana nana nana nana BATMAN"
Execute fun n times with the index as first param and join the results with joiner
Examples
join(3, ", ", &Faker.Code.isbn13/0) # => "9785053574562, 9787187574302, 9798231475230"
Get a random alphabet character as a string; one of a-z or A-Z
Execute fun n times with the index as first param and return the results as a list
Get a random lowercase character as a string; one of a-z
Pick a random element from the list
Converts a list to a string, with “and” before the last item. Uses an Oxford comma.
Get a random uppercase character as a string; one of A-Z