Class: Valideez::Base
- Inherits:
-
Object
- Object
- Valideez::Base
- Defined in:
- lib/valideez/base.rb
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
-
#validable ⇒ Object
Returns the value of attribute validable.
Instance Method Summary collapse
-
#initialize(val) ⇒ Base
constructor
A new instance of Base.
- #valid? ⇒ Boolean
Constructor Details
#initialize(val) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/valideez/base.rb', line 6 def initialize(val) @val = val.to_s.gsub(/-/, '').gsub(/\s+/, '') @validable = [] end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
3 4 5 |
# File 'lib/valideez/base.rb', line 3 def val @val end |
#validable ⇒ Object
Returns the value of attribute validable.
4 5 6 |
# File 'lib/valideez/base.rb', line 4 def validable @validable end |
Instance Method Details
#valid? ⇒ Boolean
11 12 13 14 15 16 |
# File 'lib/valideez/base.rb', line 11 def valid? # p - Array of methods (Strings) which can be used for validation p = validable.select{ |var| respond_to?("validate_#{var.to_s}", true) } # execute validations, stop and return false if current validations return false p.take_while { |var| send("validate_#{var.to_s}") }.size == p.size end |