Class: Taipu::Number
Overview
The type number.
Instance Method Summary collapse
- #constraints ⇒ Object
-
#initialize(min: nil, max: nil) ⇒ Number
constructor
A new instance of Number.
- #valid?(value) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(min: nil, max: nil) ⇒ Number
Returns a new instance of Number.
7 8 9 10 11 12 |
# File 'lib/taipu/number.rb', line 7 def initialize(min: nil, max: nil) fail 'MinIsGreaterThanMaxError' if !min.nil? && !max.nil? && min > max @min = min @max = max end |
Instance Method Details
#constraints ⇒ Object
22 23 24 25 26 27 |
# File 'lib/taipu/number.rb', line 22 def constraints { min: @min, max: @max } end |
#valid?(value) ⇒ Boolean
14 15 16 17 18 19 20 |
# File 'lib/taipu/number.rb', line 14 def valid?(value) return false unless value.is_a?(::Numeric) return false if !@min.nil? && value < @min return false if !@max.nil? && value > @max true end |