Class: SPNet::UpperLimiter

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

Overview

Author:

  • James Tunnell

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inclusiveObject (readonly)

Returns the value of attribute inclusive.



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

def inclusive
  @inclusive
end

#limitObject (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