adiwg-mdcodes 2.2.2 → 2.3.0

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
  SHA1:
3
- metadata.gz: e2234c19c3daf94bfdd3bb4b8be231da2a45f270
4
- data.tar.gz: 748870ce439720fc03791d5c42fe2f703cf2ee07
3
+ metadata.gz: a40a9ab950a81d61db62806c5fb9a799926dbf83
4
+ data.tar.gz: a9ea92833aaa1c2f5bca91ffeda9db5bbab39757
5
5
  SHA512:
6
- metadata.gz: b816d007176514a1edefde2b8d01718020a9beb624f7362bf4cd5a23035e7ffa3df15bdd9a9359715cbab01218afc2555fe2eb5316e1f4a721425494098dcd40
7
- data.tar.gz: ac4146692c4144b52deff5ce9b143ccec92af7ef77ba7fc68aa2390a1deefd7f2bcdec3e12b61690d5f2186368e470c548f87f8ed172c6298358952cfb8b6f4b
6
+ metadata.gz: 78e6f7d5214af91979ed6acae03193be84013fae9005451991022830a2f18908e17030bd724e299f159f0a6b79a100b63594f6cb81f411dc592c820f092212d2
7
+ data.tar.gz: 70fa5577ac472dfeac7091c837e5cc3d6c9dea642c2dcb4cc16886403179fd274f395be523282329ab5de8f912c4ad66d657351b4537842a761ea558b5a20ad9
data/lib/adiwg/mdcodes.rb CHANGED
@@ -1,99 +1,109 @@
1
- # Mdcodes - ADIwg codeLists to be used with adiwgJson and mdEditor
2
- # ... codeLists are maintained in a YAML file 'mdCodes.yml'
3
- # ... the Mdcodes module has methods to access and return codeLists
1
+ # Mdcodes - ADIwg codelists to be used with adiwgJson and mdEditor
2
+ # ... codelists are maintained in a YAML file 'mdCodes.yml'
3
+ # ... the Mdcodes module has methods to access and return codelists
4
4
 
5
5
  # History:
6
+ # Stan Smith 2017-08-08 add deprecated parameter to codelists
7
+ # Stan Smith 2014-12-18 split codelists into individual YAML file
8
+ # Stan Smith 2014-11-10 added README.md text
9
+ # Stan Smith 2014-11-10 added support for JSON returns
10
+ # Josh Bradley 2014-11-07 moved resources directory outside lib, add getYamlPath
11
+ # Stan Smith 2014-11-07 add methods to return only codeNames
6
12
  # Stan Smith 2014-11-07 original script
7
- # Stan Smith 2014-11-07 add methods to return only codeNames
8
- # Josh Bradley 2014-11-07 moved resources directory outside lib, add getYamlPath
9
- # Stan Smith 2014-11-10 added support for JSON returns
10
- # Stan Smith 2014-11-10 added README.md text
11
- # Stan Smith 2014-12-18 split codelists into individual YAML file
12
-
13
- # add main directories to load_path
14
13
 
15
14
  require 'yaml'
16
15
  require 'json'
17
16
 
18
17
  module ADIWG
19
- module Mdcodes
18
+ module Mdcodes
20
19
 
21
- # return the path to yaml files.
22
- def self.getYamlPath
23
- File.join(File.dirname(File.expand_path(__FILE__)),'..','..','resources')
24
- end
20
+ # return the path to yaml files.
21
+ def self.getYamlPath
22
+ File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'resources')
23
+ end
25
24
 
26
- # return all codelists with full details
27
- def self.getAllCodeistsDetail(format='hash')
28
- path = getYamlPath + '/*.yml'
29
- hCodeLists = {}
30
- Dir.glob(path) do |item|
31
- hCodeList = YAML.load_file(item)
32
- hCodeLists[hCodeList['codelistName']] = hCodeList
25
+ # return all codelists with all elements
26
+ def self.getAllCodelistsDetail(format='hash', showDeprecated=false)
27
+ path = getYamlPath + '/*.yml'
28
+ hCodelists = {}
29
+ Dir.glob(path) do |item|
30
+ hCodelist = YAML.load_file(item)
31
+ hCodelists[hCodelist['codelistName']] = hCodelist
32
+ end
33
+ unless showDeprecated
34
+ hCodelists.each do |key, value|
35
+ aKeepItems = []
36
+ value['codelist'].each do |item|
37
+ if item.has_key?('deprecated')
38
+ unless item['deprecated']
39
+ aKeepItems << item
40
+ end
41
+ else
42
+ aKeepItems << item
43
+ end
44
+ value['codelist'] = aKeepItems
45
+ end
33
46
  end
