Class: Hashidator
- Inherits:
-
Object
- Object
- Hashidator
- Defined in:
- lib/hashidator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#schema ⇒ Object
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(schema) ⇒ Hashidator
constructor
A new instance of Hashidator.
- #validate(input) ⇒ Object
Constructor Details
#initialize(schema) ⇒ Hashidator
Returns a new instance of Hashidator.
9 10 11 |
# File 'lib/hashidator.rb', line 9 def initialize(schema) @schema = schema end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/hashidator.rb', line 7 def errors @errors end |
#schema ⇒ Object
Returns the value of attribute schema.
7 8 9 |
# File 'lib/hashidator.rb', line 7 def schema @schema end |
Class Method Details
.validate(schema, input) ⇒ Object
2 3 4 5 |
# File 'lib/hashidator.rb', line 2 def self.validate(schema, input) hd = new(schema) hd.validate(input) end |
Instance Method Details
#validate(input) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hashidator.rb', line 13 def validate(input) results = schema.map { |key, validator| validate_value(validator, input[key]) } results.all? end |