dwc-archive 1.1.1 → 1.1.2

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: a5d4e174cb4ec6df2328fe99abb52b13587c74f22f01efb2a9017db4d9f1d7ba
4
- data.tar.gz: e341038db2a23282173cf2e4671750739464dca6076f7560694cc40251bdd036
3
+ metadata.gz: f91a9aa06150210f94bd69bb408dc21340feb21294c958f1fe0b03eeda4dab57
4
+ data.tar.gz: eb6c0d368729f09aa91ddc7a131545b1fa1cdfcab5c09a9326e05bcd6e55cdea
5
5
  SHA512:
6
- metadata.gz: 8b51b82724e21acab76e1763dc2375658080a16dc440c9913fd632aff195a45c34e7bf9446cf5d4afc9fc397c8ee562763ab36532ab5992421e5ed3f2df64273
7
- data.tar.gz: 04cbcc92c8b565b2c5f8e8bf082d284b65c55520d91f19c16bc63789519ea374f5ed0466c176ce69907a83566caa8efd2f834399f7b57a26801603455cf2b118
6
+ metadata.gz: 99a1903bd90f161180c59934a5533c55c3c838aeecd0a37476b7b240004c798ea9149a1511eac8ac3a434df1c2e5d5940bb0b6f125f0f7949decf62bcd78900a
7
+ data.tar.gz: 5922fca1a5e0a26ede79e9b3ee4d4a3255c9f1403b7ec71a9f5ce1b929f1dfc71abde50c82541a76a09899be9710e557f1850003f5ec04aa6c81e53f55933fd1
@@ -15,23 +15,23 @@ Gem::Specification.new do |gem|
15
15
  gem.homepage = "http://github.com/GlobalNamesArchitecture/dwc-archive"
16
16
  gem.license = "MIT"
17
17
 
18
- gem.required_ruby_version = ">= 2.5.0"
18
+ gem.required_ruby_version = ">= 2.6.0"
19
19
  gem.files = `git ls-files`.split("\n").map(&:strip)
20
20
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
22
  gem.require_paths = ["lib"]
23
23
 
24
24
  # gem.add_runtime_dependency "minitar", "~> 0.6"
25
- gem.add_runtime_dependency "nokogiri", "~> 1.10"
26
- gem.add_runtime_dependency "biodiversity", "~> 4"
25
+ gem.add_runtime_dependency "biodiversity", "~> 5"
26
+ gem.add_runtime_dependency "nokogiri", "~> 1.11"
27
27
 
28
+ gem.add_development_dependency "bundler", "~> 2.2"
28
29
  gem.add_development_dependency "byebug", "~> 11.1"
29
- gem.add_development_dependency "bundler", "~> 2.1"
30
- gem.add_development_dependency "cucumber", "~> 4"
31
- gem.add_development_dependency "git", "~> 1.7"
30
+ gem.add_development_dependency "cucumber", "~> 5"
31
+ gem.add_development_dependency "git", "~> 1.8"
32
32
  gem.add_development_dependency "rake", "~> 13"
33
- gem.add_development_dependency "rspec", "~> 3.9"
34
- gem.add_development_dependency "rubocop", "~> 0.85"
35
- gem.add_development_dependency "solargraph", "~> 0.39"
36
- gem.add_development_dependency "travis", "~> 1.9"
33
+ gem.add_development_dependency "rspec", "~> 3.10"
34
+ gem.add_development_dependency "rubocop", "~> 1.8"
35
+ gem.add_development_dependency "solargraph", "~> 0.40"
36
+ gem.add_development_dependency "travis", "~> 1.10"
37
37
  end
@@ -39,11 +39,12 @@ class DarwinCore
39
39
 
40
40
  def files(path)
41
41
  return nil unless path && FileTest.exists?(path)
42
- Dir.entries(path).reject { |e| e.match(/[\.]{1,2}$/) }.sort
42
+
43
+ Dir.entries(path).reject { |e| e.match(/[.]{1,2}$/) }.sort
43
44
  end
44
45
 
45
46
  def random_path(tmp_dir)
