Class: Jan::Random
- Inherits:
-
Object
- Object
- Jan::Random
- Defined in:
- lib/jan/random.rb
Instance Method Summary collapse
- #code ⇒ Jan::Code
-
#initialize(generator: ::Random.new) ⇒ Random
constructor
A new instance of Random.
- #instore_code ⇒ Jan::Code
Constructor Details
#initialize(generator: ::Random.new) ⇒ Random
Returns a new instance of Random.
4 5 6 |
# File 'lib/jan/random.rb', line 4 def initialize(generator: ::Random.new) @generator = generator end |
Instance Method Details
#code ⇒ Jan::Code
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_code ⇒ Jan::Code
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 |