34
- if format == 'json'
35
- return hCodeLists.to_json
36
- else
37
- return hCodeLists
38
- end
39
- end
47
+ end
48
+ return hCodelists.to_json if format == 'json'
49
+ return hCodelists
50
+ end
40
51
 
41
- # return a single codelist with full details
42
- def self.getCodelistDetail(codeList, format='hash')
43
- file = File.join(getYamlPath, codeList + '.yml')
44
- if File.exist?(file)
45
- hCodeList = YAML.load_file(file)
46
- else
47
- return nil
52
+ # return a single codelist with all elements
53
+ def self.getCodelistDetail(codelist, format='hash', showDeprecated=false)
54
+ file = File.join(getYamlPath, codelist + '.yml')
55
+ if File.exist?(file)
56
+ hCodelist = YAML.load_file(file)
57
+ unless showDeprecated
58
+ aKeepItems = []
59
+ hCodelist['codelist'].each do |item|
60
+ if item.has_key?('deprecated')
61
+ unless item['deprecated']
62
+ aKeepItems << item
63
+ end
64
+ else
65
+ aKeepItems << item
66
+ end
67
+ hCodelist['codelist'] = aKeepItems
68
+ end
48
69
  end
49
- if format == 'json'
50
- return hCodeList.to_json
51
- else
52
- return hCodeList
53
- end
54
- end
70
+ else
71
+ return nil
72
+ end
73
+ return hCodelist.to_json if format == 'json'
74
+ return hCodelist
75
+ end
55
76
 
56
- # return all static codelist with only the item names
57
- def self.getAllStaticCodelists(format='hash')
58
- codeLists = getAllCodeistsDetail
59
- hCodeLists = {}
60
- codeLists.each do |key, value|
61
- if value['codelistType'] == 'staticList'
62
- aItems = value['codelist']
63
- aList = []
64
- aItems.each do |item|
65
- aList << item['codeName']
66
- end
67
- hCodeLists[key] = aList
68
- end
77
+ # return all codelist with only the codeName
78
+ def self.getAllStaticCodelists(format='hash', showDeprecated=false)
79
+ hCodelists = {}
80
+ codelists = getAllCodelistsDetail('hash', showDeprecated)
81
+ codelists.each do |key, value|
82
+ aList = []
83
+ value['codelist'].each do |item|
84
+ aList << item['codeName']
69
85
  end
70
- if format == 'json'
71
- hCodeLists.to_json if format == 'json'
72
- else
73
- return hCodeLists
74
- end
75
- end
86
+ hCodelists[key] = aList
87
+ end
88
+ return hCodelists.to_json if format == 'json'
89
+ return hCodelists
90
+ end
76
91
 
77
- # return a single static codelist with only the item names
78
- def self.getStaticCodelist(codeList, format='hash')
79
- hCodeList = getCodelistDetail(codeList)
80
- if hCodeList
81
- hCodeNames = {}
82
- aItems = hCodeList['codelist']
83
- aList = []
84
- aItems.each do |item|
85
- aList << item['codeName']
86
- end
87
- hCodeNames[hCodeList['codelistName']] = aList
88
- if format == 'json'
89
- return hCodeNames.to_json
90
- else
91
- return hCodeNames
92
- end
93
- else
94
- return nil
92
+ # return a single codelist with only the codeName
93
+ def self.getStaticCodelist(codelist, format='hash', showDeprecated=false)
94
+ hCodelist = getCodelistDetail(codelist, 'hash', showDeprecated)
95
+ unless hCodelist.nil?
96
+ hCodeNames = {}
97
+ aList = []
98
+ hCodelist['codelist'].each do |item|
99
+ aList << item['codeName']
95
100
  end
