Class: Croesus::Base

Inherits:
Object show all
Defined in:
lib/croesus/validations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, validations) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
30
# File 'lib/croesus/validations.rb', line 24

def initialize(hash, validations)
  self.errors      = {}
  self.hash        = hash
  self.validations = validations.inject({
    }){ |memo,(k,v)| memo[k] = v.to_s.downcase; memo }
  validate
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



22
23
24
# File 'lib/croesus/validations.rb', line 22

def errors
  @errors
end

#hashObject

Returns the value of attribute hash.



22
23
24
# File 'lib/croesus/validations.rb', line 22

def hash
  @hash
end

#validationsObject

Returns the value of attribute validations.



22
23
24
# File 'lib/croesus/validations.rb', line 22

def validations
  @validations
end

Class Method Details

.validate(hash, validations) ⇒ Object



36
37
38
# File 'lib/croesus/validations.rb', line 36

def self.validate(hash, validations)
  new(hash, validations)
end

Instance Method Details

#valid?Boolean

Returns:



32
33
34
# File 'lib/croesus/validations.rb', line 32

def valid?
  errors.empty?
end