Sha256: 3d3b0e19999730ccc1729262c780c7c8a08240238544b0415ccef7b4777c90a2

Contents?: true

Size: 727 Bytes

Versions: 4

Compression:

Stored size: 727 Bytes

Contents

module SPNet
# Keeps values between the given Limit objects.
#
# @author James Tunnell
class RangeLimiter < Limiter
  attr_reader :lower, :upper
  
  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

  # Limit the given value to be between lower and upper limits. Ignores the current_value parameter.  
  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
end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spnet-0.1.8 lib/spnet/limiters/range_limiter.rb
spnet-0.1.7 lib/spnet/limiters/range_limiter.rb
spnet-0.1.6 lib/spnet/limiters/range_limiter.rb
spnet-0.1.5 lib/spnet/limiters/range_limiter.rb