46
- File.join(tmp_dir, "dwc_" + rand(10_000_000_000).to_s)
47
+ File.join(tmp_dir, "dwc_#{rand(10_000_000_000)}")
47
48
  end
48
49
  end
49
50
 
@@ -52,15 +53,14 @@ class DarwinCore
52
53
 
53
54
  def self.nil_field?(field)
54
55
  return true if [nil, "", "/N"].include?(field)
56
+
55
57
  false
56
58
  end
57
59
 
58
60
  def self.clean_all(tmp_dir = DEFAULT_TMP_DIR)
59
61
  Dir.entries(tmp_dir).each do |entry|
60
62
  path = File.join(tmp_dir, entry)
61
- if FileTest.directory?(path) && entry.match(/^dwc_[\d]+$/)
62
- FileUtils.rm_rf(path)
63
- end
63
+ FileUtils.rm_rf(path) if FileTest.directory?(path) && entry.match(/^dwc_\d+$/)
64
64
  end
65
65
  end
66
66
 
@@ -96,6 +96,7 @@ class DarwinCore
96
96
  # list of synonyms and vernacular names.
97
97
  def normalize_classification
98
98
  return nil unless parent_id?
99
+
99
100
  @classification_normalizer ||=
100
101
  DarwinCore::ClassificationNormalizer.new(self)
101
102
  @classification_normalizer.normalize
@@ -112,9 +113,11 @@ class DarwinCore
112
113
 
113
114
  def extensions
114
115
  return @extensions if @extensions
116
+
115
117
  root_key = @archive.meta.keys[0]
116
118
  ext = @archive.meta[root_key][:extension]
117
119
  return @extensions = [] unless ext
120
+
118
121
  ext = [ext] if ext.class != Array
119
122
  @extensions = ext.map { |e| DarwinCore::Extension.new(self, e) }
120
123
  end
@@ -52,6 +52,7 @@ class DarwinCore
52
52
  def prepare_eml_file
53
53
  @eml = nil
54
54
  return unless files.include?("eml.xml")
55
+
55
56
  eml_file = File.open(File.join(@expander.path, "eml.xml"))
56
57
  @eml = DarwinCore::XmlReader.from_xml(eml_file)
57
58
  end
@@ -73,7 +73,7 @@ class DarwinCore
73
73
  return nil unless @with_canonical_names
74
74
 
75
75
  canonical_name = Biodiversity::Parser.parse(a_scientific_name).
76
- dig(:canonicalName, :simple)
76
+ dig(:canonical, :simple)
77
77
  canonical_name.to_s.empty? ? a_scientific_name : canonical_name
78
78
  end
79
79
 
@@ -2,12 +2,20 @@
2
2
 
3
3
  class DarwinCore
4
4
  class Error < RuntimeError; end
5
+
5
6
  class FileNotFoundError < Error; end
7
+
6
8
  class UnpackingError < Error; end
9
+
7
10
  class InvalidArchiveError < Error; end
11
+
8
12
  class CoreFileError < Error; end
13
+
9
14
  class ExtensionFileError < Error; end
15
+
10
16
  class GeneratorError < Error; end
17
+
11
18
  class ParentNotCurrentError < Error; end
19
+
12
20
  class EncodingError < Error; end
13
21
  end
@@ -13,6 +13,7 @@ class DarwinCore
13
13
  def unpack
14
14
  clean
15
15
  raise DarwinCore::FileNotFoundError unless File.exist?(@archive_path)
16
+
16
17
  success = @unpacker.call(@dir_path, @archive_path) if @unpacker
17
18
  if @unpacker && success && $CHILD_STATUS.exitstatus.zero?
18
19
  success
@@ -39,6 +40,7 @@ class DarwinCore
39
40
  def init_unpacker
40
41
  return tar_unpacker if @archive_path =~ /tar.gz$/i
41
42
  return zip_unpacker if @archive_path =~ /zip$/i
43
+
42
44
  nil
43
45
  end
44
46
 
@@ -58,11 +60,11 @@ class DarwinCore
58
60
  end
59
61
 
60
62
  def esc(a_str)
61
- "'" + a_str.gsub(92.chr, '\\\\\\').gsub("'", "\\\\'") + "'"
63
+ "'#{a_str.gsub(92.chr, '\\\\\\').gsub("'", "\\\\'")}'"
62
64
  end
63
65
 
64
66
  def path_entries(dir)
65
- Dir.entries(dir).reject { |e| e.match(/[\.]{1,2}$/) }.sort
67
+ Dir.entries(dir).reject { |e| e.match(/\.{1,2}$/) }.sort
66
68
  end
67
69
 
68
70
  def files_path
@@ -76,6 +78,7 @@ class DarwinCore
76
78
  check_path = File.join(@dir_path, e)
77
79
  next unless FileTest.directory?(check_path) &&
78
80
  path_entries(check_path).include?("meta.xml")
81
+
79
82
  res = check_path
80
83
  break
81
84
  end
@@ -12,7 +12,7 @@ class DarwinCore
12
12
  @meta_xml_data = { extensions: [] }
13
13
  @eml_xml_data = { id: nil, title: nil, authors: [], abstrac: nil,
14
14
  citation: nil, url: nil }
15
- @write = "w:utf-8"
15
+ @write = 'w:utf-8'
16
16
  end
17
17
 
18
18
  def clean
@@ -20,14 +20,14 @@ class DarwinCore
20
20
  end
21
21
 
22
22
  def add_core(data, file_name, keep_headers = true)
23
- opts = { type: "core", data: data, file_name: file_name,
23
+ opts = { type: 'core', data: data, file_name: file_name,
24
24
  keep_headers: keep_headers }
25
25
  prepare_csv_file(opts)
26
26
  end
27
27
 
28
28
  def add_extension(data, file_name, keep_headers = true,
29
- row_type = "http://rs.tdwg.org/dwc/terms/Taxon")
30
- opts = { type: "extension", data: data, file_name: file_name,
29
+ row_type = 'http://rs.tdwg.org/dwc/terms/Taxon')
30
+ opts = { type: 'extension', data: data, file_name: file_name,
31
31
  keep_headers: keep_headers, row_type: row_type }
32
32
  prepare_csv_file(opts)
33
33
  end
@@ -57,7 +57,7 @@ class DarwinCore
57
57
  def prepare_csv_file(opts)
58
58
  c = CSV.open(File.join(@path, opts[:file_name]), @write)
59
59
  attributes = prepare_attributes(opts)
60
- if opts[:type] == "core"
60
+ if opts[:type] == 'core'
61
61
  @meta_xml_data[:core] = attributes
62
62
  else
63
63
  @meta_xml_data[:extensions] << attributes
@@ -83,7 +83,8 @@ class DarwinCore
83
83
  f = f.strip
84
84
  err = "No header in #{file_type} data, or header fields are not urls"
85
85
  raise DarwinCore::GeneratorError, err unless f =~ %r{^http://}
86
- f.split("/")[-1]
86
+
87
+ f.split('/')[-1]
87
88
  end
88
89
  end
89
90
  end
@@ -25,6 +25,7 @@ class DarwinCore
25
25
 
26
26
  def authors
27
27
  return nil unless defined?(@metadata[:eml][:dataset][:creator])
28
+
28
29
  authors = [@metadata[:eml][:dataset][:creator]].flatten
29
30
  authors.map do |au|
30
31
  { first_name: au[:individualName][:givenName],
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version constant of the class
4
4
  class DarwinCore
5
- VERSION = "1.1.1"
5
+ VERSION = "1.1.2"
6
6
  end
@@ -35,13 +35,14 @@ class DarwinCore
35
35
  end
36
36
 
37
37
  def prepare(data)
38
- data.class == String && data.to_i.to_s == data ? data.to_i : data
38
+ data.instance_of?(String) && data.to_i.to_s == data ? data.to_i : data
39
39
  end
40
40
 
41
41
  def add_attributes
42
42
  return if @node.attributes.empty?
43
+
43
44
  @val[:attributes] = {}
44
- @node.attributes.keys.each do |key|
45
+ @node.attributes.each_key do |key|
45
46
  add_attribute(@val[:attributes], @node.attributes[key])
46
47
  end
47
48
  end
@@ -28,10 +28,10 @@ describe DarwinCore do
28
28
  it "cleans dwca directories" do
29
29
  Dir.chdir(tmp_dir)
30
30
  FileUtils.mkdir("dwc_123") unless File.exist?("dwc_123")
31
- dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_[\d]+$/) }
31
+ dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_\d+$/) }
32
32
  expect(dwca_dirs.size).to be > 0