96
- end
101
+ hCodeNames[hCodelist['codelistName']] = aList
102
+ return hCodeNames.to_json if format == 'json'
103
+ return hCodeNames
104
+ end
105
+ return nil
106
+ end
97
107
 
98
- end
108
+ end
99
109
  end
@@ -1,6 +1,8 @@
1
1
  # adiwg mdCodes
2
2
 
3
3
  # version 2 history
4
+ # 2.3.0 2017-08-01 added showDeprecated parameter to mdCodes methods
5
+ # 2.3.0 2017-08-01 change to associationTypes: revised definitions, deprecated some codes
4
6
  # 2.2.0 2017-06-29 added adiwg namespace codelist
5
7
  # 2.1.7 2017-06-08 added scienceBase date codes to dateType
6
8
  # 2.1.6 2017-05-16 added 'isoTopicCategory' to keyword type code list
@@ -12,7 +14,6 @@
12
14
  # 2.1.0 2016-11-27 added 10 MI codelists
13
15
 
14
16
  # version 1 history
15
-
16
17
  # 0.1.0 2014-11-05 first release
17
18
  # 0.1.1 2014-11-06 added factSheet to scope
18
19
  # 0.2.0 2014-11-07 add option to return only codeNames
@@ -29,6 +30,6 @@
29
30
 
30
31
  module ADIWG
31
32
  module Mdcodes
32
- VERSION = "2.2.2"
33
+ VERSION = "2.3.0"
33
34
  end
34
35
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdcodes",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "CodeLists for ADIwg mdJSON",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,3 +12,4 @@ codelist:
12
12
  - {code: "cdddf5c7-eec4-4e0c-9b54-d75b763a88fc", codeName: data.gov, description: "U.S. Government repository of open data"}
13
13
  - {code: "da0336c4-a8f6-4010-99b3-1b848d14ff2f", codeName: ScienceBase, description: "U.S. Geological Survey repository for data and metadata"}
14
14
  - {code: "b1d2ffbe-0b64-40fe-890a-02c4f0b6b9b4", codeName: ScienceCatalog, description: "U.S. Geological Survey inventory for data and metadata"}
15
+ - {code: "a791e961-f2d4-4be4-ab3c-1cdf8fd025b9", codeName: LCCScienceCatalog, description: "Repository of Landscape Conservation Cooperative projects and data products."}
@@ -10,19 +10,24 @@ sourceName: "DS_AssociationTypeCode"
10
10
  extensible: true
11
11
  description: "justification for the correlation of two resources (datasets or projects)"
12
12
  codelist:
