Class: Faker::Number

Inherits:
Base
  • Object
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



24
25
26
# File 'lib/faker/number.rb', line 24

def between(from = 1.00, to = 5000.00)
  Faker::Base::rand_in_range(from, to)
end

.decimal(l_digits, r_digits = 2) ⇒ Object



8
9
10
11
12
# File 'lib/faker/number.rb', line 8

def decimal(l_digits, r_digits = 2)
  l_d = self.number(l_digits)
  r_d = self.number(r_digits)
  "#{l_d}.#{r_d}"
end

.digitObject



14
15
16
# File 'lib/faker/number.rb', line 14

def digit
  (rand() * 9).round.to_s
end

.hexadecimal(digits) ⇒ Object



18
19
20
21
22
# File 'lib/faker/number.rb', line 18

def hexadecimal(digits)
  hex = ""
  digits.times { hex += rand(15).to_s(16) }
  hex
end

.negative(from = -5000.00,, to = -1.00)) ⇒ Object



33
34
35
36
# File 'lib/faker/number.rb', line 33

def negative(from = -5000.00, to = -1.00)
  random_number = between(from, to)
  less_than_zero(random_number)
end

.number(digits) ⇒ Object



4
5
6
# File 'lib/faker/number.rb', line 4

def number(digits)
  (1..digits).collect {digit}.join
end

.positive(from = 1.00, to = 5000.00) ⇒ Object



28
29
30
31
# File 'lib/faker/number.rb', line 28

def positive(from = 1.00, to = 5000.00)
  random_number = between(from, to)
  greater_than_zero(random_number)
end