Class: NRSER::Types::Bounded

Inherits:
Type
  • Object
show all
Defined in:
lib/nrser/types/bounded.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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,
                **options
  super **options
  
  @min = min
  @max = max
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



18
19
20
# File 'lib/nrser/types/bounded.rb', line 18

def max
  @max
end

#minObject (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_nameObject



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