Class: Hashidator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/hashidator.rb', line 7

def errors
  @errors
end

#schemaObject

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