Class: Faker::Number
- Inherits:
-
Base
- Object
- Base
- Faker::Number
show all
- Defined in:
- lib/faker/number.rb
Constant Summary
Constants inherited
from Base
Base::Letters, Base::Numbers, Base::ULetters
Class Method Summary
collapse
Methods inherited from Base
bothify, fetch, flexible, letterify, method_missing, numerify, parse, rand_in_range, regexify, translate
Class Method Details
.between(from = 1.00, to = 5000.00) ⇒ Object
46
47
48
|
# File 'lib/faker/number.rb', line 46
def between(from = 1.00, to = 5000.00)
Faker::Base::rand_in_range(from, to)
end
|
.decimal(l_digits, r_digits = 2) ⇒ Object
26
27
28
29
30
|
# File 'lib/faker/number.rb', line 26
def decimal(l_digits, r_digits = 2)
l_d = self.number(l_digits)
r_d = self.decimal_part(r_digits)
"#{l_d}.#{r_d}"
end
|
.decimal_part(digits) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/faker/number.rb', line 17
def decimal_part digits
num = ''
if digits > 1
num = non_zero_digit
digits -= 1
end
leading_zero_number(digits) + num
end
|
.digit ⇒ Object
36
37
38
|
# File 'lib/faker/number.rb', line 36
def digit
rand(10).to_s
end
|
.hexadecimal(digits) ⇒ Object
40
41
42
43
44
|
# File 'lib/faker/number.rb', line 40
def hexadecimal(digits)
hex = ""
digits.times { hex += rand(15).to_s(16) }
hex
end
|
.leading_zero_number(digits) ⇒ Object
13
14
15
|
# File 'lib/faker/number.rb', line 13
def leading_zero_number(digits)
(1..digits).collect {digit}.join
end
|
.negative(from = -5000.00,, to = -1.00)) ⇒ Object
55
56
57
58
|
# File 'lib/faker/number.rb', line 55
def negative(from = -5000.00, to = -1.00)
random_number = between(from, to)
less_than_zero(random_number)
end
|
.non_zero_digit ⇒ Object
32
33
34
|
# File 'lib/faker/number.rb', line 32
def non_zero_digit
( rand(9) + 1 ).to_s
end
|
.number(digits) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/faker/number.rb', line 4
def number(digits)
num = ''
if digits > 1
num = non_zero_digit
digits -= 1
end
num + leading_zero_number(digits)
end
|
.positive(from = 1.00, to = 5000.00) ⇒ Object
50
51
52
53
|
# File 'lib/faker/number.rb', line 50
def positive(from = 1.00, to = 5000.00)
random_number = between(from, to)
greater_than_zero(random_number)
end
|