epb_view_models 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/epb_view_models.rb +1 -1
- data/lib/presenter/xsd.rb +21 -48
- data/lib/view_model_boundary/node_not_found.rb +3 -0
- data/lib/view_model_boundary/xsd_files_not_found.rb +3 -0
- data/lib/view_model_domain/xsd_arguments.rb +12 -0
- data/lib/view_model_gateway/xsd_files_gateway.rb +55 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fe31a8b4317370e678562b7ce01baa5db0b8e48b8b185197c88285731a476b
|
4
|
+
data.tar.gz: 73542839d5a7ac83b87698248308e46faa5397f94c8a63758ebdfd4a93f42a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27154cc9e7eb4e48f595042cf2e100093647307e62fd6552f57d9e782d5926232fa67d0cb07c0f8767582fe6e123ec165db33efe62b7ca2fd73e237af87e9107
|
7
|
+
data.tar.gz: 2d05b80c15f37828f1da3ac56857843e21fc33b138c9bfd8109e7a74f9defb64042155a3a84fc6343e99ffea5353cc157f5d8ef6337ac2be30de29036e1c4b94
|
data/lib/epb_view_models.rb
CHANGED
data/lib/presenter/xsd.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
1
|
module Presenter
|
2
2
|
class Xsd
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def get_enums_by_type(domain_arguments)
|
4
|
+
xsd_files_gateway = ViewModelGateway::XsdFilesGateway.new(domain_arguments)
|
5
|
+
|
6
|
+
begin
|
7
|
+
xsd_files = xsd_files_gateway.xsd_files
|
8
|
+
rescue ViewModelBoundary::XsdFilesNotFound => e
|
9
|
+
raise ViewModelBoundary::XsdFilesNotFound, e.message.to_s
|
10
|
+
end
|
7
11
|
|
8
|
-
def get_enums_by_type(simple_type)
|
9
12
|
hash = {}
|
10
|
-
xpath = "//xs:simpleType[@name='#{simple_type}']//xs:enumeration"
|
11
|
-
|
12
|
-
|
13
|
+
xpath = "//xs:simpleType[@name='#{domain_arguments.simple_type}']//xs:enumeration"
|
14
|
+
|
15
|
+
xsd_files.each do |file|
|
16
|
+
doc = REXML::Document.new(File.read(file))
|
13
17
|
enums_hash = {}
|
14
|
-
REXML::XPath.each(doc, "#{xpath}/@value") do |
|
15
|
-
desc_path = "#{xpath}[@value='#{
|
16
|
-
enums_hash.merge!(
|
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)
|
17
21
|
end
|
18
22
|
|
19
23
|
next if enums_hash.empty?
|
20
24
|
|
21
|
-
hash[schema_version(
|
25
|
+
hash[xsd_files_gateway.schema_version(file)] = enums_hash
|
22
26
|
end
|
27
|
+
|
28
|
+
raise ViewModelBoundary::NodeNotFound, "Node #{domain_arguments.simple_type} was not found in any of the xsd files in #{domain_arguments.xsd_dir_path} directory" if hash.empty?
|
29
|
+
|
23
30
|
hash
|
24
31
|
end
|
25
32
|
|
26
|
-
def unique_enums(
|
33
|
+
def unique_enums(domain_arguments)
|
27
34
|
uniq_enums = []
|
28
|
-
enums = get_enums_by_type(
|
35
|
+
enums = get_enums_by_type(domain_arguments).values
|
29
36
|
|
30
37
|
enums.each_with_index do |_hash, i|
|
31
38
|
if i.positive? && (enums[i].to_a != enums[i + 1].to_a)
|
@@ -38,39 +45,5 @@ module Presenter
|
|
38
45
|
def variation_between_schema_versions?(enums_hash)
|
39
46
|
enums_hash.values.flatten.uniq.count != 1
|
40
47
|
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def schema_version(file_name)
|
45
|
-
schema_version = file_name.delete_prefix("api/schemas/xml/").split("/").first
|
46
|
-
sap_defnied_in_rdsap_dir?(file_name) ? "#{schema_version}/SAP" : schema_version
|
47
|
-
end
|
48
|
-
|
49
|
-
def xsd_files
|
50
|
-
case @assessment_type
|
51
|
-
when "SAP"
|
52
|
-
sap_xsd_files
|
53
|
-
when "RdSAP"
|
54
|
-
rdsap_xsd_files
|
55
|
-
when "CEPC"
|
56
|
-
cepc_xsd_files
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def sap_xsd_files
|
61
|
-
Dir.glob("#{@xsd_dir_path}*-Domains.xsd")
|
62
|
-
end
|
63
|
-
|
64
|
-
def rdsap_xsd_files
|
65
|
-
Dir.glob("#{@xsd_dir_path}SAP-Domains.xsd")
|
66
|
-
end
|
67
|
-
|
68
|
-
def cepc_xsd_files
|
69
|
-
Dir.glob("#{@xsd_dir_path}Reported-Data.xsd")
|
70
|
-
end
|
71
|
-
|
72
|
-
def sap_defnied_in_rdsap_dir?(file_name)
|
73
|
-
@assessment_type == "SAP" && file_name.end_with?("SAP-Domains.xsd")
|
74
|
-
end
|
75
48
|
end
|
76
49
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ViewModelDomain
|
2
|
+
class XsdArguments
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :gem_path
|
4
|
+
|
5
|
+
def initialize(simple_type:, assessment_type:, xsd_dir_path: "/api/schemas/xml/**/", gem_path: "")
|
6
|
+
@simple_type = simple_type
|
7
|
+
@assessment_type = assessment_type
|
8
|
+
@xsd_dir_path = xsd_dir_path
|
9
|
+
@gem_path = gem_path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ViewModelGateway
|
2
|
+
class XsdFilesGateway
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :glob_path
|
4
|
+
|
5
|
+
def initialize(domain_arguments)
|
6
|
+
@simple_type = domain_arguments.simple_type
|
7
|
+
@assessment_type = domain_arguments.assessment_type
|
8
|
+
@xsd_dir_path = domain_arguments.xsd_dir_path
|
9
|
+
@dir_path = Dir.pwd if domain_arguments.gem_path.nil? || domain_arguments.gem_path.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def schema_version(file)
|
13
|
+
api_path = "api/schemas/xml/"
|
14
|
+
api_path_start = file.index(api_path) + api_path.length
|
15
|
+
schema_version = file[api_path_start..].split("/").first
|
16
|
+
sap_defnied_in_rdsap_dir?(file) ? "#{schema_version}/SAP" : schema_version
|
17
|
+
end
|
18
|
+
|
19
|
+
def xsd_files
|
20
|
+
files = case @assessment_type.downcase
|
21
|
+
when "sap"
|
22
|
+
sap_xsd_files
|
23
|
+
when "rdsap"
|
24
|
+
rdsap_xsd_files
|
25
|
+
when "cepc"
|
26
|
+
cepc_xsd_files
|
27
|
+
end
|
28
|
+
|
29
|
+
raise ViewModelBoundary::XsdFilesNotFound, "No xsd files were found in #{@glob_path} directory" if files.nil? || files.empty?
|
30
|
+
|
31
|
+
files
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def sap_defnied_in_rdsap_dir?(file)
|
37
|
+
assessment_type == "SAP" && file.end_with?("SAP-Domains.xsd")
|
38
|
+
end
|
39
|
+
|
40
|
+
def sap_xsd_files
|
41
|
+
@glob_path = "#{@dir_path + xsd_dir_path}*-Domains.xsd"
|
42
|
+
Dir.glob(@glob_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def rdsap_xsd_files
|
46
|
+
@glob_path = "#{@dir_path + xsd_dir_path}*-Domains.xsd"
|
47
|
+
Dir.glob(@glob_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def cepc_xsd_files
|
51
|
+
@glob_path = "#{@dir_path + xsd_dir_path}Reported-Data.xsd"
|
52
|
+
Dir.glob(@glob_path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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.10
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -1821,6 +1821,10 @@ files:
|
|
1821
1821
|
- lib/view_model/sap_schema_ni_174/common_schema.rb
|
1822
1822
|
- lib/view_model/sap_schema_ni_1800/common_schema.rb
|
1823
1823
|
- lib/view_model/sap_wrapper.rb
|
1824
|
+
- lib/view_model_boundary/node_not_found.rb
|
1825
|
+
- lib/view_model_boundary/xsd_files_not_found.rb
|
1826
|
+
- lib/view_model_domain/xsd_arguments.rb
|
1827
|
+
- lib/view_model_gateway/xsd_files_gateway.rb
|
1824
1828
|
homepage: https://github.com/communitiesuk/epb-view-models
|
1825
1829
|
licenses:
|
1826
1830
|
- MIT
|