Class: SPNet::EnumLimiter

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

Overview

Author:

  • James Tunnell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ EnumLimiter

Returns a new instance of EnumLimiter.

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/spnet/limiters/enum_limiter.rb', line 8

def initialize values
  raise ArgumentError, "values is not an Enumerable" unless values.is_a?(Enumerable)
  @values = values
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



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

def values
  @values
end

Instance Method Details

#apply_limit(value, current_value) ⇒ Object

Limit the given value to those given by @values. If the given value is not found, return the current value.



15
16
17
18
19
20
21
# File 'lib/spnet/limiters/enum_limiter.rb', line 15

def apply_limit value, current_value
  if @values.include? value
    return value
  else
    return current_value
  end
end