Class: NRSER::Types::Bounded
Instance Attribute Summary collapse
-
#max ⇒ Number
readonly
Minimum value.
-
#min ⇒ Number
readonly
Minimum value.
Instance Method Summary collapse
- #explain ⇒ Object
-
#initialize(min: nil, max: nil, **options) ⇒ Bounded
constructor
A new instance of Bounded.
- #test?(value) ⇒ Boolean
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
#initialize(min: nil, max: nil, **options) ⇒ Bounded
Returns a new instance of Bounded.
20 21 22 23 24 25 26 27 |
# File 'lib/nrser/types/bounded.rb', line 20 def initialize min: nil, max: nil, ** super ** @min = min @max = max end |
Instance Attribute Details
#max ⇒ Number (readonly)
Minimum value.
17 18 19 |
# File 'lib/nrser/types/bounded.rb', line 17 def max @max end |
#min ⇒ Number (readonly)
Minimum value.
10 11 12 |
# File 'lib/nrser/types/bounded.rb', line 10 def min @min end |
Instance Method Details
#explain ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nrser/types/bounded.rb', line 35 def explain attrs_str = ['min', 'max'].map {|name| [name, instance_variable_get("@#{ name }")] }.reject {|name, value| value.nil? }.map {|name, value| "#{ name }=#{ value }" }.join(', ') "#{ self.class.demod_name }<#{ attrs_str }>" end |
#test?(value) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/nrser/types/bounded.rb', line 29 def test? value return false if @min && value < @min return false if @max && value > @max true end |