33
33
  subject.clean_all
34
- dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_[\d]+$/) }
34
+ dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_\d+$/) }
35
35
  expect(dwca_dirs.size).to be 0
36
36
  end
37
37
 
@@ -39,7 +39,7 @@ describe DarwinCore do
39
39
  it "does nothing" do
40
40
  subject.clean_all
41
41
  subject.clean_all
42
- dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_[\d]+$/) }
42
+ dwca_dirs = Dir.entries(tmp_dir).select { |d| d.match(/^dwc_\d+$/) }
43
43
  expect(dwca_dirs.size).to be 0
44
44
  end
45
45
  end
@@ -13,10 +13,10 @@ describe DarwinCore::GnubTaxon do
13
13
  expect(tn).to be_kind_of DarwinCore::GnubTaxon
14
14
  expect(tn).to be_kind_of DarwinCore::TaxonNormalized
15
15
  expect(tn.uuid).to eq "8faa91f6-663f-4cfe-b785-0ab4e9415a51"
16
- expect(tn.uuid_path).to eq [
17
- "9a9f9eeb-d5f9-4ff6-b6cb-a5ad345e33c3",
18
- "bf4c91c0-3d1f-44c7-9d3b-249382182a26",
19
- "8faa91f6-663f-4cfe-b785-0ab4e9415a51"
16
+ expect(tn.uuid_path).to eq %w[
17
+ 9a9f9eeb-d5f9-4ff6-b6cb-a5ad345e33c3
18
+ bf4c91c0-3d1f-44c7-9d3b-249382182a26
19
+ 8faa91f6-663f-4cfe-b785-0ab4e9415a51
20
20
  ]
21
21
  end
22
22
 
metadata CHANGED
@@ -1,99 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dwc-archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Mozzherin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: nokogiri
14
+ name: biodiversity
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: biodiversity
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4'
33
+ version: '1.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
- name: byebug
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '11.1'
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '11.1'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: '11.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: '11.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4'
75
+ version: '5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '4'
82
+ version: '5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: git
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.7'
89
+ version: '1.8'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.7'
96
+ version: '1.8'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,56 +114,56 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.9'
117
+ version: '3.10'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.9'
124
+ version: '3.10'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.85'
131
+ version: '1.8'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.85'
138
+ version: '1.8'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: solargraph
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.39'
145
+ version: '0.40'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0.39'
152
+ version: '0.40'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: travis
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.9'
159
+ version: '1.10'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.9'
166
+ version: '1.10'
167
167
  description: Darwin Core Archive is the current standard exchange format for GLobal
168
168
  Names Architecture modules. This gem makes it easy to incorporate files in Darwin
169
169
  Core Archive format into a ruby project.
@@ -245,7 +245,7 @@ homepage: http://github.com/GlobalNamesArchitecture/dwc-archive
245
245
  licenses:
246
246
  - MIT
247
247
  metadata: {}
248
- post_install_message:
248
+ post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths:
251
251
  - lib
@@ -253,15 +253,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - ">="
255
255
  - !ruby/object:Gem::Version
256
- version: 2.5.0
256
+ version: 2.6.0
257
257
  required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
259
  - - ">="
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  requirements: []
263
- rubygems_version: 3.1.2
264
- signing_key:
263
+ rubygems_version: 3.2.6
264
+ signing_key:
265
265
  specification_version: 4
266
266
  summary: Handler of Darwin Core Archive files
267
267
  test_files: