Class: SafeType::Integer
- Inherits:
-
Rule
- Object
- Rule
- SafeType::Integer
show all
- Defined in:
- lib/safe_type/primitive/integer.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Rule
#after, #before, coerce, #coerce
Constructor Details
#initialize(type: ::Integer, min: nil, max: nil, **args) ⇒ Integer
Returns a new instance of Integer.
3
4
5
6
7
|
# File 'lib/safe_type/primitive/integer.rb', line 3
def initialize(type: ::Integer, min: nil, max: nil, **args)
@min = min
@max = max
super
end
|
Class Method Details
.default(value = 0, min: nil, max: nil) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/safe_type/primitive/integer.rb', line 15
def self.default(value=0, min: nil, max: nil)
new(
default: value,
min: min,
max: max
)
end
|
.strict(min: nil, max: nil) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/safe_type/primitive/integer.rb', line 23
def self.strict(min: nil, max: nil)
new(
required: true,
min: min,
max: max
)
end
|
Instance Method Details
#is_valid?(input) ⇒ Boolean
9
10
11
12
13
|
# File 'lib/safe_type/primitive/integer.rb', line 9
def is_valid?(input)
return false unless @min.nil? || input >= @min
return false unless @max.nil? || input <= @max
super
end
|