govuk_publishing_components 21.41.1 → 21.41.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c65e3a8bdade54b8a91ed68376eec0044c3d6d170f308e2b840033fc6869e8
|
4
|
+
data.tar.gz: adcfea00c085644145561da1186bbd6fe1b79377f4b88860de9ee4f5d509a0fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af40024d3f31625a02ab376c334f12b530b39b7103815f664032d16b88f06dba85ab59cb457a0b8f39e6512ec59af3a1d92fabd654dd446236a7fc8c19995ed4
|
7
|
+
data.tar.gz: 974e433acf0cf715994401e07ac0a2a2d861bea247b9f163caf30cb9ca1eae6eb524de4020c1457555719ffb28fbf1280ee04fef543413d8901d5f6c8ce458c5
|
@@ -57,22 +57,42 @@ module GovukPublishingComponents
|
|
57
57
|
|
58
58
|
question = page.title
|
59
59
|
|
60
|
-
# rubocop:disable Style/IfInsideElse
|
61
60
|
doc.xpath("html/body").children.each_with_object({}) do |element, q_and_as|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
_q_and_as, question = recursive_question_and_answers(element, question, q_and_as)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def recursive_question_and_answers(element, question, q_and_as)
|
66
|
+
if is_a_question?(element)
|
67
|
+
question = element.text
|
68
|
+
q_and_as[question] = { anchor: element["id"] }
|
69
|
+
else
|
70
|
+
q_and_as = add_answer_to_question(q_and_as, element, question)
|
71
|
+
element.children.each do |child_element|
|
72
|
+
if child_element.element?
|
73
|
+
q_and_as, question = recursive_question_and_answers(child_element, question, q_and_as)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
75
|
-
|
77
|
+
|
78
|
+
[q_and_as, question]
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_answer_to_question(q_and_as, element, question)
|
82
|
+
if no_questions_in_subtree?(element)
|
83
|
+
if question_hash_is_unset?(q_and_as, question)
|
84
|
+
q_and_as[question] = { answer: element.to_s }
|
85
|
+
elsif answer_is_unset?(q_and_as, question)
|
86
|
+
q_and_as[question][:answer] = element.to_s
|
87
|
+
else
|
88
|
+
q_and_as[question][:answer] << element.to_s
|
89
|
+
end
|
90
|
+
end
|
91
|
+
q_and_as
|
92
|
+
end
|
93
|
+
|
94
|
+
def no_questions_in_subtree?(element)
|
95
|
+
element.search(QUESTION_TAG).none?
|
76
96
|
end
|
77
97
|
|
78
98
|
def question_hash_is_unset?(q_and_as, question)
|
@@ -86,7 +106,7 @@ module GovukPublishingComponents
|
|
86
106
|
# we use H2 tags as the "question" and the html between them as the "answer"
|
87
107
|
QUESTION_TAG = "h2".freeze
|
88
108
|
|
89
|
-
def
|
109
|
+
def is_a_question?(element)
|
90
110
|
element.name == QUESTION_TAG
|
91
111
|
end
|
92
112
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 21.41.
|
4
|
+
version: 21.41.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gds-api-adapters
|