circuitdata 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 632b6dce93cc547fc056096f00efcc01f79bbab3
4
- data.tar.gz: fa0edc6a62b0099464d26f46ccb6b071d459a50f
3
+ metadata.gz: 8afe970dee794317aa4e6219eb0f0cb435c1c331
4
+ data.tar.gz: 962e808e99ac521bea079b088a72ae74f77732ac
5
5
  SHA512:
6
- metadata.gz: c641c9e7691ffe865cc3e2f7640d9d4d97e4d08094c41f34e6a668b2f10fa64ad745fee64b3e66733fbd4b71ce6e8d0b3b4a601d01f22251ff06bc1c58b55c0f
7
- data.tar.gz: 95407595a7864527031ba43e056e5e415e6e52fb6ceed2d86a967a38198fddf37974b60ae6cafadb1885ca566bc7b5045a9894b47681a2170d4bd3ef6b8ceb00
6
+ metadata.gz: 080aa1a98c41639323b76924a5a10bc569f2288a8bf546d97c18d5bb0dc27654df3fc5dd03459b1b3b19721c0bb72de54217f11ab8a92ccdd0ea123d1cffc30b
7
+ data.tar.gz: 9f8de21fbd3db36e5ff24e6484ebb81a7d27ef3beec49240aec83514cd593c742a8449610f5ff3fde7adb78fb5d02381f2818204ebeff26613b996bc6f508a74
data/lib/circuitdata.rb CHANGED
@@ -1,6 +1,125 @@
1
1
  module Circuitdata
2
+
3
+
4
+ def self.content(checksjson)
5
+ product = false
6
+ stackup = false
7
+ profile_defaults = false
8
+ profile_enforced = false
9
+ profile_restricted = false
10
+ capabilities = false
11
+ if checksjson.has_key? "open_trade_transfer_package"
12
+ if checksjson["open_trade_transfer_package"].has_key? "products"
13
+ if checksjson["open_trade_transfer_package"]["products"].length > 0
14
+ product = true
15
+ checksjson["open_trade_transfer_package"]["products"].each do |key, value|
16
+ if checksjson["open_trade_transfer_package"]["products"][key].has_key? "stackup"
17
+ if checksjson["open_trade_transfer_package"]["products"][key]["stackup"].has_key? "specification_level"
18
+ if checksjson["open_trade_transfer_package"]["products"][key]["stackup"]["specification_level"] == "specified"
19
+ if checksjson["open_trade_transfer_package"]["products"][key]["stackup"].has_key? "specified"
20
+ if checksjson["open_trade_transfer_package"]["products"][key]["stackup"]["specified"].length > 0
21
+ stackup = true
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ if checksjson["open_trade_transfer_package"].has_key? "profiles"
31
+ if checksjson["open_trade_transfer_package"]["profiles"].has_key? "enforced"
32
+ if checksjson["open_trade_transfer_package"]["profiles"]["enforced"].length > 0
33
+ profile_enforced = true
34
+ end
35
+ end
36
+ if checksjson["open_trade_transfer_package"]["profiles"].has_key? "restricted"
37
+ if checksjson["open_trade_transfer_package"]["profiles"]["restricted"].length > 0
38
+ profile_restricted = true
39
+ end
40
+ end
41
+ if checksjson["open_trade_transfer_package"]["profiles"].has_key? "defaults"
42
+ if checksjson["open_trade_transfer_package"]["profiles"]["defaults"].length > 0
43
+ profile_defaults = true
44
+ end
45
+ end
46
+ end
47
+ if checksjson["open_trade_transfer_package"].has_key? "capabilities"
48
+ if checksjson["open_trade_transfer_package"]["capabilities"].length > 0
49
+ capabilities = true
50
+ end
51
+ end
52
+ end
53
+ return product, stackup, profile_defaults, profile_restricted, profile_enforced, capabilities
54
+ end
55
+
56
+ def self.read_json(content)
57
+
58
+ require 'open-uri'
59
+ require 'json'
60
+
61
+ error = false
62
+ message = ""
63
+ returncontent = nil
64
+ if content.is_a? Hash
65
+ begin
66
+ returncontent = JSON.parse(content)
67
+ rescue
68
+ error = true
69
+ message = "Could not convert the Hash into JSON"
70
+ end
71
+ else
72
+ begin
73
+ open(content) do |f|
74
+ returncontent = JSON.parse(f.read)
75
+ end
76
+ rescue
77
+ error = true
78
+ message = "Could not read the file"
79
+ end
80
+ end
81
+ return error, message, returncontent
82
+ end
83
+
84
+ def self.validate(content)
85
+ require 'json-schema'
86
+ $jsonschema_v1 = 'http://schema.circuitdata.org/v1/ottp_circuitdata_schema.json'
87
+
88
+ error = false
89
+ message = ""
90
+ validationserrors = {}
91
+
92
+ begin
93
+ validated = JSON::Validator.fully_validate($jsonschema_v1, content, :errors_as_objects => true)
94
+ rescue JSON::Schema::ReadFailed
95
+ errors = true
96
+ message = "Could not read the schema #{$jsonschema_v1}"
97
+ rescue JSON::Schema::SchemaError
98
+ errors = true
99
+ message = "Something was wrong with the schema #{$jsonschema_v1}"
100
+ end
101
+ unless errors
102
+ if validated.count > 0
103
+ error = true
104
+ message = "Could not validate the file against the CircuitData json schema"
105
+ validated.each do |valerror|
106
+ validationserrors[valerror[:fragment]] = [] unless validationserrors.has_key? valerror[:fragment]
107
+ begin
108
+ scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema\\sfile[\\s\\S]*)$").captures
109
+ rescue
110
+ keep = valerror[:message]
111
+ end
112
+ validationserrors[valerror[:fragment]] << keep
113
+ end
114
+ end
115
+ end
116
+ return error, message, validationserrors
117
+
118
+ end
119
+
2
120
  def self.compatibility_checker( productfile, checksfile=nil, validate_origins=true )
3
121
 
122
+ require 'open-uri'
4
123
  require 'json'
5
124
  require 'json-schema'
6
125
 
@@ -14,134 +133,96 @@ module Circuitdata
14
133
  restrictederrors: {},
15
134
  enforcederrors: {},
16
135
  capabilitieserrors: {},
136
+ contains: {
137
+ file1: {
138
+ product: false,
139
+ stackup: false,
140
+ profile_defaults: false,
141
+ profile_enforced: false,
142
+ profile_restricted: false,
143
+ capabilities: false
144
+ },
145
+ file2: {
146
+ product: false,
147
+ stackup: false,
148
+ profile_defaults: false,
149
+ profile_enforced: false,
150
+ profile_restricted: false,
151
+ capabilities: false
152
+ }
153
+ }
17
154
  }
18
155
 
19
- unless productfile.is_a? Hash
20
- # Check to see if the URIs are correct on the received files
21
- if not File.exist?(productfile)
22
- returnarray[:error] = true
23
- returnarray[:errormessage] = "Could not access the file to test"
24
- return returnarray
25
- end
26
- end
27
- unless checksfile.is_a? Hash
28
- if not checksfile.nil?
29
- if not File.exist?(checksfile)
30
- returnarray[:error] = true
31
- returnarray[:errormessage] = "Could not access the file to check agains (profile or capability)"
32
- return returnarray
33
- end
34
- end
156
+ # Check the files or hashes
157
+ #
158
+ returnarray[:error], returnarray[:errormessage], json_productfile = self.read_json(productfile)
159
+ return returnarray if returnarray[:error]
160
+ if not checksfile.nil?
161
+ returnarray[:error], returnarray[:errormessage], json_checksfile = self.read_json(checksfile)
162
+ return returnarray if returnarray[:error]
35
163
  end
36
164
 
37
165
  # Validate the original files against the CircuitData schema
38
166
  if validate_origins
