Class: RiceBubble::Attributes::Integer

Inherits:
Number
  • Object
show all
Defined in:
lib/rice_bubble/attributes/integer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Number

#description

Methods inherited from Base

#call, #description, #fetch, #optional

Constructor Details

#initialize(min: nil, max: nil, **options) ⇒ Integer

Returns a new instance of Integer.



6
7
8
9
10
# File 'lib/rice_bubble/attributes/integer.rb', line 6

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.



4
5
6
# File 'lib/rice_bubble/attributes/integer.rb', line 4

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



4
5
6
# File 'lib/rice_bubble/attributes/integer.rb', line 4

def min
  @min
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:



16
17
18
19
20
# File 'lib/rice_bubble/attributes/integer.rb', line 16

def valid?(value)
  super &&
    (!min || value >= min) &&
    (!max || value <= max)
end

#valid_typesObject



12
13
14
# File 'lib/rice_bubble/attributes/integer.rb', line 12

def valid_types
  [::Integer]
end