validate_xml_xsi 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ea7f8a1a26dc8803332c448e4ab3609d9699f116f33ab3636a3cec9cf47c86b
4
- data.tar.gz: 9423b6a6cccd460ef5949d39340bd7330e898e9791160e747e70014763cc4ddc
3
+ metadata.gz: 4fa9e060212c9992fc22333d6858d9005c0f0be545a1f921c2324fda0071a634
4
+ data.tar.gz: 880b5e1af35f7cfb1f7c71f09b7fd676632bf921c3ecd5af657c6ce0e4b36df6
5
5
  SHA512:
6
- metadata.gz: 4ac1fdf7c33249fe3146fbb296dd10ec60f0a20b9cd9cbccf527fd408b66b3ed09c6d8a435c49b91f6c0e34ec452422d5d7cb2b8dab7045ba2e769e5035981f0
7
- data.tar.gz: 7c3b944868fdc9545a30b50a571e1cc5a30e6a75889a1a861bfe3964da56e02af8650d3290180b1dabcfdfd53b9819116a0ba8a7b44dbb6c5a63ed82c15f3a83
6
+ metadata.gz: 63187e958fc288c4722444b0b73464a8af4f94776516dd619feb33bc9cbafbdc69dfca7c72fe7184a95c7014a838fbf10245db6d126d4beea1f04049573ef7f8
7
+ data.tar.gz: '0975b1be594880e516af4b8a0e758c50eec6c1d4d92621d4e3c870cfcdddde2c1f32973812f3ff4167832958d62f8bb2afb1563db462557904e2b8471c12e3e4'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.2.0
2
+
3
+ * Change namespace to XML_XSI and rename/promote Validation::Error to Schema::ValidationError < StandardError.
4
+
1
5
  ## v0.1.4
2
6
 
3
7
  * Change module XML, Validation, & Schema to be classes instead.
@@ -1,18 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'nokogiri'
3
3
 
4
- class XML
5
- class Validation
6
- class Error
7
- Params = [:type, :file, :line, :column, :message, :err]
8
- attr_reader *Params, :description
9
- def initialize(*args)
10
- Params.each.with_index { |param, idx| instance_variable_set("@#{param.to_s}", args[idx]) }
11
- @description = "#{@type.to_s} ERROR [#{@file}:#{@line}:#{@column}]: #{@message}".freeze
12
- end
13
- end
14
- end
15
-
4
+ class XML_XSI
16
5
  def self.parse(obj)
17
6
  filename = nil
18
7
  obj = File::read(filename = obj) if obj.is_a?(String) && File::exist?(obj)
@@ -23,8 +12,18 @@ class XML
23
12
  end
24
13
 
25
14
  class Schema
15
+ class ValidationError < StandardError
16
+ Params = [:type, :file, :line, :column, :message, :err]
17
+ attr_reader *Params, :description
18
+ def initialize(*args)
19
+ Params.each.with_index { |param, idx| instance_variable_set("@#{param.to_s}", args[idx]) }
20
+ @description = "#{@type.to_s} ERROR [#{@file}:#{@line}:#{@column}]: #{@message}".freeze
21
+ super(@description)
22
+ end
23
+ end
24
+
26
25
  def self.validate(xml_doc)
27
- xml_doc = XML::parse(xml_doc) unless xml_doc.is_a?(Nokogiri::XML::Document)
26
+ xml_doc = XML_XSI::parse(xml_doc) unless xml_doc.is_a?(Nokogiri::XML::Document)
28
27
  errors = []
29
28
  ## Build an all-in-one XSD document that imports all of the separate schema locations
30
29
  xsd_doc = "<?xml version=\"1.0\"?>\n"
@@ -52,13 +51,13 @@ class XML
52
51
  xsd = Nokogiri::XML.Schema(xsd_doc)
53
52
  xsd.errors.each do |err|
54
53
  err_msg = (/ERROR: /.match(err.message)) ? $' : err.message
55
- errors << XML::Validation::Error.new(:XSD, err.file, err.line, err.column, err_msg, err)
54
+ errors << ValidationError.new(:XSD, err.file, err.line, err.column, err_msg, err)
56
55
  end
57
56
  errs = xsd.validate(xml_doc)
58
57
  errs.each do |err|
59
58
  err_msg = (/ERROR: /.match(err.message)) ? $' : err.message
60
59
  fname = (err.file.nil?) ? xml_doc.filename : err.file
61
- errors << XML::Validation::Error.new(:XML, fname, err.line, err.column, err_msg, err)
60
+ errors << ValidationError.new(:XML, fname, err.line, err.column, err_msg, err)
62
61
  end
63
62
  errors
64
63
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "validate_xml_xsi"
3
- spec.version = "0.1.4"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["David Hansen"]
5
5
  spec.email = ["david@hansen4.net"]
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_xml_xsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Hansen