Class: Opto::Resolvers::RandomNumber

Inherits:
Opto::Resolver show all
Defined in:
lib/opto/resolvers/random_number.rb

Overview

Geneerate a new random number. Requires :min and :max in hint to define range.

Instance Attribute Summary

Attributes inherited from Opto::Resolver

#hint, #option

Instance Method Summary collapse

Methods inherited from Opto::Resolver

for, inherited, #initialize, origin, #origin, resolvers

Constructor Details

This class inherits a constructor from Opto::Resolver

Instance Method Details

#resolveObject

Raises:

  • (ArgumentError)

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/opto/resolvers/random_number.rb', line 11

def resolve
  raise ArgumentError, "Range not set" if hint.nil?

  unless hint.kind_of?(Hash)
    raise TypeError, "Range invalid, define min: and max: using hash syntax"
  end

  unless hint[:min]
    raise ArgumentError, "Range definition missing :min"
  end

  unless hint[:max]
    raise ArgumentError, "Range definition missing :max"
  end

  rand(hint[:min]..hint[:max])
end