mirror of
https://github.com/askn/faker.git
synced 2023-08-10 21:13:01 +03:00
add Number.hexadecimal
This commit is contained in:
parent
a2b3ede6fa
commit
ed6663e116
@ -59,4 +59,9 @@ describe Faker::Number do
|
||||
(random_number >= 1).should be_true
|
||||
(random_number <= 100).should be_true
|
||||
end
|
||||
|
||||
it "hexadecimal" do
|
||||
Faker::Number.hexadecimal(4).match(/[0-9a-f]{4}/).should_not eq nil
|
||||
Faker::Number.hexadecimal(7).match(/[0-9a-f]{7}/).should_not eq nil
|
||||
end
|
||||
end
|
||||
|
@ -28,6 +28,12 @@ module Faker
|
||||
less_than_zero(random_number)
|
||||
end
|
||||
|
||||
def self.hexadecimal(digits)
|
||||
hex = ""
|
||||
digits.times { hex += rand(15).to_s(16) }
|
||||
hex
|
||||
end
|
||||
|
||||
private def self.greater_than_zero(number)
|
||||
if number > 0
|
||||
number
|
||||
|
Loading…
Reference in New Issue
Block a user