Class: PositionalGenerator::Builder::Int
- Inherits:
-
Object
- Object
- PositionalGenerator::Builder::Int
- Defined in:
- lib/helpers/positional_generator.rb
Instance Method Summary collapse
- #generate(_) ⇒ Object
-
#initialize(length, ranges) ⇒ Int
constructor
A new instance of Int.
Constructor Details
#initialize(length, ranges) ⇒ Int
Returns a new instance of Int.
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/helpers/positional_generator.rb', line 407 def initialize(length, ranges) # Internally we store only an Enumerable of Range values. So if we are # not given any Ranges but are given a length, we need to convert the # length to a Range. # # If the length is `5`, that means we should compute the Range `10000..99999`. # We can compute the lower end with a simple exponent: 10^4 = 10000. # The upper end is one less than an exponent: 10^5 - 1 = 99999. if ranges.nil? lower = 10**(length - 1) upper = (10**length) - 1 ranges = [lower..upper] end @ranges = ranges end |