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.
23 24 25 26 27 28 29 30 |
# File 'lib/nrser/types/bounded.rb', line 23 def initialize min: nil, max: nil, ** super ** @min = min @max = max end |
Instance Attribute Details
#max ⇒ Number (readonly)
Minimum value.
20 21 22 |
# File 'lib/nrser/types/bounded.rb', line 20 def max @max end |
#min ⇒ Number (readonly)
Minimum value.
13 14 15 |
# File 'lib/nrser/types/bounded.rb', line 13 def min @min end |
Instance Method Details
#explain ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nrser/types/bounded.rb', line 38 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
32 33 34 35 36 |
# File 'lib/nrser/types/bounded.rb', line 32 def test? value return false if @min && value < @min return false if @max && value > @max true end |