Class: Rant::RantVar::Constraints::IntegerInRange

Inherits:
Integer show all
Defined in:
lib/rant/import/var/numbers.rb

Instance Method Summary collapse

Methods inherited from Integer

rant_constraint

Constructor Details

#initialize(range) ⇒ IntegerInRange

Returns a new instance of IntegerInRange.



37
38
39
# File 'lib/rant/import/var/numbers.rb', line 37

def initialize(range)
    @range = range
end

Instance Method Details

#defaultObject



48
49
50
# File 'lib/rant/import/var/numbers.rb', line 48

def default
    @range.min
end

#filter(val) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/rant/import/var/numbers.rb', line 40

def filter(val)
    i = super
    if @range === i
	i
    else
	raise ConstraintError.new(self, val)
    end
end

#to_sObject



51
52
53
# File 'lib/rant/import/var/numbers.rb', line 51

def to_s
    super + " #{@range}"
end