13
- - {code: "001", codeName: crossReference, description: "reference from one resource (dataset or project) to another"}
14
- - {code: "002", codeName: largerWorkCitation, description: "reference to a master resource (dataset or project) of which this one is a part"}
15
- - {code: "003", codeName: partOfSeamlessDatabase, description: "part of the same structured set of data held in a computer"}
16
- - {code: "004", codeName: source, description: "mapping and charting information from which the dataset content originates"}
17
- - {code: "005", codeName: stereoMate, description: "part of a set of imagery that when used together, provides three-dimensional images"}
18
- - {code: "006", codeName: isComposedOf, description: "reference to resources (datasets or projects) that are parts of this resource"}
19
- - {code: "007", codeName: collectiveTitle, description: "common title for a collection of resources. NOTE Title identifies elements of a series collectively, combined with information about what volumes are available at the source cite."}
20
- - {code: "008", codeName: series, description: "associated through a common heritage such as produced to a common product specification"}
21
- - {code: "009", codeName: dependency, description: "associated through a dependency"}
22
- - {code: "010", codeName: revisionOf, description: "resource is a revision of associated resource"}
23
- - {code: "adiwg001", codeName: projectProduct, description: "products developed as deliverables of a project or program (DEPRECATED: use productOf)"}
24
- - {code: "adiwg002", codeName: supplementalResource, description: "supplemental resource"}
25
- - {code: "adiwg003", codeName: produced, description: "reference to a product or deliverable produced by the resource (e.g. project or program)"}
26
- - {code: "adiwg004", codeName: productOf, description: "reference to a project or program which produced the resource as a deliverable"}
27
- - {code: "adiwg005", codeName: mainprojectOf, description: "reference to a project which is a derivative of the resource"}
28
- - {code: "adiwg006", codeName: subprojectOf, description: "reference to a project of which the resource is a derivative"}
13
+ - {code: "001", codeName: crossReference, description: "the associated resource is a reference to another dataset or project"}
14
+ - {code: "002", codeName: largerWorkCitation, description: "the associated resource is a citation to a master resource of the main resource"}
15
+ - {code: "003", codeName: partOfSeamlessDatabase, description: "the associated resource is a part of the same structured dataset as the main resource"}
16
+ - {code: "004", codeName: source, description: "the associated resource is mapping and charting information from which the main resource content originates"}
17
+ - {code: "005", codeName: stereoMate, description: "the associated resource is part of a set of imagery that when used together provide three-dimensional images"}
18
+ - {code: "006", codeName: isComposedOf, description: "the associated resource is a dataset or project that is part of the main resource"}
19
+ - {code: "007", codeName: collectiveTitle, description: "the associated resource is a common title for a collection of resources. NOTE Title identifies elements of a series collectively, combined with information about what volumes are available at the source cite."}
20
+ - {code: "008", codeName: series, description: "the associated resource was produced via the same product specifications as the main resource"}
21
+ - {code: "009", codeName: dependency, description: "the associated resource is dependent on the main resource"}
22
+ - {code: "010", codeName: revisionOf, description: "the main resource is a revision of the associated resource"}
23
+ - {code: "adiwg001", codeName: projectProduct, description: "DEPRECATED: use product", deprecated: true}
24
+ - {code: "adiwg002", codeName: supplementalResource, description: "the associated resource is a supplemental resource to the main resource"}
25
+ - {code: "adiwg003", codeName: produced, description: "DEPRECATED: use product", deprecated: true}
26
+ - {code: "adiwg004", codeName: productOf, description: "DEPRECATED: use parentProject", deprecated: true}
27
+ - {code: "adiwg005", codeName: mainProjectOf, description: "DEPRECATED: use subProject", deprecated: true}
28
+ - {code: "adiwg006", codeName: subProjectOf, description: "DEPRECATED: use parentProject", deprecated: true}
29
+ - {code: "adiwg007", codeName: product, description: "the associated resource is a product developed as deliverable of the main resource"}
30
+ - {code: "adiwg008", codeName: parentProject, description: "the associated resource is a parent project of the main resource"}
31
+ - {code: "adiwg009", codeName: subProject, description: "the associated resource is sub-project or task of the main resource"}
32
+ - {code: "adiwg010", codeName: derivativeProduct, description: "the associated resource is product derived from main resource"}
33
+ - {code: "adiwg011", codeName: alternate, description: "the associated resource is an alternate reference for the main resource"}
data/test/tc_mdcodes.rb CHANGED
@@ -6,49 +6,71 @@
6
6
  =end
7
7
 
8
8
  require 'minitest/autorun'
9
- require File.join(File.dirname(__FILE__),'..','lib', 'adiwg-mdcodes.rb')
9
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'adiwg-mdcodes.rb')
10
10
 
11
11
  class TestMdcodes < Minitest::Test
12
- def test_parseYaml
13
- @errors = Array.new
14
12
 