39
- $error = false
40
- begin
41
- prod = JSON::Validator.fully_validate($jsonschema_v1, productfile, :errors_as_objects => true)
42
- rescue JSON::Schema::ReadFailed
43
- $errors = true
44
- returnarray[:error] = true
45
- returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
46
- rescue JSON::Schema::SchemaError
47
- $errors = true
48
- returnarray[:error] = true
49
- returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
50
- end
51
- unless $errors
52
- if prod.count > 0
53
- returnarray[:error] = true
54
- returnarray[:errormessage] = "Could not validate the product file against the CircuitData json schema"
55
- prod.each do |valerror|
56
- returnarray[:validationserrors][valerror[:fragment]] = [] unless returnarray[:validationserrors].has_key? valerror[:fragment]
57
- begin
58
- scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema\\sfile[\\s\\S]*)$").captures
59
- rescue
60
- keep = valerror[:message]
61
- end
62
- returnarray[:validationserrors][valerror[:fragment]] << keep
63
- end
64
- end
65
- end
167
+ returnarray[:error], returnarray[:errormessage], returnarray[:validationserrors] = self.validate(json_productfile)
168
+ return returnarray if returnarray[:error]
66
169
  if not checksfile.nil?
67
- $error = false
68
- begin
69
- checks = JSON::Validator.fully_validate($jsonschema_v1, checksfile, :errors_as_objects => true)
70
- rescue JSON::Schema::ReadFailed
71
- $errors = true
72
- returnarray[:error] = true
73
- returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
74
- rescue JSON::Schema::SchemaError
75
- $errors = true
76
- returnarray[:error] = true
77
- returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
78
- end
79
- unless $errors
80
- if checks.count > 0
81
- returnarray[:error] = true
82
- returnarray[:errormessage] = "Could not validate the file to check agains (profile or capability) against the CircuitData json schema"
83
- checks.each do |valerror|
84
- returnarray[:validationserrors][valerror[:fragment]] = [] unless returnarray[:validationserrors].has_key? valerror[:fragment]
85
- begin
86
- scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema\\sfile[\\s\\S]*)$").captures
87
- rescue
88
- keep = valerror[:message]
89
- end
90
- returnarray[:validationserrors][valerror[:fragment]] << keep
91
- end
92
- return returnarray
93
- end
94
- end
170
+ returnarray[:error], returnarray[:errormessage], returnarray[:validationserrors] = self.validate(json_checksfile)
171
+ return returnarray if returnarray[:error]
95
172
  end
96
173
  end
97
174
 
175
+ # Check against the content
176
+ returnarray[:contains][:file1][:product], returnarray[:contains][:file1][:stackup], returnarray[:contains][:file1][:profile_defaults], returnarray[:contains][:file1][:profile_restricted], returnarray[:contains][:file1][:profile_enforced], returnarray[:contains][:file1][:capabilities] = self.content(json_productfile)
98
177
  if not checksfile.nil?
99
- $has_restrictions = false
100
- $has_enforced = false
101
- $has_capabilities = false
178
+ returnarray[:contains][:file2][:product], returnarray[:contains][:file2][:stackup], returnarray[:contains][:file2][:profile_defaults], returnarray[:contains][:file2][:profile_restricted], returnarray[:contains][:file2][:profile_enforced], returnarray[:contains][:file2][:capabilities] = self.content(json_checksfile)
179
+ end
102
180
 
181
+ if not checksfile.nil?
103
182
 
