Class: RiceBubble::Attributes::Number
- Defined in:
- lib/rice_bubble/attributes/number.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(min: nil, max: nil) ⇒ Number
constructor
A new instance of Number.
- #valid?(value) ⇒ Boolean
- #valid_types ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(min: nil, max: nil) ⇒ Number
Returns a new instance of Number.
6 7 8 9 10 |
# File 'lib/rice_bubble/attributes/number.rb', line 6 def initialize(min: nil, max: nil, &) super(&) @min = min @max = max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/rice_bubble/attributes/number.rb', line 4 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
4 5 6 |
# File 'lib/rice_bubble/attributes/number.rb', line 4 def min @min end |
Instance Method Details
#description ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rice_bubble/attributes/number.rb', line 22 def description result = super if min && max "#{result} between #{min} and #{max}" elsif min "#{result} greater than or equal to #{min}" elsif max "#{result} less than or equal to #{max}" else result end end |
#valid?(value) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/rice_bubble/attributes/number.rb', line 16 def valid?(value) super && !min&.send(:>, value) && !max&.send(:<, value) end |
#valid_types ⇒ Object
12 13 14 |
# File 'lib/rice_bubble/attributes/number.rb', line 12 def valid_types [::Numeric] end |