Sha256: 6444aab49a223ab3e4b809689eb699d69e357e3556543a976027117b24bd0e67

Contents?: true

Size: 612 Bytes

Versions: 4

Compression:

Stored size: 612 Bytes

Contents

module SPNet
# Keeps values at or below the given Limit.
#
# @author James Tunnell
class UpperLimiter < Limiter
  attr_reader :limit, :inclusive
  
  def initialize limit, inclusive
    @limit = limit
    @inclusive = inclusive
  end

  # Limit the given value to be at or below @limit. Ignores the current_value parameter.
  def apply_limit value, current_value = nil
    if inclusive
      if value <= @limit
        return value
      else
        return @limit
      end
    else
      if value < @limit
        return value
      else
        return @limit - Float::EPSILON
      end
    end
  end
end

end

Version data entries

4 entries across 4 versions & 1 rubygems

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