Class: NRSER::Types::Bounded
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
- #default_name ⇒ Object
-
#initialize(min: nil, max: nil, **options) ⇒ Bounded
constructor
A new instance of Bounded.
- #test(value) ⇒ Object
Methods inherited from Type
#check, #from_data, #from_s, #has_from_data?, #has_from_s?, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s
Constructor Details
#initialize(min: nil, max: nil, **options) ⇒ Bounded
Returns a new instance of Bounded.
21 22 23 24 25 26 27 28 |
# File 'lib/nrser/types/bounded.rb', line 21 def initialize min: nil, max: nil, ** super ** @min = min @max = max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
18 19 20 |
# File 'lib/nrser/types/bounded.rb', line 18 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
12 13 14 |
# File 'lib/nrser/types/bounded.rb', line 12 def min @min end |
Instance Method Details
#default_name ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nrser/types/bounded.rb', line 36 def default_name attrs_str = ['min', 'max'].map {|name| [name, instance_variable_get("@#{ name }")] }.reject {|name, value| value.nil? }.map {|name, value| "#{ name }=#{ value }" }.join(', ') "#{ self.class.short_name } #{ attrs_str }" end |
#test(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/nrser/types/bounded.rb', line 30 def test value return false if @min && value < @min return false if @max && value > @max true end |