forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Faker::Alphanumeric (faker-ruby#1302)
* Add Faker::Alphanum * Update and rename alphanum.md to alphanumeric.md * Update README.md * Remove duplications * Minor change
- Loading branch information
1 parent
b8d0671
commit 14a86bf
Showing
9 changed files
with
61 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Faker::Alphanumeric | ||
|
||
It might be available in the next version. | ||
|
||
```ruby | ||
Faker::Alphanumeric.alpha 10 #=> "zlvubkrwga" | ||
|
||
Faker::Alphanumeric.alphanumeric 10 #=> "3yfq2phxtb" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class Alphanumeric < Base | ||
class << self | ||
ALPHABET = ('a'..'z').to_a | ||
ALPHANUMS = ALPHABET + (0..9).to_a | ||
|
||
def alpha(char_count = 32) | ||
char_count = resolve(char_count) | ||
return '' if char_count.to_i < 1 | ||
Array.new(char_count) { sample(ALPHABET) }.join | ||
end | ||
|
||
def alphanumeric(char_count = 32) | ||
char_count = resolve(char_count) | ||
return '' if char_count.to_i < 1 | ||
Array.new(char_count) { sample(ALPHANUMS) }.join | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'test_helper' | ||
|
||
class TestFakerAlphanum < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Alphanumeric | ||
end | ||
|
||
def alpha | ||
assert @tester.alpha(5).match(/[a-z]{5}/) | ||
end | ||
|
||
def alphanum | ||
assert @tester.alphanumeric(5).match(/[a-z0-9]{5}/) | ||
end | ||
end |