Class: SPNet::RangeLimiter
- Defined in:
- lib/spnet/limiters/range_limiter.rb
Overview
Instance Attribute Summary collapse
-
#lower ⇒ Object
readonly
Returns the value of attribute lower.
-
#upper ⇒ Object
readonly
Returns the value of attribute upper.
Instance Method Summary collapse
-
#apply_limit(value, current_value = nil) ⇒ Object
Limit the given value to be between lower and upper limits.
-
#initialize(lower_limit, lower_inclusive, upper_limit, upper_inclusive) ⇒ RangeLimiter
constructor
A new instance of RangeLimiter.
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
#lower ⇒ Object (readonly)
Returns the value of attribute lower.
6 7 8 |
# File 'lib/spnet/limiters/range_limiter.rb', line 6 def lower @lower end |
#upper ⇒ Object (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 |