Class: EightBall::Conditions::Range
- Defined in:
- lib/eight_ball/conditions/range.rb
Overview
The Range Condition describes a range of acceptable values by specifying a minimum and a maximum. These can be strings, integers, etc. but mixing data types will probably give you unexpected results.
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Range
constructor
Creates a new instance of a Range Condition.
- #satisfied?(value) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Range
Creates a new instance of a Range Condition.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eight_ball/conditions/range.rb', line 20 def initialize( = {}) ||= {} raise ArgumentError, 'Missing value for min' if [:min].nil? raise ArgumentError, 'Missing value for max' if [:max].nil? @min = [:min] raise ArgumentError, 'Max must be greater or equal to min' if [:max] < min @max = [:max] self.parameter = [:parameter] end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
8 9 10 |
# File 'lib/eight_ball/conditions/range.rb', line 8 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
8 9 10 |
# File 'lib/eight_ball/conditions/range.rb', line 8 def min @min end |
Instance Method Details
#satisfied?(value) ⇒ Boolean
44 45 46 |
# File 'lib/eight_ball/conditions/range.rb', line 44 def satisfied?(value) value >= min && value <= max end |