govuk_document_types 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d1ca4831e2fccf5819f5d1b0d9758448e22bede1794541d561921db1c7dfdcc
4
- data.tar.gz: dfe564af149da8821063dcb542cd43c5cba6a1dc47a44ba523656bec7b50847f
3
+ metadata.gz: bb2f822160da7b706b543bc0b58a2470ec172693b9f3f0a89fd5137c0db5367d
4
+ data.tar.gz: c947a14e448b6a4fa8aef7415c2a91ae8c87e5895e85a02b382d41bdd921f2b5
5
5
  SHA512:
6
- metadata.gz: d1a835c8ffedaf922411e509a1e7c357ccf97482d83a7b7aabf9bf49ff7d416598232f5af1a1d39abd55c63a521389d29d2af5683740898ee285857fa9c08df3
7
- data.tar.gz: 3900036c325282d3a7fbf2065b5b108da92bcab612226f4547dfdcf4dfeede9056b56589d715b58acb4f530b7cf61f2f1db5e26f68ab5f6eff56c7f4716aa41d
6
+ metadata.gz: dd60e6eb75bf94f6eaa380de68917ede7b057beb4f93e8df41cc360d3f136a070b442f7746a509d4407da0ea29e5b5674882f6f8ea38c9829711be02ed6b8b9f
7
+ data.tar.gz: 6b7e39e60cd3648499f31d846d31ea8d33d1749599082d0277f5c9099f8b61cf0c473dc5aa72cf642072dbf8c2960b3dd503129d163b66a483e18b5512ea7a8d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.8.0
2
+
3
+ * Adds `GovukDocumentTypes.supergroup_subgroups` as a way to retrieve
4
+ subgroups registered to the specified supergroups.
5
+ * Adds `GovukDocumentTypes.supergroup_document_types` as a way to retrieve
6
+ document types registered to the specified supergroups.
7
+ * Adds `GovukDocumentTypes.subgroup_document_types` as a way to retrieve
8
+ document types registered to the specified subgroups.
9
+
1
10
  # 0.7.1
2
11
 
3
12
  * Add `hrmc_manual` format to `guidance` `content_purpose_subgroup`
@@ -1,3 +1,3 @@
1
1
  module GovukDocumentTypes
2
- VERSION = "0.7.1".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  end
@@ -2,13 +2,13 @@ require "govuk_document_types/version"
2
2
  require "yaml"
3
3
 
4
4
  module GovukDocumentTypes
5
- DATA = YAML.load_file(File.dirname(__FILE__) + "/../data/supertypes.yml")
5
+ SUPERTYPES = YAML.load_file(File.dirname(__FILE__) + "/../data/supertypes.yml")
6
6
  SUPERGROUPS = YAML.load_file(File.dirname(__FILE__) + "/../data/supergroups.yml")
7
7
 
8
8
  def self.supertypes(document_type:)
9
9
  types = {}
10
10
 
11
- DATA.each do |name, definition|
11
+ SUPERTYPES.each do |name, definition|
12
12
  group_data = definition["items"].find do |supertype|
13
13
  supertype['document_types'].include?(document_type)
14
14
  end
@@ -24,4 +24,28 @@ module GovukDocumentTypes
24
24
  groups = SUPERGROUPS["content_purpose_supergroup"]["items"]
25
25
  groups.select { |g| ids.include?(g["id"]) }
26
26
  end
27
+
28
+ def self.supergroup_subgroups(*supergroup_ids)
29
+ SUPERGROUPS
30
+ .dig('content_purpose_supergroup', 'items')
31
+ .select { |supergroup| supergroup_ids.include?(supergroup['id']) }
32
+ .map { |supergroup| supergroup['subgroups'] }
33
+ .flatten
34
+ .uniq
35
+ .sort
36
+ end
37
+
38
+ def self.supergroup_document_types(*supergroup_ids)
39
+ subgroup_document_types(*supergroup_subgroups(*supergroup_ids))
40
+ end
41
+
42
+ def self.subgroup_document_types(*subgroup_ids)
43
+ SUPERTYPES
44
+ .dig('content_purpose_subgroup', 'items')
45
+ .select { |subgroup| subgroup_ids.include?(subgroup['id']) }
46
+ .map { |subgroup| subgroup['document_types'] }
47
+ .flatten
48
+ .uniq
49
+ .sort
50
+ end
27
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_document_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake