epb_view_models 1.0.11 → 1.0.12
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 +4 -4
- data/lib/epb_view_models.rb +1 -1
- data/lib/presenter/xsd.rb +26 -8
- data/lib/view_model_domain/xsd_arguments.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa9014f126ebe6df35a45f9be7898fe71ebf4253739d537c62ab133f976480a
|
4
|
+
data.tar.gz: 9de075f8be11ba4626d771128e75f72917edfb3797eeee2f4bac4c6252df32d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea8139966fc1c55555be100e3ecb63a19364eb6e027c631aa1865a753af2577abee1c00ab53edb78436754fdd89db0aa331a42518cdf1bea5b03b242be48023
|
7
|
+
data.tar.gz: cefc2119116d4aab5c1299dd71f609df481e4ca2327a17a8bca256d83a92eeefed2e17127650e3d24d86fdd39445306d8456439947c55db20119168414ce50c7
|
data/lib/epb_view_models.rb
CHANGED
data/lib/presenter/xsd.rb
CHANGED
@@ -10,22 +10,16 @@ module Presenter
|
|
10
10
|
end
|
11
11
|
|
12
12
|
hash = {}
|
13
|
-
xpath = "//xs:simpleType[@name='#{domain_arguments.simple_type}']//xs:enumeration"
|
14
13
|
|
15
14
|
xsd_files.each do |file|
|
16
|
-
|
17
|
-
enums_hash = {}
|
18
|
-
REXML::XPath.each(doc, "#{xpath}/@value") do |node|
|
19
|
-
desc_path = "#{xpath}[@value='#{node.value}']//xs:annotation//xs:documentation"
|
20
|
-
enums_hash.merge!(node.value => REXML::XPath.first(doc, desc_path).children.first)
|
21
|
-
end
|
15
|
+
enums_hash = File.extname(file).downcase == ".xsd" ? read_xsd(file, domain_arguments.simple_type) : read_xml(file, domain_arguments.simple_type, domain_arguments.node_hash)
|
22
16
|
|
23
17
|
next if enums_hash.empty?
|
24
18
|
|
25
19
|
hash[xsd_files_gateway.schema_version(file)] = enums_hash
|
26
20
|
end
|
27
21
|
|
28
|
-
raise ViewModelBoundary::NodeNotFound, "Node #{domain_arguments.simple_type} was not found in any of the
|
22
|
+
raise ViewModelBoundary::NodeNotFound, "Node #{domain_arguments.simple_type} was not found in any of the files in #{domain_arguments.xsd_dir_path} directory" if hash.empty?
|
29
23
|
|
30
24
|
hash
|
31
25
|
end
|
@@ -45,5 +39,29 @@ module Presenter
|
|
45
39
|
def variation_between_schema_versions?(enums_hash)
|
46
40
|
enums_hash.values.flatten.uniq.count != 1
|
47
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def read_xsd(file_name, simple_type)
|
46
|
+
xpath = "//xs:simpleType[@name='#{simple_type}']//xs:enumeration"
|
47
|
+
doc = REXML::Document.new(File.read(file_name))
|
48
|
+
enums_hash = {}
|
49
|
+
REXML::XPath.each(doc, "#{xpath}/@value") do |node|
|
50
|
+
desc_path = "#{xpath}[@value='#{node.value}']//xs:annotation//xs:documentation"
|
51
|
+
enums_hash.merge!(node.value => REXML::XPath.first(doc, desc_path).children.first)
|
52
|
+
end
|
53
|
+
enums_hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def read_xml(file_name, node_name, node_hash)
|
57
|
+
doc = Nokogiri.XML(File.read(file_name))
|
58
|
+
enums_hash = {}
|
59
|
+
|
60
|
+
doc.xpath(node_name).each do |node|
|
61
|
+
enums_hash.merge!(node.xpath(node_hash.keys[0].to_s).children.text => node.xpath(node_hash.values[0]).children.text)
|
62
|
+
end
|
63
|
+
|
64
|
+
enums_hash
|
65
|
+
end
|
48
66
|
end
|
49
67
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module ViewModelDomain
|
2
2
|
class XsdArguments
|
3
|
-
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :gem_path
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :gem_path, :node_hash
|
4
4
|
|
5
|
-
def initialize(simple_type:, assessment_type:, xsd_dir_path: "", gem_path: "")
|
5
|
+
def initialize(simple_type:, assessment_type:, xsd_dir_path: "", gem_path: "", node_hash: nil)
|
6
6
|
@simple_type = simple_type
|
7
7
|
@assessment_type = assessment_type
|
8
8
|
@xsd_dir_path = xsd_dir_path
|
9
9
|
@gem_path = gem_path
|
10
|
+
@node_hash = node_hash
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epb_view_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MHCLG Energy Performance of Buildings
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|