epb_view_models 1.0.7 → 1.0.11

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: e84293861022176f883ddae06d91d887da347b27ca44d9ed52ad2bb7135d0a53
4
- data.tar.gz: 0cb5910f39ba8e6272c2427b3255346005e5c5636777334158a457f258807f71
3
+ metadata.gz: f71a412d77bf50228e2736594bce2312c64b088dc80a7e0708b3606fcb9f3e2c
4
+ data.tar.gz: 4d2e94eafa908f2a26ea7aa09e2940fa2461ded527a620f0ebf6a29d9a34281e
5
5
  SHA512:
6
- metadata.gz: 243a54697bca19151c977439193fa2b2651235f4289a9c853916ba91d9237fed64e67ca4df8cd6351a77bae268ecdcc6b29e8ea55cb0b95887fd202703f33a39
7
- data.tar.gz: 5e0182f480eef682e2b46c4335161ec1e68e3c3463f95ec5609ee7b6103cd8ba87f682da26c362d120ff3b884a21090fd6c3aa88761aa9c478277e3a96ed2f76
6
+ metadata.gz: 82cb7dcc22da7a1d5033a65a3cd57ec67827a7dcbf31bcc45cc328de2746a376457feb120143cdc22a6f6367acb2bf5a722bb55044308d4f4cfe1bd1734914e1
7
+ data.tar.gz: 54c8b796430bb11ff37474b65b80db256fbddccdb88d516404baab6b720ff86c8ecbd2ad703bece026a0b61d0f3f75dfd0c3342100c4ee56c0bdce9d1027462a
data/Gemfile CHANGED
@@ -10,5 +10,6 @@ source "https://rubygems.org" do
10
10
  end
11
11
 
12
12
  gem "nokogiri", "~> 1.11"
13
+ gem "rexml", "~> 3.2", ">= 3.2.5"
13
14
  gem "zeitwerk", "~> 2.4.2"
14
15
  end
data/Gemfile.lock CHANGED
@@ -83,6 +83,7 @@ PLATFORMS
83
83
  DEPENDENCIES
84
84
  nokogiri (~> 1.11)!
85
85
  rake (~> 13.0.6)!
86
+ rexml (~> 3.2, >= 3.2.5)!
86
87
  rspec (~> 3.0)!
87
88
  rubocop-govuk (~> 4.0.0)!
88
89
  zeitwerk (~> 2.4.2)!
@@ -5,7 +5,7 @@ loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup
6
6
 
7
7
  module EpbViewModels
8
- VERSION = "1.0.7"
8
+ VERSION = "1.0.11"
9
9
  end
10
10
 
11
11
  # Monkey patching to avoid using ActiveRecord::Type::Boolean.new.cast
@@ -163,7 +163,7 @@ module Helper
163
163
  "6" => "mechanical extract, decentralised (MEV dc)",
164
164
  "7" => "balanced without heat recovery (MV)",
165
165
  "8" => "balanced with heat recovery (MVHR)",
166
- "9" => "natural with intermittent extract fans and/or passive vents. For backwards compatibility only, do not use.",
166
+ "9" => "natural with intermittent extract fans and/or passive vents. For backwards compatibility only, do not use.",
167
167
  "10" => "natural with intermittent extract fans and passive vents",
168
168
  }.freeze
