Class: NRSER::Types::Bounded
Overview
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.
- #symbolic ⇒ Object
- #test?(value) ⇒ Boolean
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #default_name, #default_symbolic, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_proc, #to_s, #union, #xor
Constructor Details
#initialize(min: nil, max: nil, **options) ⇒ Bounded
Returns a new instance of Bounded.
44 45 46 47 48 49 50 51 |
# File 'lib/nrser/types/bounded.rb', line 44 def initialize min: nil, max: nil, ** super ** @min = min @max = max end |
Instance Attribute Details
#max ⇒ Number (readonly)
Minimum value.
41 42 43 |
# File 'lib/nrser/types/bounded.rb', line 41 def max @max end |
#min ⇒ Number (readonly)
Minimum value.
34 35 36 |
# File 'lib/nrser/types/bounded.rb', line 34 def min @min end |
Instance Method Details
#explain ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/nrser/types/bounded.rb', line 76 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 |
#symbolic ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nrser/types/bounded.rb', line 59 def symbolic if min if max # has min and max, use range notation "(#{ min.inspect }..#{ max.inspect })" else # only has min "(#{ min.inspect }..)" # "{ x : x #{ NRSER::Types::GEQ } #{ min } }" end else # only has max "(..#{ max.inspect })" # "{ x : x #{ NRSER::Types::LEQ } #{ max } }" end end |
#test?(value) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/nrser/types/bounded.rb', line 53 def test? value return false if @min && value < @min return false if @max && value > @max true end |