Class: ValidatesIdentity::ArDni::Validator
- Inherits:
-
Object
- Object
- ValidatesIdentity::ArDni::Validator
- Defined in:
- lib/validates_identity/ar_dni/validator.rb
Constant Summary collapse
- VALIDATION_REGULAR_EXPRESSION =
/^(\d{2}\.?\d{3}\.?\d{3})$/.freeze
- FORMAT_REGULAR_EXPRESSION =
/(\d{2})(\d{3})(\d{3})/.freeze
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #formatted ⇒ Object
-
#initialize(value) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Validator
Returns a new instance of Validator.
11 12 13 |
# File 'lib/validates_identity/ar_dni/validator.rb', line 11 def initialize(value) @value = value.to_s end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/validates_identity/ar_dni/validator.rb', line 9 def value @value end |
Instance Method Details
#formatted ⇒ Object
21 22 23 24 25 26 |
# File 'lib/validates_identity/ar_dni/validator.rb', line 21 def formatted return if result.nil? result = FORMAT_REGULAR_EXPRESSION.match(striped_value) "#{result[1]}.#{result[2]}.#{result[3]}" end |
#valid? ⇒ Boolean
15 16 17 18 19 |
# File 'lib/validates_identity/ar_dni/validator.rb', line 15 def valid? return true if value.blank? result.present? end |