Class: Knight::Rule::MinimumLength
- Inherits:
-
Knight::Rule
- Object
- Knight::Rule
- Knight::Rule::MinimumLength
- Defined in:
- lib/knight/rule/minimum_length.rb
Overview
A rule for checking the length of a value
Constant Summary collapse
- DEFAULT_MESSAGE =
'%{attribute} is too short'.freeze
Instance Attribute Summary collapse
-
#minimum ⇒ Fixnum
readonly
private
Length value.
Attributes inherited from Knight::Rule
#attribute_name, #message, #options
Instance Method Summary collapse
-
#initialize(attribute_name, minimum, options = {}) ⇒ undefined
constructor
Initialize an exact length rule.
-
#matches?(value) ⇒ true, false
private
Check length of the value.
-
#to_hash ⇒ Hash
Return the rule as a hash.
Methods inherited from Knight::Rule
Constructor Details
#initialize(attribute_name, minimum, options = {}) ⇒ undefined
Initialize an exact length rule
31 32 33 34 |
# File 'lib/knight/rule/minimum_length.rb', line 31 def initialize(attribute_name, minimum, = {}) super(attribute_name, ) @minimum = minimum end |
Instance Attribute Details
#minimum ⇒ Fixnum (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Length value
15 16 17 |
# File 'lib/knight/rule/minimum_length.rb', line 15 def minimum @minimum end |
Instance Method Details
#matches?(value) ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check length of the value
44 45 46 |
# File 'lib/knight/rule/minimum_length.rb', line 44 def matches?(value) value.length >= minimum end |
#to_hash ⇒ Hash
Return the rule as a hash
56 57 58 59 60 |
# File 'lib/knight/rule/minimum_length.rb', line 56 def to_hash super.merge({ minimum: minimum }).freeze end |