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, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, sample, shuffle, translate, unique, with_locale
Class Method Details
.between(from = 1.00, to = 5000.00) ⇒ Object
53
54
55
|
# File 'lib/faker/number.rb', line 53
def between(from = 1.00, to = 5000.00)
Faker::Base::rand_in_range(from, to)
end
|
.decimal(l_digits = 5, r_digits = 2) ⇒ Object
26
27
28
29
30
|
# File 'lib/faker/number.rb', line 26
def decimal(l_digits=5, r_digits=2)
l_d = self.number(l_digits)
r_d = self.decimal_part(r_digits)
"#{l_d}.#{r_d}"
end
|
.decimal_part(digits = 10) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/faker/number.rb', line 17
def decimal_part(digits=10)
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 = 6) ⇒ Object
40
41
42
43
44
|
# File 'lib/faker/number.rb', line 40
def hexadecimal(digits=6)
hex = ""
digits.times { hex += rand(15).to_s(16) }
hex
end
|
.leading_zero_number(digits = 10) ⇒ Object
13
14
15
|
# File 'lib/faker/number.rb', line 13
def leading_zero_number(digits=10)
(1..digits).collect {digit}.join
end
|
.negative(from = -5000.00,, to = -1.00)) ⇒ Object
62
63
64
65
|
# File 'lib/faker/number.rb', line 62
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
|
.normal(mean = 1, standard_deviation = 1) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/faker/number.rb', line 46
def normal(mean=1, standard_deviation=1)
theta = 2 * Math::PI * rand
rho = Math.sqrt(-2 * Math.log(1 - rand))
scale = standard_deviation * rho
mean + scale * Math.cos(theta)
end
|
.number(digits = 10) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/faker/number.rb', line 4
def number(digits=10)
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
57
58
59
60
|
# File 'lib/faker/number.rb', line 57
def positive(from = 1.00, to = 5000.00)
random_number = between(from, to)
greater_than_zero(random_number)
end
|