183
+ # Create the JSON
104
184
  restrictedschema = enforcedschema = capabilityschema = {
105
- "$schema": "http://json-schema.org/draft-04/schema#",
106
- "type": "object",
107
- "additionalProperties": false,
108
- "required": ["open_trade_transfer_package"],
109
- "properties": {
110
- "open_trade_transfer_package": {
111
- "type": "object",
112
- "properties": {
113
- "version": {
114
- "type": "string",
115
- "pattern": "^1.0$"
116
- },
117
- "information": {
118
- "$ref": "https://raw.githubusercontent.com/elmatica/Open-Trade-Transfer-Package/master/v1/ottp_schema_definitions.json#/definitions/information"
119
- },
120
- "products": {
121
- "type": "object",
122
- "properties": {
123
- "generic": {
124
- "type": "object",
125
- "properties": {},
126
- "id": "generic",
127
- "description": "this should validate any element under generic to be valid"
128
- }
185
+ "$schema": "http://json-schema.org/draft-04/schema#",
186
+ "type": "object",
187
+ "additionalProperties": false,
188
+ "required": ["open_trade_transfer_package"],
189
+ "properties": {
190
+ "open_trade_transfer_package": {
191
+ "type": "object",
192
+ "properties": {
193
+ "version": {
194
+ "type": "string",
195
+ "pattern": "^1.0$"
196
+ },
197
+ "information": {
198
+ "$ref": "https://raw.githubusercontent.com/elmatica/Open-Trade-Transfer-Package/master/v1/ottp_schema_definitions.json#/definitions/information"
129
199
  },
130
- "patternProperties": {
131
- "^(?!generic$).*": {
132
- "type": "object",
133
- "required": ["printed_circuits_fabrication_data"],
134
- "properties": {
135
- "printed_circuits_fabrication_data": {
136
- "type": "object",
137
- "required": ["version"],
138
- "properties": {
139
- "stackup": {
140
- "type": "object",
141
- "properties": {
142
- "specified": {
143
- "type": "object",
144
- "properties": {
200
+ "products": {
201
+ "type": "object",
202
+ "properties": {
203
+ "generic": {
204
+ "type": "object",
205
+ "properties": {},
206
+ "id": "generic",
207
+ "description": "this should validate any element under generic to be valid"
208
+ }
209
+ },
210
+ "patternProperties": {
211
+ "^(?!generic$).*": {
212
+ "type": "object",
213
+ "required": ["printed_circuits_fabrication_data"],
214
+ "properties": {
215
+ "printed_circuits_fabrication_data": {
216
+ "type": "object",
217
+ "required": ["version"],
218
+ "properties": {
219
+ "stackup": {
220
+ "type": "object",
221
+ "properties": {
222
+ "specified": {
223
+ "type": "object",
224
+ "properties": {
225
+ }
145
226
  }
146
227
  }
147
228
  }
@@ -155,78 +236,119 @@ module Circuitdata
155
236
  }
156
237
  }
157
238
  }
158
- }
159
239
 
160
-
161
- checksjson = JSON.parse(File.read(checksfile))
162
- if checksjson["open_trade_transfer_package"].has_key? "profiles"
240
+ if returnarray[:contains][:file1][:product] or returnarray[:contains][:file1][:stackup]
163
241
  # RUN THROUGH THE ENFORCED
164
- if checksjson["open_trade_transfer_package"]["profiles"].has_key? "enforced"
165
- $has_enforced = true
166
- if checksjson["open_trade_transfer_package"]["profiles"]["enforced"].has_key? "printed_circuits_fabrication_data"
167
- checksjson["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"].each do |key, value|
168
- if checksjson["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].is_a? Hash
169
- checksjson["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
170
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
171
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
172
- if subvalue.is_a? String
173
- if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
174
- from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
175
- newhash = eval("{:minimum => #{from}, :maximum => #{too}}")
176
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
177
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
178
- else # This is a normal string - check for commas
179
- enum = []
180
- subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
181
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
182
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
183
- end
184
- elsif subvalue.is_a? Numeric # This is a normal string
185
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
186
- enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
242
+ if returnarray[:contains][:file2][:profile_enforced]
243
+ json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"].each do |key, value|
244
+ if json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].is_a? Hash
245
+ json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
246
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
247
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
248
+ if subvalue.is_a? String
249
+ if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
250
+ from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
251
+ newhash = eval("{:minimum => #{from}, :maximum => #{too}}")
252
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
253
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
254
+ else # This is a normal string - check for commas
255
+ enum = []
256
+ subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
257
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
258
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
187
259
  end
260
+ elsif subvalue.is_a? Numeric # This is a normal string
261
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
262
+ enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
263
+ end
264
+ end
265
+ end
266
+ end
267
+ begin
268
+ enforcedvalidate = JSON::Validator.fully_validate(enforcedschema.to_json, json_productfile, :errors_as_objects => true)
269
+ rescue JSON::Schema::ReadFailed
270
+ $errors = true
271
+ returnarray[:error] = true
272
+ returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
273
+ rescue JSON::Schema::SchemaError
274
+ $errors = true
275
+ returnarray[:error] = true
276
+ returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
277
+ end
278
+ unless $errors
279
+ if enforcedvalidate.count > 0
280
+ returnarray[:error] = true
281
+ returnarray[:errormessage] = "The product to check did not meet the requirements"
282
+ enforcedvalidate.each do |valerror|
283
+ returnarray[:enforcederrors][valerror[:fragment]] = [] unless returnarray[:enforcederrors].has_key? valerror[:fragment]
284
+ begin
285
+ scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
286
+ rescue
287
+ keep = valerror[:message]
188
288
  end
289
+ returnarray[:enforcederrors][valerror[:fragment]] << keep
189
290
  end
190
291
  end
191
292
  end
293
+ end
192
294
  # RUN THROUGH THE RESTRICTED
193
- elsif checksjson["open_trade_transfer_package"]["profiles"].has_key? "restricted"
194
- $has_restrictions = true
195
- if checksjson["open_trade_transfer_package"]["profiles"]["restricted"].has_key? "printed_circuits_fabrication_data"
196
- checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"].each do |key, value|
197
- if checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].is_a? Hash
198
- checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
199
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
200
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
201
- if subvalue.is_a? String
202
- if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
203
- from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
204
- newhash = {:not => {:allOf => [{:minimum => from.to_f},{:maximum => too.to_f}]}}
205
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
206
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
207
- else # This is a normal string - check for commas
208
- newhash = {:not => {:anyOf => [{ :enum => ""}]}}
209
- enum = []
210
- subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
211
- newhash[:not][:anyOf][0][:enum] = enum
212
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
213
- restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
214
- end
215
- elsif subvalue.is_a? Numeric # This is a normal string
216
- newhash = {:not => {:allOf => [{:minimum => subvalue.to_f},{:maximum => subvalue.to_f}]}}
295
+ if returnarray[:contains][:file2][:profile_restricted]
296
+ checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"].each do |key, value|
297
+ if checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].is_a? Hash
298
+ checksjson["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
299
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
300
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
301
+ if subvalue.is_a? String
302
+ if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
303
+ from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
304
+ newhash = {:not => {:allOf => [{:minimum => from.to_f},{:maximum => too.to_f}]}}
305
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
306
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
307
+ else # This is a normal string - check for commas
308
+ newhash = {:not => {:anyOf => [{ :enum => ""}]}}
309
+ enum = []
310
+ subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
311
+ newhash[:not][:anyOf][0][:enum] = enum
217
312
  restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
218
313
  restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
219
314
  end
315
+ elsif subvalue.is_a? Numeric # This is a normal string
316
+ newhash = {:not => {:allOf => [{:minimum => subvalue.to_f},{:maximum => subvalue.to_f}]}}
317
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
318
+ restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
220
319
  end
221
320
  end
222
321
  end
223
322
  end
323
+ begin
324
+ restrictedvalidate = JSON::Validator.fully_validate(restrictedschema.to_json, json_productfile, :errors_as_objects => true)
325
+ rescue JSON::Schema::ReadFailed
326
+ $errors = true
327
+ returnarray[:error] = true
328
+ returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
329
+ rescue JSON::Schema::SchemaError
330
+ $errors = true
331
+ returnarray[:error] = true
332
+ returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
333
+ end
334
+ unless $errors
335
+ if restrictedvalidate.count > 0
336
+ returnarray[:error] = true
337
+ returnarray[:errormessage] = "The product to check did not meet the requirements"
338
+ restrictedvalidate.each do |valerror|
339
+ returnarray[:restrictederrors][valerror[:fragment]] = [] unless returnarray[:restrictederrors].has_key? valerror[:fragment]
340
+ begin
341
+ scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
342
+ rescue
343
+ keep = valerror[:message]
344
+ end
345
+ returnarray[:restrictederrors][valerror[:fragment]] << keep
346
+ end
347
+ end
348
+ end
224
349
  end
225
- end
226
- # RUN THROUGH THE CAPABILITIES
227
- if checksjson["open_trade_transfer_package"].has_key? "capabilities"
228
- $has_capabilities = true
229
- if checksjson["open_trade_transfer_package"]["capabilities"].has_key? "printed_circuits_fabrication_data"
350
+ # RUN THROUGH THE CAPABILITIES
351
+ if returnarray[:contains][:file2][:capabilities]
230
352
  checksjson["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"].each do |key, value|
231
353
  if checksjson["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"][key].is_a? Hash
232
354
  checksjson["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
@@ -251,98 +373,30 @@ module Circuitdata
251
373
  end
252
374
  end
253
375
  end
254
- end
255
- end
256
-
257
- # Test enforced
258
- if $has_enforced
259
- $error = false
260
- begin
261
- enforcedvalidate = JSON::Validator.fully_validate(enforcedschema.to_json, productfile, :errors_as_objects => true)
262
- rescue JSON::Schema::ReadFailed
263
- $errors = true
264
- returnarray[:error] = true
265
- returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
266
- rescue JSON::Schema::SchemaError
267
- $errors = true
268
- returnarray[:error] = true
269
- returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
270
- end
271
- unless $errors
272
- if enforcedvalidate.count > 0
376
+ begin
377
+ capabilitiesvalidate = JSON::Validator.fully_validate(capabilityschema.to_json, json_productfile, :errors_as_objects => true)
378
+ rescue JSON::Schema::ReadFailed
379
+ $errors = true
273
380
  returnarray[:error] = true
274
- returnarray[:errormessage] = "The product to check did not meet the requirements"
275
- enforcedvalidate.each do |valerror|
276
- returnarray[:enforcederrors][valerror[:fragment]] = [] unless returnarray[:enforcederrors].has_key? valerror[:fragment]
277
- begin
278
- scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
279
- rescue
280
- keep = valerror[:message]
281
- end
282
- returnarray[:enforcederrors][valerror[:fragment]] << keep
283
- end
284
- end
285
- end
286
- end
287
-
288
-
289
- # Test restricted
290
- if $has_restrictions
291
- $error = false
292
- begin
293
- restrictedvalidate = JSON::Validator.fully_validate(restrictedschema.to_json, productfile, :errors_as_objects => true)
294
- rescue JSON::Schema::ReadFailed
295
- $errors = true
296
- returnarray[:error] = true
297
- returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
298
- rescue JSON::Schema::SchemaError
299
- $errors = true
300
- returnarray[:error] = true
301
- returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
302
- end
303
- unless $errors
304
- if restrictedvalidate.count > 0
381
+ returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
382
+ rescue JSON::Schema::SchemaError
383
+ $errors = true
305
384
  returnarray[:error] = true
306
- returnarray[:errormessage] = "The product to check did not meet the requirements"
307
- restrictedvalidate.each do |valerror|
308
- returnarray[:restrictederrors][valerror[:fragment]] = [] unless returnarray[:restrictederrors].has_key? valerror[:fragment]
309
- begin
310
- scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
311
- rescue
312
- keep = valerror[:message]
313
- end
314
- returnarray[:restrictederrors][valerror[:fragment]] << keep
315
- end
385
+ returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
316
386
  end
317
- end
318
- end
319
-
320
- # Test capabilites
321
- if $has_capabilities
322
- $error = false
323
- begin
324
- capabilitiesvalidate = JSON::Validator.fully_validate(capabilityschema.to_json, productfile, :errors_as_objects => true)
325
- rescue JSON::Schema::ReadFailed
326
- $errors = true
327
- returnarray[:error] = true
328
- returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
329
- rescue JSON::Schema::SchemaError
330
- $errors = true
331
- returnarray[:error] = true
332
- returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
333
- end
334
- unless $errors
335
- if capabilitiesvalidate.count > 0
336
- returnarray[:error] = true
337
- returnarray[:errormessage] = "The product to check did not meet the requirements"
338
- capabilitiesvalidate.each do |valerror|
339
- returnarray[:capabilitieserrors][valerror[:fragment]] = [] unless returnarray[:capabilitieserrors].has_key? valerror[:fragment]
340
- begin
341
- scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
342
- rescue
343
- keep = valerror[:message]
387
+ unless $errors
388
+ if capabilitiesvalidate.count > 0
389
+ returnarray[:error] = true
390
+ returnarray[:errormessage] = "The product to check did not meet the requirements"
391
+ capabilitiesvalidate.each do |valerror|
392
+ returnarray[:capabilitieserrors][valerror[:fragment]] = [] unless returnarray[:capabilitieserrors].has_key? valerror[:fragment]
393
+ begin
394
+ scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
395
+ rescue
396
+ keep = valerror[:message]
397
+ end
398
+ returnarray[:capabilitieserrors][valerror[:fragment]] << keep
344
399
  end
345
- returnarray[:capabilitieserrors][valerror[:fragment]] << keep
346
400
  end
347
401
  end
348
402
  end
@@ -1,3 +1,3 @@
1
1
  module Circuitdata
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuitdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Lydersen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema