Exception: KXI::Exceptions::OutOfRangeException

Inherits:
Exception
  • Object
show all
Defined in:
lib/kxi/exceptions/out_of_range_exception.rb

Overview

Raised when certain value is out of range

Instance Method Summary collapse

Constructor Details

#initialize(val, min = nil, max = nil) ⇒ OutOfRangeException

Note:

If both min and max are nil, then range is empty set

Instantiates the KXI::Exceptions::OutOfRangeException class

Parameters:

  • val (Object)

    Erroneous value

  • min (Object, nil) (defaults to: nil)

    Minimal expected value; nil if there is no minimum

  • max (Object, nil) (defaults to: nil)

    Maximal expected value; nil if there is no maximum



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kxi/exceptions/out_of_range_exception.rb', line 30

def initialize(val, min = nil, max = nil)
	if min == nil and max == nil
		super("Value '#{val}' is out of range {}!")
	elsif min == max
		super("Value '#{val}' is out of range {#{min}}!")
	else
		super("Value '#{val}' is out of range #{(min == nil ? '(-∞' : "<#{min}")};#{(max == nil ? '∞)' : "#{max}>")}!")
	end
	@val = val
	@min = min
	@max = max
end

Instance Method Details

#maximumObject?

Returns maximal expected value

Returns:

  • (Object, nil)

    Maximal expected value; nil if there is no maximum



21
22
23
# File 'lib/kxi/exceptions/out_of_range_exception.rb', line 21

def maximum
	@max
end

#minimumObject?

Returns minimal expected value

Returns:

  • (Object, nil)

    Minimal expected value; nil if there is no minimum



15
16
17
# File 'lib/kxi/exceptions/out_of_range_exception.rb', line 15

def minimum
	@min
end

#valueObject

Returns erroneous value

Returns:

  • (Object)

    Erroneous value



9
10
11
# File 'lib/kxi/exceptions/out_of_range_exception.rb', line 9

def value
	@val
end