Class: SPNet::UpperLimiter
- Defined in:
- lib/spnet/limiters/upper_limiter.rb
Overview
Instance Attribute Summary collapse
-
#inclusive ⇒ Object
readonly
Returns the value of attribute inclusive.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
-
#apply_limit(value, current_value = nil) ⇒ Object
Limit the given value to be at or below @limit.
-
#initialize(limit, inclusive) ⇒ UpperLimiter
constructor
A new instance of UpperLimiter.
Constructor Details
#initialize(limit, inclusive) ⇒ UpperLimiter
Returns a new instance of UpperLimiter.
8 9 10 11 |
# File 'lib/spnet/limiters/upper_limiter.rb', line 8 def initialize limit, inclusive @limit = limit @inclusive = inclusive end |
Instance Attribute Details
#inclusive ⇒ Object (readonly)
Returns the value of attribute inclusive.
6 7 8 |
# File 'lib/spnet/limiters/upper_limiter.rb', line 6 def inclusive @inclusive end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
6 7 8 |
# File 'lib/spnet/limiters/upper_limiter.rb', line 6 def limit @limit end |
Instance Method Details
#apply_limit(value, current_value = nil) ⇒ Object
Limit the given value to be at or below @limit. Ignores the current_value parameter.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spnet/limiters/upper_limiter.rb', line 14 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 |