Class: SPNet::RangeLimiter

Inherits:
Limiter
  • Object
show all
Defined in:
lib/spnet/limiters/range_limiter.rb

Overview

Author:

  • James Tunnell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lower_limit, lower_inclusive, upper_limit, upper_inclusive) ⇒ RangeLimiter

Returns a new instance of RangeLimiter.



8
9
10
11
# File 'lib/spnet/limiters/range_limiter.rb', line 8

def initialize lower_limit, lower_inclusive, upper_limit, upper_inclusive
  @lower = LowerLimiter.new(lower_limit, lower_inclusive)
  @upper = UpperLimiter.new(upper_limit, upper_inclusive)
end

Instance Attribute Details

#lowerObject (readonly)

Returns the value of attribute lower.



6
7
8
# File 'lib/spnet/limiters/range_limiter.rb', line 6

def lower
  @lower
end

#upperObject (readonly)

Returns the value of attribute upper.



6
7
8
# File 'lib/spnet/limiters/range_limiter.rb', line 6

def upper
  @upper
end

Instance Method Details

#apply_limit(value, current_value = nil) ⇒ Object

Limit the given value to be between lower and upper limits. Ignores the current_value parameter.



14
15
16
17
18
19
20
21
# File 'lib/spnet/limiters/range_limiter.rb', line 14

def apply_limit value, current_value = nil
  new_value = @lower.apply_limit value
  if(new_value == value)
    # value is OK so far. Make sure the right (upper) limit is OK too.
    new_value = @upper.apply_limit value
  end
  return new_value
end