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
- #combinations_with_one_of ⇒ Object
- #cover ⇒ Object
- #cover_enum ⇒ Object
- #cover_one_of ⇒ 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.
13 14 15 16 |
# File 'lib/fitting/records/unit/json_schema.rb', line 13 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.
11 12 13 |
# File 'lib/fitting/records/unit/json_schema.rb', line 11 def json_schema @json_schema end |
Instance Method Details
#bodies ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fitting/records/unit/json_schema.rb', line 18 def bodies @bodies ||= @tested_bodies.inject([]) do |res, tested_body| next res unless JSON::Validator.validate(@json_schema, tested_body) res.push(tested_body) rescue JSON::Schema::UriError res.push(tested_body) end end |
#combinations ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fitting/records/unit/json_schema.rb', line 42 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 |
#combinations_with_one_of ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fitting/records/unit/json_schema.rb', line 57 def combinations_with_one_of return @combinations_with_one_of if @combinations_with_one_of @combinations_with_one_of = [] qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi + Fitting::Cover::JSONSchemaOneOf.new(@json_schema).combi qwe.map do |comb| @combinations_with_one_of.push(Fitting::Records::Unit::Combination.new( comb, bodies )) end @combinations_with_one_of end |
#cover ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fitting/records/unit/json_schema.rb', line 73 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
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fitting/records/unit/json_schema.rb', line 85 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 |
#cover_one_of ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fitting/records/unit/json_schema.rb', line 97 def cover_one_of @cover_one_of ||= if bodies == [] 0 else count = 0 combinations_with_one_of.map do |combination| count += 1 unless combination.valid_bodies == [] end (count + 1) * 100 / (combinations_with_one_of.size + 1) end end |