Class: Jan::Random

Inherits:
Object
  • Object
show all
Defined in:
lib/jan/random.rb

Instance Method Summary collapse

Constructor Details

#initialize(generator: ::Random.new) ⇒ Random

Returns a new instance of Random.

Parameters:

  • generator (Random) (defaults to: ::Random.new)

    Random-like object which respond to #rand(max)



4
5
6
# File 'lib/jan/random.rb', line 4

def initialize(generator: ::Random.new)
  @generator = generator
end

Instance Method Details

#codeJan::Code

Returns:



9
10
11
12
# File 'lib/jan/random.rb', line 9

def code
  twelve_digits_str = sprintf('%012d', @generator.rand(1_000_000_000_000))
  Jan::CodeBody.new(twelve_digits_str).generate_code
end

#instore_codeJan::Code

Returns:



15
16
17
18
# File 'lib/jan/random.rb', line 15

def instore_code
  twelve_digits_str = '2' + sprintf('%011d', @generator.rand(100_000_000_000))
  Jan::CodeBody.new(twelve_digits_str).generate_code
end