Class: IntegerRule
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
-
#min ⇒ Object
Returns the value of attribute min.
Instance Method Summary collapse
-
#initialize ⇒ IntegerRule
constructor
A new instance of IntegerRule.
- #load(value) ⇒ Object
- #train ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize ⇒ IntegerRule
Returns a new instance of IntegerRule.
6 7 8 9 |
# File 'lib/rules/IntegerRule.rb', line 6 def initialize() @min = nil @max = nil end |
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max.
4 5 6 |
# File 'lib/rules/IntegerRule.rb', line 4 def max @max end |
#min ⇒ Object
Returns the value of attribute min.
3 4 5 |
# File 'lib/rules/IntegerRule.rb', line 3 def min @min end |
Instance Method Details
#load(value) ⇒ Object
11 12 13 |
# File 'lib/rules/IntegerRule.rb', line 11 def load(value) @values << value end |
#train ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rules/IntegerRule.rb', line 15 def train() numbers = @values.select {|num| num.class == Integer } numbers.sort! @min = numbers.first @max = numbers.last end |
#validate ⇒ Object
22 23 24 25 |
# File 'lib/rules/IntegerRule.rb', line 22 def validate() return false if value < rule.min return false if value > rule.max end |