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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f71a412d77bf50228e2736594bce2312c64b088dc80a7e0708b3606fcb9f3e2c
4
- data.tar.gz: 4d2e94eafa908f2a26ea7aa09e2940fa2461ded527a620f0ebf6a29d9a34281e
3
+ metadata.gz: 1aa9014f126ebe6df35a45f9be7898fe71ebf4253739d537c62ab133f976480a
4
+ data.tar.gz: 9de075f8be11ba4626d771128e75f72917edfb3797eeee2f4bac4c6252df32d7
5
5
  SHA512:
6
- metadata.gz: 82cb7dcc22da7a1d5033a65a3cd57ec67827a7dcbf31bcc45cc328de2746a376457feb120143cdc22a6f6367acb2bf5a722bb55044308d4f4cfe1bd1734914e1
7
- data.tar.gz: 54c8b796430bb11ff37474b65b80db256fbddccdb88d516404baab6b720ff86c8ecbd2ad703bece026a0b61d0f3f75dfd0c3342100c4ee56c0bdce9d1027462a
6
+ metadata.gz: 3ea8139966fc1c55555be100e3ecb63a19364eb6e027c631aa1865a753af2577abee1c00ab53edb78436754fdd89db0aa331a42518cdf1bea5b03b242be48023
7
+ data.tar.gz: cefc2119116d4aab5c1299dd71f609df481e4ca2327a17a8bca256d83a92eeefed2e17127650e3d24d86fdd39445306d8456439947c55db20119168414ce50c7
@@ -5,7 +5,7 @@ loader = Zeitwerk::Loader.for_gem
5
5
  loader.setup
6
6
 
7
7
  module EpbViewModels
8
- VERSION = "1.0.11"
8
+ VERSION = "1.0.12"
9
9
  end
10
10
 
11
11
  # Monkey patching to avoid using ActiveRecord::Type::Boolean.new.cast
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
- 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
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 xsd files in #{domain_arguments.xsd_dir_path} directory" if hash.empty?
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.11
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-13 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri