Class: SPNet::EnumLimiter
- Defined in:
- lib/spnet/limiters/enum_limiter.rb
Overview
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#apply_limit(value, current_value) ⇒ Object
Limit the given value to those given by @values.
-
#initialize(values) ⇒ EnumLimiter
constructor
A new instance of EnumLimiter.
Constructor Details
#initialize(values) ⇒ EnumLimiter
Returns a new instance of EnumLimiter.
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
#values ⇒ Object (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 |