15
- FileList[ADIWG::Mdcodes.getYamlPath + '**/*.yml'].each do |fname|
16
- begin YAML.load_file(fname)
17
- rescue Exception
18
- @errors << "Could not parse YAML: #{fname}"
13
+ def test_parseYaml
14
+ @errors = Array.new
15
+
16
+ path = ADIWG::Mdcodes.getYamlPath
17
+ Dir["#{File.join(path, '**/*.yml')}"].each do |fname|
18
+ begin
19
+ YAML.load_file(fname)
20
+ rescue Exception
21
+ @errors << "Could not parse YAML: #{fname}"
22
+ end
23
+ end
24
+ assert(@errors.empty?, @errors.join("\n"))
25
+ end
26
+
27
+ def test_yamlResourceDir
28
+ yamlDir = ADIWG::Mdcodes.getYamlPath
29
+ assert(Dir.exist?(yamlDir), 'Did not find resource Directory.')
30
+ end
31
+
32
+ def test_getAllCodelistsDetail
33
+ assert_instance_of(Hash, ADIWG::Mdcodes.getAllCodelistsDetail)
34
+ end
35
+
36
+ def test_getCodelistDetail
37
+ yaml = ADIWG::Mdcodes.getAllCodelistsDetail
38
+ refute_empty(yaml)
39
+
40
+ yaml.keys.each do |key|
41
+ assert_instance_of(Hash, ADIWG::Mdcodes.getCodelistDetail(key), 'Failed to load ' + key)
19
42
  end
20
- end
21
- assert(@errors.empty?, @errors.join("\n"))
22
- end
23
-
24
- def test_yamlResourceDir
25
- yamlDir = ADIWG::Mdcodes.getYamlPath
26
- assert(Dir.exist?(yamlDir), 'Did not find resource Directory.')
27
- end
28
-
29
- def test_getAllCodeistsDetail
30
- assert_instance_of(Hash,ADIWG::Mdcodes.getAllCodeistsDetail)
31
- end
32
-
33
- def test_getCodelistDetail
34
- yaml = ADIWG::Mdcodes.getAllCodeistsDetail
35
- refute_empty(yaml)
36
-
37
- yaml.keys.each do |key|
38
- assert_instance_of(Hash,ADIWG::Mdcodes.getCodelistDetail(key), 'Failed to load ' + key)
39
- end
40
- end
41
-
42
- def test_getAllStaticCodelists
43
- assert_instance_of(Hash,ADIWG::Mdcodes.getAllStaticCodelists)
44
- end
45
-
46
- def test_getStaticCodelist
47
- yaml = ADIWG::Mdcodes.getAllStaticCodelists
48
- refute_empty(yaml)
49
-
50
- yaml.keys.each do |key|
51
- assert_instance_of(Hash,ADIWG::Mdcodes.getStaticCodelist(key), 'Failed to load ' + key)
52
- end
53
- end
43
+ end
44
+
45
+ def test_getAllStaticCodelists
46
+ assert_instance_of(Hash, ADIWG::Mdcodes.getAllStaticCodelists)
47
+ end
48
+
49
+ def test_getStaticCodelist
50
+ yaml = ADIWG::Mdcodes.getAllStaticCodelists
51
+ refute_empty(yaml)
52
+
53
+ yaml.keys.each do |key|
54
+ assert_instance_of(Hash, ADIWG::Mdcodes.getStaticCodelist(key), 'Failed to load ' + key)
55
+ end
56
+ end
57
+
58
+ def test_getStaticCodelist_deprecated
59
+ yaml = ADIWG::Mdcodes.getStaticCodelist('iso_associationType')
60
+ yamlDeprecated = ADIWG::Mdcodes.getStaticCodelist('iso_associationType', 'hash', true)
61
+
62
+ refute_empty yaml['iso_associationType']
63
+ refute_empty yamlDeprecated['iso_associationType']
64
+ assert (yaml['iso_associationType'].length < yamlDeprecated['iso_associationType'].length)
65
+ end
66
+
67
+ def test_getAllCodelistsDetail_deprecated
68
+ yaml = ADIWG::Mdcodes.getAllCodelistsDetail
69
+ yamlDeprecated = ADIWG::Mdcodes.getAllCodelistsDetail('hash', true)
70
+
71
+ refute_empty yaml['iso_associationType']['codelist']
72
+ refute_empty yamlDeprecated['iso_associationType']['codelist']
73
+ assert (yaml['iso_associationType']['codelist'].length < yamlDeprecated['iso_associationType']['codelist'].length)
74
+ end
75
+
54
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adiwg-mdcodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - stansmith907, jlblcc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.5.2
163
+ rubygems_version: 2.4.5
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: adiwg-mdcodes provides code lists for mdJSON.