Class: Randrizer::Types::Int
- Defined in:
- lib/randrizer/types/int.rb
Overview
A primitive integer type. The evaluation will generate a random number between
the given min and max.
Constant Summary collapse
- DEFAULT_MIN =
Default minimum generable number
0- DEFAULT_MAX =
Default maximum generable number
9_999_999_999
Instance Method Summary collapse
- #eval ⇒ Object
-
#initialize(min: DEFAULT_MIN, max: DEFAULT_MAX) ⇒ Int
constructor
A new instance of Int.
- #validate! ⇒ Object
Constructor Details
#initialize(min: DEFAULT_MIN, max: DEFAULT_MAX) ⇒ Int
Returns a new instance of Int.
16 17 18 19 |
# File 'lib/randrizer/types/int.rb', line 16 def initialize(min: DEFAULT_MIN, max: DEFAULT_MAX) @min = min @max = max end |
Instance Method Details
#eval ⇒ Object
27 28 29 30 31 |
# File 'lib/randrizer/types/int.rb', line 27 def eval return @min if @min == @max rand(@min..@max) end |
#validate! ⇒ Object
21 22 23 24 25 |
# File 'lib/randrizer/types/int.rb', line 21 def validate! return if @max >= @min raise ValidationError("invalid min/max configuration") end |