Class: Fitting::Records::Unit::JsonSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/records/unit/json_schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(json_schema, tested_bodies) ⇒ JsonSchema

Returns a new instance of JsonSchema.



7
8
9
10
# File 'lib/fitting/records/unit/json_schema.rb', line 7

def initialize(json_schema, tested_bodies)
  @json_schema = json_schema
  @tested_bodies = tested_bodies
end

Instance Method Details

#bodiesObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/fitting/records/unit/json_schema.rb', line 12

def bodies
  @bodies ||= @tested_bodies.inject([]) do |res, tested_body|
    begin
      next res unless JSON::Validator.validate(@json_schema, tested_body)
      res.push(tested_body)
    rescue JSON::Schema::UriError
      res.push(tested_body)
    end
  end
end