Class: Valideez::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/valideez/base.rb

Direct Known Subclasses

Nip, Pesel, Phone

Instance Attribute Summary collapse

Instance Method Summary collapse

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(/-/, '')
  @validable = []
end

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



3
4
5
# File 'lib/valideez/base.rb', line 3

def val
  @val
end

#validableObject

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

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/valideez/base.rb', line 11

def valid?
  p = validable.select{ |var| respond_to?("validate_#{var.to_s}", true) }
  p.take_while { |var| send("validate_#{var.to_s}") }.size == p.size
end