Class: SafeType::Symbol
Class Method Summary collapse
- .default(value = nil, min_length: nil, max_length: nil) ⇒ Object
- .strict(min_length: nil, max_length: nil) ⇒ Object
Instance Method Summary collapse
- #after(input) ⇒ Object
-
#initialize(type: ::Symbol, min_length: nil, max_length: nil, **args) ⇒ Symbol
constructor
A new instance of Symbol.
- #is_valid?(input) ⇒ Boolean
Methods inherited from Rule
Constructor Details
#initialize(type: ::Symbol, min_length: nil, max_length: nil, **args) ⇒ Symbol
Returns a new instance of Symbol.
3 4 5 6 7 |
# File 'lib/safe_type/primitive/symbol.rb', line 3 def initialize(type: ::Symbol, min_length: nil, max_length: nil, **args) @min_length = min_length @max_length = max_length super end |
Class Method Details
.default(value = nil, min_length: nil, max_length: nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/safe_type/primitive/symbol.rb', line 20 def self.default(value=nil, min_length: nil, max_length: nil) new( default: value, min_length: min_length, max_length: max_length ) end |
.strict(min_length: nil, max_length: nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/safe_type/primitive/symbol.rb', line 28 def self.strict(min_length: nil, max_length: nil) new( required: true, min_length: min_length, max_length: max_length ) end |
Instance Method Details
#after(input) ⇒ Object
15 16 17 18 |
# File 'lib/safe_type/primitive/symbol.rb', line 15 def after(input) return nil if input.length == 0 super end |
#is_valid?(input) ⇒ Boolean
9 10 11 12 13 |
# File 'lib/safe_type/primitive/symbol.rb', line 9 def is_valid?(input) return false unless @min_length.nil? || input.length >= @min_length return false unless @max_length.nil? || input.length <= @max_length super end |