Class: Fitting::Records::Unit::JsonSchema
- Inherits:
-
Object
- Object
- Fitting::Records::Unit::JsonSchema
- Defined in:
- lib/fitting/records/unit/json_schema.rb
Instance Attribute Summary collapse
-
#json_schema ⇒ Object
readonly
Returns the value of attribute json_schema.
Instance Method Summary collapse
- #bodies ⇒ Object
- #combinations ⇒ Object
- #combinations_with_enum ⇒ Object
- #cover ⇒ Object
- #cover_enum ⇒ Object
-
#initialize(json_schema, tested_bodies) ⇒ JsonSchema
constructor
A new instance of JsonSchema.
Constructor Details
#initialize(json_schema, tested_bodies) ⇒ JsonSchema
Returns a new instance of JsonSchema.
12 13 14 15 |
# File 'lib/fitting/records/unit/json_schema.rb', line 12 def initialize(json_schema, tested_bodies) @json_schema = json_schema @tested_bodies = tested_bodies end |
Instance Attribute Details
#json_schema ⇒ Object (readonly)
Returns the value of attribute json_schema.
10 11 12 |
# File 'lib/fitting/records/unit/json_schema.rb', line 10 def json_schema @json_schema end |
Instance Method Details
#bodies ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fitting/records/unit/json_schema.rb', line 17 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 |
#combinations ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fitting/records/unit/json_schema.rb', line 28 def combinations return @combinations if @combinations @combinations = [] cover_json_schema = Fitting::Cover::JSONSchema.new(@json_schema) cover_json_schema.combi.map do |comb| @combinations.push(Fitting::Records::Unit::Combination.new( comb, bodies )) end @combinations end |
#combinations_with_enum ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fitting/records/unit/json_schema.rb', line 41 def combinations_with_enum return @combinations_with_enum if @combinations_with_enum @combinations_with_enum = [] qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi qwe.map do |comb| @combinations_with_enum.push(Fitting::Records::Unit::Combination.new( comb, bodies )) end @combinations_with_enum end |
#cover ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fitting/records/unit/json_schema.rb', line 54 def cover @cover ||= if bodies == [] 0 else count = 0 combinations.map do |combination| count += 1 unless combination.valid_bodies == [] end (count + 1) * 100 / (combinations.size + 1) end end |
#cover_enum ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fitting/records/unit/json_schema.rb', line 66 def cover_enum @cover_enum ||= if bodies == [] 0 else count = 0 combinations_with_enum.map do |combination| count += 1 unless combination.valid_bodies == [] end (count + 1) * 100 / (combinations_with_enum.size + 1) end end |