169
169
  CYLINDER_INSULATION_THICKNESS = {
@@ -306,7 +306,7 @@ module Helper
306
306
  end
307
307
 
308
308
  def self.transaction_type(value, report_type = "2", schema_type = "")
309
- types_of_ni = %w[
309
+ types_of_ni = %i[
310
310
  RdSAP-Schema-NI-20.0.0
311
311
  RdSAP-Schema-NI-19.0
312
312
  RdSAP-Schema-NI-18.0
@@ -464,14 +464,13 @@ module Helper
464
464
  end
465
465
 
466
466
  def self.mechanical_ventilation(value, schema_type, report_type)
467
- types_of_sap_pre12 = %w[
467
+ types_of_sap_pre12 = %i[
468
468
  SAP-Schema-11.2
469
469
  SAP-Schema-11.0
470
470
  SAP-Schema-10.2
471
471
  SAP-Schema-NI-11.2
472
472
  ].freeze
473
-
474
- if types_of_sap_pre12.include?(schema_type.to_s) && is_rdsap(report_type)
473
+ if types_of_sap_pre12.include?(schema_type) && is_rdsap(report_type)
475
474
  return MECHANICAL_VENTILATION["#{value}-pre12.0"]
476
475
  end
477
476
 
@@ -499,7 +498,7 @@ module Helper
499
498
  end
500
499
 
501
500
  def self.ventilation_type(value, schema_type = "")
502
- ni_sap = %w[
501
+ ni_sap = %i[
503
502
  SAP-Schema-NI-16.1
504
503
  SAP-Schema-NI-16.0
505
504
  SAP-Schema-NI-15.0
@@ -0,0 +1,49 @@
1
+ module Presenter
2
+ class Xsd
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
11
+
12
+ hash = {}
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))
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
22
+
23
+ next if enums_hash.empty?
24
+
25
+ hash[xsd_files_gateway.schema_version(file)] = enums_hash
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
+
30
+ hash
31
+ end
32
+
33
+ def unique_enums(domain_arguments)
34
+ uniq_enums = []
35
+ enums = get_enums_by_type(domain_arguments).values
36
+
37
+ enums.each_with_index do |_hash, i|
38
+ if i.positive? && (enums[i].to_a != enums[i + 1].to_a)
39
+ uniq_enums << enums[i]
40
+ end
41
+ end
42
+ uniq_enums
43
+ end
44
+
45
+ def variation_between_schema_versions?(enums_hash)
46
+ enums_hash.values.flatten.uniq.count != 1
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module ViewModelBoundary
2
+ class NodeNotFound < StandardError; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module ViewModelBoundary
2
+ class XsdFilesNotFound < StandardError; end
3
+ 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: "", 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,61 @@
1
+ module ViewModelGateway
2
+ class XsdFilesGateway
3
+ attr_reader :simple_type, :assessment_type, :xsd_dir_path, :glob_path
4
+
5
+ API_PATH = "api/schemas/xml/".freeze
6
+ XSD_DEFAULT_PATH = "/api/schemas/xml/**/".freeze
7
+
8
+ def initialize(domain_arguments)
9
+ @simple_type = domain_arguments.simple_type
10
+ @assessment_type = domain_arguments.assessment_type
11
+ @xsd_dir_path = domain_arguments.xsd_dir_path
12
+ @dir_path = Dir.pwd if domain_arguments.gem_path.nil? || domain_arguments.gem_path.empty?
13
+ end
14
+
15
+ def schema_version(file)
16
+ api_path_start = file.index(API_PATH) + API_PATH.length
17
+ schema_version = file[api_path_start..].split("/").first
18
+ sap_defnied_in_rdsap_dir?(file) ? "#{schema_version}/SAP" : schema_version
19
+ end
20
+
21
+ def xsd_files
22
+ files = if @xsd_dir_path.nil? || @xsd_dir_path.empty?
23
+ case @assessment_type.downcase
24
+ when "sap"
25
+ sap_xsd_files
26
+ when "rdsap"
27
+ rdsap_xsd_files
28
+ when "cepc"
29
+ cepc_xsd_files
30
+ end
31
+ else
32
+ Dir.glob("#{@dir_path}#{@xsd_dir_path}")
33
+ end
34
+
35
+ raise ViewModelBoundary::XsdFilesNotFound, "No xsd files were found in #{@glob_path} directory" if files.nil? || files.empty?
36
+
37
+ files
38
+ end
39
+
40
+ private
41
+
42
+ def sap_defnied_in_rdsap_dir?(file)
43
+ assessment_type == "SAP" && file.end_with?("SAP-Domains.xsd")
44
+ end
45
+
46
+ def sap_xsd_files
47
+ @glob_path = "#{@dir_path + XSD_DEFAULT_PATH}*-Domains.xsd"
48
+ Dir.glob(@glob_path)
49
+ end
50
+
51
+ def rdsap_xsd_files
52
+ @glob_path = "#{@dir_path + XSD_DEFAULT_PATH}*-Domains.xsd"
53
+ Dir.glob(@glob_path)
54
+ end
55
+
56
+ def cepc_xsd_files
57
+ @glob_path = "#{@dir_path + XSD_DEFAULT_PATH}Reported-Data.xsd"
58
+ Dir.glob(@glob_path)
59
+ end
60
+ end
61
+ 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.7
4
+ version: 1.0.11
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-09-24 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -1661,6 +1661,7 @@ files:
1661
1661
  - lib/presenter/sap/recommendation_report.rb
1662
1662
  - lib/presenter/sap/report.rb
1663
1663
  - lib/presenter/sap/summary.rb
1664
+ - lib/presenter/xsd.rb
1664
1665
  - lib/view_model/ac_cert_wrapper.rb
1665
1666
  - lib/view_model/ac_report_wrapper.rb
1666
1667
  - lib/view_model/base_view_model.rb
@@ -1820,6 +1821,10 @@ files:
1820
1821
  - lib/view_model/sap_schema_ni_174/common_schema.rb
1821
1822
  - lib/view_model/sap_schema_ni_1800/common_schema.rb
1822
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
1823
1828
  homepage: https://github.com/communitiesuk/epb-view-models
1824
1829
  licenses:
1825
1830
  - MIT