Class: NRSER::Types::Bounded

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

#maxNumber (readonly)

Minimum value.

Returns:

  • (Number)


20
21
22
# File 'lib/nrser/types/bounded.rb', line 20

def max
  @max
end

#minNumber (readonly)

Minimum value.

Returns:

  • (Number)


13
14
15
# File 'lib/nrser/types/bounded.rb', line 13

def min
  @min
end

Instance Method Details

#explainObject



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

Returns:

  • (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