briard 2.4.1 → 2.6.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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +72 -0
  3. data/.github/workflows/rubocop.yml +50 -0
  4. data/.rubocop.yml +144 -620
  5. data/.rubocop_todo.yml +76 -0
  6. data/CHANGELOG.md +22 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +43 -6
  9. data/Rakefile +1 -1
  10. data/{bolognese.gemspec → briard.gemspec} +46 -38
  11. data/lib/briard/array.rb +2 -2
  12. data/lib/briard/author_utils.rb +79 -71
  13. data/lib/briard/cli.rb +12 -13
  14. data/lib/briard/crossref_utils.rb +73 -61
  15. data/lib/briard/datacite_utils.rb +132 -106
  16. data/lib/briard/doi_utils.rb +10 -10
  17. data/lib/briard/metadata.rb +96 -106
  18. data/lib/briard/metadata_utils.rb +87 -78
  19. data/lib/briard/readers/bibtex_reader.rb +65 -65
  20. data/lib/briard/readers/cff_reader.rb +88 -70
  21. data/lib/briard/readers/citeproc_reader.rb +90 -84
  22. data/lib/briard/readers/codemeta_reader.rb +68 -50
  23. data/lib/briard/readers/crosscite_reader.rb +2 -2
  24. data/lib/briard/readers/crossref_reader.rb +249 -210
  25. data/lib/briard/readers/datacite_json_reader.rb +3 -3
  26. data/lib/briard/readers/datacite_reader.rb +225 -189
  27. data/lib/briard/readers/npm_reader.rb +49 -42
  28. data/lib/briard/readers/ris_reader.rb +82 -80
  29. data/lib/briard/readers/schema_org_reader.rb +182 -159
  30. data/lib/briard/string.rb +1 -1
  31. data/lib/briard/utils.rb +4 -4
  32. data/lib/briard/version.rb +3 -1
  33. data/lib/briard/whitelist_scrubber.rb +11 -4
  34. data/lib/briard/writers/bibtex_writer.rb +14 -8
  35. data/lib/briard/writers/cff_writer.rb +33 -26
  36. data/lib/briard/writers/codemeta_writer.rb +19 -15
  37. data/lib/briard/writers/csv_writer.rb +6 -4
  38. data/lib/briard/writers/datacite_json_writer.rb +8 -2
  39. data/lib/briard/writers/jats_writer.rb +33 -28
  40. data/lib/briard/writers/rdf_xml_writer.rb +1 -1
  41. data/lib/briard/writers/ris_writer.rb +30 -18
  42. data/lib/briard/writers/turtle_writer.rb +1 -1
  43. data/lib/briard.rb +6 -6
  44. data/rubocop.sarif +0 -0
  45. data/spec/array_spec.rb +5 -5
  46. data/spec/author_utils_spec.rb +151 -132
  47. data/spec/datacite_utils_spec.rb +135 -83
  48. data/spec/doi_utils_spec.rb +168 -164
  49. data/spec/find_from_format_spec.rb +69 -69
  50. data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/onlies_keep_specific_tags.yml +65 -0
  51. data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/removes_a_tags.yml +65 -0
  52. data/spec/metadata_spec.rb +91 -90
  53. data/spec/readers/bibtex_reader_spec.rb +43 -38
  54. data/spec/readers/cff_reader_spec.rb +165 -153
  55. data/spec/readers/citeproc_reader_spec.rb +45 -40
  56. data/spec/readers/codemeta_reader_spec.rb +128 -115
  57. data/spec/readers/crosscite_reader_spec.rb +34 -24
  58. data/spec/readers/crossref_reader_spec.rb +1098 -939
  59. data/spec/readers/datacite_json_reader_spec.rb +53 -40
  60. data/spec/readers/datacite_reader_spec.rb +1541 -1337
  61. data/spec/readers/npm_reader_spec.rb +48 -43
  62. data/spec/readers/ris_reader_spec.rb +53 -47
  63. data/spec/readers/schema_org_reader_spec.rb +329 -267
  64. data/spec/spec_helper.rb +6 -5
  65. data/spec/utils_spec.rb +371 -347
  66. data/spec/writers/bibtex_writer_spec.rb +143 -143
  67. data/spec/writers/cff_writer_spec.rb +96 -90
  68. data/spec/writers/citation_writer_spec.rb +34 -33
  69. data/spec/writers/citeproc_writer_spec.rb +226 -224
  70. data/spec/writers/codemeta_writer_spec.rb +18 -16
  71. data/spec/writers/crosscite_writer_spec.rb +91 -73
  72. data/spec/writers/crossref_writer_spec.rb +99 -91
  73. data/spec/writers/csv_writer_spec.rb +70 -70
  74. data/spec/writers/datacite_json_writer_spec.rb +78 -68
  75. data/spec/writers/datacite_writer_spec.rb +417 -322
  76. data/spec/writers/jats_writer_spec.rb +177 -161
  77. data/spec/writers/rdf_xml_writer_spec.rb +68 -63
  78. data/spec/writers/ris_writer_spec.rb +162 -162
  79. data/spec/writers/turtle_writer_spec.rb +47 -47
  80. metadata +250 -160
  81. data/.github/workflows/release.yml +0 -47
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,76 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-01-30 21:43:14 UTC using RuboCop version 1.25.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 101
10
+ InternalAffairs/NodeDestructuring:
11
+ Enabled: false
12
+
13
+ # Offense count: 55
14
+ # Configuration parameters: CountComments, CountAsOne.
15
+ Metrics/ClassLength:
16
+ Max: 191
17
+
18
+ # Offense count: 235
19
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
20
+ Metrics/MethodLength:
21
+ Max: 14
22
+
23
+ # Offense count: 8
24
+ # Configuration parameters: CountComments, CountAsOne.
25
+ Metrics/ModuleLength:
26
+ Max: 129
27
+
28
+ # Offense count: 9
29
+ RSpec/AnyInstance:
30
+ Exclude:
31
+ - 'spec/rubocop/cli_spec.rb'
32
+ - 'spec/rubocop/cli/suggest_extensions_spec.rb'
33
+ - 'spec/rubocop/cop/lint/duplicate_methods_spec.rb'
34
+ - 'spec/rubocop/cop/team_spec.rb'
35
+ - 'spec/rubocop/target_finder_spec.rb'
36
+
37
+ # Offense count: 1279
38
+ # Configuration parameters: Prefixes.
39
+ # Prefixes: when, with, without
40
+ RSpec/ContextWording:
41
+ Enabled: false
42
+
43
+ # Offense count: 2414
44
+ # Configuration parameters: CountAsOne.
45
+ RSpec/ExampleLength:
46
+ Enabled: false
47
+
48
+ # Offense count: 39
49
+ RSpec/ExpectOutput:
50
+ Exclude:
51
+ - 'spec/rubocop/cli/auto_gen_config_spec.rb'
52
+ - 'spec/rubocop/cli/options_spec.rb'
53
+ - 'spec/rubocop/config_spec.rb'
54
+ - 'spec/rubocop/cop/cop_spec.rb'
55
+ - 'spec/rubocop/formatter/disabled_config_formatter_spec.rb'
56
+ - 'spec/rubocop/formatter/formatter_set_spec.rb'
57
+ - 'spec/rubocop/options_spec.rb'
58
+ - 'spec/rubocop/rake_task_spec.rb'
59
+ - 'spec/rubocop/result_cache_spec.rb'
60
+ - 'spec/rubocop/target_finder_spec.rb'
61
+
62
+ # Offense count: 404
63
+ RSpec/MultipleExpectations:
64
+ Max: 25
65
+
66
+ # Offense count: 9
67
+ RSpec/SubjectStub:
68
+ Exclude:
69
+ - 'spec/rubocop/config_spec.rb'
70
+ - 'spec/rubocop/formatter/json_formatter_spec.rb'
71
+ - 'spec/rubocop/formatter/pacman_formatter_spec.rb'
72
+ - 'spec/rubocop/formatter/progress_formatter_spec.rb'
73
+
74
+ # Offense count: 12
75
+ Rake/MethodDefinitionInTask:
76
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.5.1](https://github.com/front-matter/briard/tree/v2.5.1) (2022-09-18)
4
+
5
+ [Full Changelog](https://github.com/front-matter/briard/compare/v2.5.0...v2.5.1)
6
+
7
+ ## [v2.5.0](https://github.com/front-matter/briard/tree/v2.5.0) (2022-09-18)
8
+
9
+ [Full Changelog](https://github.com/front-matter/briard/compare/v2.4.2...v2.5.0)
10
+
11
+ **Fixed bugs:**
12
+
13
+ - Incomplete URL substring sanitization [\#12](https://github.com/front-matter/briard/issues/12)
14
+ - Incomplete URL substring sanitization [\#11](https://github.com/front-matter/briard/issues/11)
15
+ - Incomplete URL substring sanitization [\#10](https://github.com/front-matter/briard/issues/10)
16
+
17
+ ## [v2.4.2](https://github.com/front-matter/briard/tree/v2.4.2) (2022-08-24)
18
+
19
+ [Full Changelog](https://github.com/front-matter/briard/compare/v2.4.1...v2.4.2)
20
+
21
+ ## [v2.4.1](https://github.com/front-matter/briard/tree/v2.4.1) (2022-08-24)
22
+
23
+ [Full Changelog](https://github.com/front-matter/briard/compare/v2.4...v2.4.1)
24
+
3
25
  ## [v2.4](https://github.com/front-matter/briard/tree/v2.4) (2022-08-24)
4
26
 
5
27
  [Full Changelog](https://github.com/front-matter/briard/compare/v2.3.1...v2.4)
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- briard (2.4.1)
4
+ briard (2.5.1)
5
5
  activesupport (>= 4.2.5)
6
6
  base32-url (>= 0.5.0, < 1)
7
7
  benchmark_methods (~> 0.7)
@@ -14,6 +14,7 @@ PATH
14
14
  dotenv (~> 2.1, >= 2.1.1)
15
15
  edtf (~> 3.0, >= 3.0.4)
16
16
  faraday (~> 0.17.3)
17
+ faraday-multipart (~> 1.0.4)
17
18
  gender_detector (~> 0.1.2)
18
19
  iso8601 (~> 0.9.1)
19
20
  json-ld-preloaded (~> 3.1, >= 3.1.3)
@@ -33,7 +34,7 @@ PATH
33
34
  GEM
34
35
  remote: https://rubygems.org/
35
36
  specs:
36
- activesupport (7.0.3.1)
37
+ activesupport (7.0.4)
37
38
  concurrent-ruby (~> 1.0, >= 1.0.2)
38
39
  i18n (>= 1.6, < 2)
39
40
  minitest (>= 5.1)
@@ -41,6 +42,7 @@ GEM
41
42
  addressable (2.8.1)
42
43
  public_suffix (>= 2.0.2, < 6.0)
43
44
  amazing_print (1.4.0)
45
+ ast (2.4.2)
44
46
  base32-url (0.5)
45
47
  benchmark_methods (0.7)
46
48
  bibtex-ruby (6.0.0)
@@ -51,6 +53,8 @@ GEM
51
53
  citeproc-ruby (1.1.14)
52
54
  citeproc (~> 1.0, >= 1.0.9)
53
55
  csl (~> 1.6)
56
+ code-scanning-rubocop (0.6.1)
57
+ rubocop (~> 1.0)
54
58
  colorize (0.8.1)
55
59
  concurrent-ruby (1.1.10)
56
60
  crack (0.4.5)
@@ -78,6 +82,8 @@ GEM
78
82
  multipart-post (>= 1.2, < 3)
79
83
  faraday-encoding (0.0.5)
80
84
  faraday
85
+ faraday-multipart (1.0.4)
86
+ multipart-post (~> 2)
81
87
  faraday_middleware (0.14.0)
82
88
  faraday (>= 0.7.4, < 1.0)
83
89
  gender_detector (0.1.2)
@@ -107,7 +113,7 @@ GEM
107
113
  optimist (~> 3)
108
114
  latex-decode (0.4.0)
109
115
  link_header (0.0.8)
110
- loofah (2.18.0)
116
+ loofah (2.19.0)
111
117
  crass (~> 1.0.2)
112
118
  nokogiri (>= 1.5.9)
113
119
  maremma (4.9.8)
@@ -133,6 +139,9 @@ GEM
133
139
  oj (3.13.21)
134
140
  oj_mimic_json (1.0.1)
135
141
  optimist (3.0.1)
142
+ parallel (1.22.1)
143
+ parser (3.1.2.1)
144
+ ast (~> 2.4.1)
136
145
  postrank-uri (1.0.24)
137
146
  addressable (>= 2.4.0)
138
147
  nokogiri (>= 1.8.0)
@@ -142,6 +151,7 @@ GEM
142
151
  rack (2.2.4)
143
152
  rack-test (0.8.3)
144
153
  rack (>= 1.0, < 3)
154
+ rainbow (3.1.1)
145
155
  rake (12.3.3)
146
156
  rdf (3.2.9)
147
157
  link_header (~> 0.0, >= 0.0.8)
@@ -167,6 +177,7 @@ GEM
167
177
  rdf-xsd (3.2.1)
168
178
  rdf (~> 3.2)
169
179
  rexml (~> 3.2)
180
+ regexp_parser (2.5.0)
170
181
  rexml (3.2.5)
171
182
  rspec (3.11.0)
172
183
  rspec-core (~> 3.11.0)
@@ -174,16 +185,36 @@ GEM
174
185
  rspec-mocks (~> 3.11.0)
175
186
  rspec-core (3.11.0)
176
187
  rspec-support (~> 3.11.0)
177
- rspec-expectations (3.11.0)
188
+ rspec-expectations (3.11.1)
178
189
  diff-lcs (>= 1.2.0, < 2.0)
179
190
  rspec-support (~> 3.11.0)
180
191
  rspec-mocks (3.11.1)
181
192
  diff-lcs (>= 1.2.0, < 2.0)
182
193
  rspec-support (~> 3.11.0)
183
- rspec-support (3.11.0)
194
+ rspec-support (3.11.1)
184
195
  rspec-xsd (0.1.0)
185
196
  nokogiri (~> 1.6)
186
197
  rspec (~> 3)
198
+ rubocop (1.36.0)
199
+ json (~> 2.3)
200
+ parallel (~> 1.10)
201
+ parser (>= 3.1.2.1)
202
+ rainbow (>= 2.2.2, < 4.0)
203
+ regexp_parser (>= 1.8, < 3.0)
204
+ rexml (>= 3.2.5, < 4.0)
205
+ rubocop-ast (>= 1.20.1, < 2.0)
206
+ ruby-progressbar (~> 1.7)
207
+ unicode-display_width (>= 1.4.0, < 3.0)
208
+ rubocop-ast (1.21.0)
209
+ parser (>= 3.1.1.0)
210
+ rubocop-performance (1.15.0)
211
+ rubocop (>= 1.7.0, < 2.0)
212
+ rubocop-ast (>= 0.4.0)
213
+ rubocop-rake (0.6.0)
214
+ rubocop (~> 1.0)
215
+ rubocop-rspec (2.13.1)
216
+ rubocop (~> 1.33)
217
+ ruby-progressbar (1.11.0)
187
218
  scanf (1.0.0)
188
219
  simplecov (0.17.1)
189
220
  docile (~> 1.1)
@@ -198,7 +229,8 @@ GEM
198
229
  tilt (2.0.11)
199
230
  tzinfo (2.0.5)
200
231
  concurrent-ruby (~> 1.0)
201
- unicode-types (1.7.0)
232
+ unicode-display_width (2.3.0)
233
+ unicode-types (1.8.0)
202
234
  unicode_utils (1.4.0)
203
235
  vcr (3.0.3)
204
236
  webmock (3.18.1)
@@ -212,11 +244,16 @@ PLATFORMS
212
244
  DEPENDENCIES
213
245
  briard!
214
246
  bundler (>= 1.0)
247
+ code-scanning-rubocop (~> 0.6.1)
215
248
  hashdiff (>= 1.0.0.beta1, < 2.0.0)
216
249
  rack-test (~> 0)
217
250
  rake (~> 12.0)
218
251
  rspec (~> 3.4)
219
252
  rspec-xsd (~> 0.1.0)
253
+ rubocop (~> 1.36)
254
+ rubocop-performance (~> 1.15)
255
+ rubocop-rake (~> 0.6.0)
256
+ rubocop-rspec (~> 2.13)
220
257
  simplecov (= 0.17.1)
221
258
  vcr (~> 3.0, >= 3.0.3)
222
259
  webmock (~> 3.0, >= 3.0.1)
data/Rakefile CHANGED
@@ -10,4 +10,4 @@ Bundler::GemHelper.install_tasks
10
10
  RSpec::Core::RakeTask.new('spec')
11
11
 
12
12
  # default task is running rspec tests
13
- task :default => :spec
13
+ task default: :spec
@@ -1,60 +1,68 @@
1
- require "date"
2
- require File.expand_path("../lib/briard/version", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require 'date'
5
+ require File.expand_path('lib/briard/version', __dir__)
3
6
 
4
7
  Gem::Specification.new do |s|
5
- s.authors = "Martin Fenner"
6
- s.email = "martin@front-matter.io"
7
- s.name = "briard"
8
- s.homepage = "https://github.com/front-matter/briard"
9
- s.summary = "Ruby client library for conversion of DOI Metadata"
10
- s.date = Date.today
11
- s.description = "Ruby gem and command-line utility for conversion of DOI metadata from and to different metadata formats, including schema.org. Fork of version 1.19.12 of the bolognese gem."
12
- s.require_paths = ["lib"]
8
+ s.authors = 'Martin Fenner'
9
+ s.email = 'martin@front-matter.io'
10
+ s.name = 'briard'
11
+ s.homepage = 'https://github.com/front-matter/briard'
12
+ s.summary = 'Ruby client library for conversion of DOI Metadata'
13
+ s.description = 'Ruby gem and command-line utility for conversion of DOI metadata from and to different metadata formats, including schema.org. Fork of version 1.19.12 of the bolognese gem.'
14
+ s.require_paths = ['lib']
13
15
  s.version = Briard::VERSION
14
- s.extra_rdoc_files = ["README.md"]
15
- s.license = 'MIT'
16
+ s.extra_rdoc_files = ['README.md']
17
+ s.license = 'MIT'
16
18
  s.required_ruby_version = '~> 2.3'
17
19
 
18
20
  # Declare dependencies here, rather than in the Gemfile
19
- s.add_dependency 'maremma', '>= 4.9.7', '< 5'
20
- s.add_dependency 'base32-url', '>= 0.5.0', '< 1'
21
- s.add_dependency 'faraday', '~> 0.17.3'
22
- s.add_dependency 'nokogiri', '~> 1.13.1'
23
- s.add_dependency 'loofah', '~> 2.0', '>= 2.0.3'
24
- s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
25
21
  s.add_dependency 'activesupport', '>= 4.2.5'
22
+ s.add_dependency 'base32-url', '>= 0.5.0', '< 1'
23
+ s.add_dependency 'benchmark_methods', '~> 0.7'
26
24
  s.add_dependency 'bibtex-ruby', '>= 5.1.0'
27
- s.add_dependency 'thor', '>= 1.1.0'
28
- s.add_dependency 'colorize', '~> 0.8.1'
29
- s.add_dependency 'namae', '~> 1.0'
30
- s.add_dependency 'edtf', '~> 3.0', '>= 3.0.4'
25
+ s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
31
26
  s.add_dependency 'citeproc-ruby', '~> 1.1', '>= 1.1.12'
27
+ s.add_dependency 'colorize', '~> 0.8.1'
28
+ s.add_dependency 'concurrent-ruby', '~> 1.1', '>= 1.1.5'
32
29
  s.add_dependency 'csl-styles', '~> 1.0', '>= 1.0.1.10'
30
+ s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
31
+ s.add_dependency 'edtf', '~> 3.0', '>= 3.0.4'
32
+ s.add_dependency 'faraday', '~> 0.17.3'
33
+ s.add_dependency 'faraday-multipart', '~> 1.0.4'
34
+ s.add_dependency 'gender_detector', '~> 0.1.2'
33
35
  s.add_dependency 'iso8601', '~> 0.9.1'
34
- s.add_dependency 'postrank-uri', '~> 1.0', '>= 1.0.18'
35
- s.add_dependency 'public_suffix', '2.0.5'
36
36
  s.add_dependency 'json-ld-preloaded', '~> 3.1', '>= 3.1.3'
37
37
  s.add_dependency 'jsonlint', '~> 0.3.0'
38
+ s.add_dependency 'loofah', '~> 2.0', '>= 2.0.3'
39
+ s.add_dependency 'maremma', '>= 4.9.7', '< 5'
40
+ s.add_dependency 'namae', '~> 1.0'
41
+ s.add_dependency 'nokogiri', '~> 1.13.1'
38
42
  s.add_dependency 'oj', '~> 3.10'
39
- s.add_dependency "oj_mimic_json", "~> 1.0", ">= 1.0.1"
40
- s.add_dependency 'rdf-turtle', '~> 3.1'
43
+ s.add_dependency 'oj_mimic_json', '~> 1.0', '>= 1.0.1'
44
+ s.add_dependency 'postrank-uri', '~> 1.0', '>= 1.0.18'
45
+ s.add_dependency 'public_suffix', '2.0.5'
41
46
  s.add_dependency 'rdf-rdfxml', '~> 3.1'
42
- s.add_dependency 'benchmark_methods', '~> 0.7'
43
- s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
44
- s.add_dependency 'gender_detector', '~> 0.1.2'
45
- s.add_dependency 'concurrent-ruby', '~> 1.1', '>= 1.1.5'
47
+ s.add_dependency 'rdf-turtle', '~> 3.1'
48
+ s.add_dependency 'thor', '>= 1.1.0'
46
49
  s.add_development_dependency 'bundler', '>= 1.0'
50
+ s.add_development_dependency 'code-scanning-rubocop', '~> 0.6.1'
51
+ s.add_development_dependency 'hashdiff', ['>= 1.0.0.beta1', '< 2.0.0']
52
+ s.add_development_dependency 'rack-test', '~> 0'
53
+ s.add_development_dependency 'rake', '~> 12.0'
47
54
  s.add_development_dependency 'rspec', '~> 3.4'
48
55
  s.add_development_dependency 'rspec-xsd', '~> 0.1.0'
49
- s.add_development_dependency 'rake', '~> 12.0'
50
- s.add_development_dependency 'rack-test', '~> 0'
56
+ s.add_development_dependency 'rubocop', '~> 1.36'
57
+ s.add_development_dependency 'rubocop-performance', '~> 1.15'
58
+ s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
59
+ s.add_development_dependency 'rubocop-rspec', '~> 2.13'
60
+ s.add_development_dependency 'simplecov', '0.17.1'
51
61
  s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
52
62
  s.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
53
- s.add_development_dependency 'simplecov', '0.17.1'
54
- s.add_development_dependency 'hashdiff', ['>= 1.0.0.beta1', '< 2.0.0']
55
63
 
56
- s.require_paths = ["lib"]
57
- s.files = `git ls-files`.split($/)
58
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
59
- s.executables = ["briard"]
64
+ s.require_paths = ['lib']
65
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
66
+ s.executables = ['briard']
67
+ s.metadata['rubygems_mfa_required'] = 'true'
60
68
  end
data/lib/briard/array.rb CHANGED
@@ -4,9 +4,9 @@
4
4
  # Reverses Array.wrap, but uses self to allow chaining with Array.wrap
5
5
  class Array
6
6
  def unwrap
7
- case self.length
7
+ case length
8
8
  when 0 then nil
9
- when 1 then self.first
9
+ when 1 then first
10
10
  else self
11
11
  end
12
12
  end
@@ -8,53 +8,56 @@ module Briard
8
8
  #
9
9
  # benchmark :get_authors
10
10
 
11
- IDENTIFIER_SCHEME_URIS = {
12
- "ORCID" => "https://orcid.org/"
13
- }
11
+ IDENTIFIER_SCHEME_URIS = { 'ORCID' => 'https://orcid.org/' }.freeze
14
12
 
15
13
  def get_one_author(author)
16
14
  # author is a string
17
- author = { "creatorName" => author } if author.is_a?(String)
15
+ author = { 'creatorName' => author } if author.is_a?(String)
18
16
 
19
17
  # malformed XML
20
- return nil if author.fetch("creatorName", nil).is_a?(Array)
18
+ return nil if author.fetch('creatorName', nil).is_a?(Array)
21
19
 
22
- name = parse_attributes(author.fetch("creatorName", nil)) ||
23
- parse_attributes(author.fetch("contributorName", nil))
24
- given_name = parse_attributes(author.fetch("givenName", nil))
25
- family_name = parse_attributes(author.fetch("familyName", nil))
20
+ name = parse_attributes(author.fetch('creatorName', nil)) ||
21
+ parse_attributes(author.fetch('contributorName', nil))
22
+ given_name = parse_attributes(author.fetch('givenName', nil))
23
+ family_name = parse_attributes(author.fetch('familyName', nil))
26
24
  name = cleanup_author(name)
27
- name = [family_name, given_name].join(", ") if family_name.present? && given_name.present?
28
- contributor_type = parse_attributes(author.fetch("contributorType", nil))
25
+ name = [family_name, given_name].join(', ') if family_name.present? && given_name.present?
26
+ contributor_type = parse_attributes(author.fetch('contributorType', nil))
29
27
 
30
- name_type = parse_attributes(author.fetch("creatorName", nil), content: "nameType", first: true) || parse_attributes(author.fetch("contributorName", nil), content: "nameType", first: true)
28
+ name_type = parse_attributes(author.fetch('creatorName', nil), content: 'nameType',
29
+ first: true) || parse_attributes(author.fetch('contributorName', nil), content: 'nameType',
30
+ first: true)
31
31
 
32
- name_identifiers = Array.wrap(author.fetch("nameIdentifier", nil)).map do |ni|
33
- if ni["nameIdentifierScheme"] == "ORCID"
32
+ name_identifiers = Array.wrap(author.fetch('nameIdentifier', nil)).map do |ni|
33
+ if ni['nameIdentifierScheme'] == 'ORCID'
34
34
  {
35
- "nameIdentifier" => normalize_orcid(ni["__content__"]),
36
- "schemeUri" => "https://orcid.org",
37
- "nameIdentifierScheme" => "ORCID" }.compact
38
- elsif ni["schemeURI"].present?
35
+ 'nameIdentifier' => normalize_orcid(ni['__content__']),
36
+ 'schemeUri' => 'https://orcid.org',
37
+ 'nameIdentifierScheme' => 'ORCID'
38
+ }.compact
39
+ elsif ni['schemeURI'].present?
39
40
  {
40
- "nameIdentifier" => ni["schemeURI"].to_s + ni["__content__"].to_s,
41
- "schemeUri" => ni["schemeURI"].to_s,
42
- "nameIdentifierScheme" => ni["nameIdentifierScheme"] }.compact
41
+ 'nameIdentifier' => ni['schemeURI'].to_s + ni['__content__'].to_s,
42
+ 'schemeUri' => ni['schemeURI'].to_s,
43
+ 'nameIdentifierScheme' => ni['nameIdentifierScheme']
44
+ }.compact
43
45
  else
44
46
  {
45
- "nameIdentifier" => ni["__content__"],
46
- "schemeUri" => nil,
47
- "nameIdentifierScheme" => ni["nameIdentifierScheme"] }.compact
47
+ 'nameIdentifier' => ni['__content__'],
48
+ 'schemeUri' => nil,
49
+ 'nameIdentifierScheme' => ni['nameIdentifierScheme']
50
+ }.compact
48
51
  end
49
52
  end.presence
50
53
 
51
- author = { "nameType" => name_type,
52
- "name" => name,
53
- "givenName" => given_name,
54
- "familyName" => family_name,
55
- "nameIdentifiers" => name_identifiers,
56
- "affiliation" => get_affiliations(author.fetch("affiliation", nil)),
57
- "contributorType" => contributor_type }.compact
54
+ author = { 'nameType' => name_type,
55
+ 'name' => name,
56
+ 'givenName' => given_name,
57
+ 'familyName' => family_name,
58
+ 'nameIdentifiers' => name_identifiers,
59
+ 'affiliation' => get_affiliations(author.fetch('affiliation', nil)),
60
+ 'contributorType' => contributor_type }.compact
58
61
 
59
62
  return author if family_name.present?
60
63
 
@@ -66,25 +69,25 @@ module Briard
66
69
  if parsed_name.present?
67
70
  given_name = parsed_name.given
68
71
  family_name = parsed_name.family
69
- name = [family_name, given_name].join(", ")
72
+ name = [family_name, given_name].join(', ')
70
73
  else
71
74
  given_name = nil
72
75
  family_name = nil
73
76
  end
74
77
 
75
- { "nameType" => "Personal",
76
- "name" => name,
77
- "givenName" => given_name,
78
- "familyName" => family_name,
79
- "nameIdentifiers" => Array.wrap(name_identifiers),
80
- "affiliation" => Array.wrap(author.fetch("affiliation", nil)),
81
- "contributorType" => contributor_type }.compact
78
+ { 'nameType' => 'Personal',
79
+ 'name' => name,
80
+ 'givenName' => given_name,
81
+ 'familyName' => family_name,
82
+ 'nameIdentifiers' => Array.wrap(name_identifiers),
83
+ 'affiliation' => Array.wrap(author.fetch('affiliation', nil)),
84
+ 'contributorType' => contributor_type }.compact
82
85
  else
83
- { "nameType" => name_type,
84
- "name" => name,
85
- "nameIdentifiers" => Array.wrap(name_identifiers),
86
- "affiliation" => Array.wrap(author.fetch("affiliation", nil)),
87
- "contributorType" => contributor_type }.compact
86
+ { 'nameType' => name_type,
87
+ 'name' => name,
88
+ 'nameIdentifiers' => Array.wrap(name_identifiers),
89
+ 'affiliation' => Array.wrap(author.fetch('affiliation', nil)),
90
+ 'contributorType' => contributor_type }.compact
88
91
  end
89
92
  end
90
93
 
@@ -92,10 +95,12 @@ module Briard
92
95
  return nil unless author.present?
93
96
 
94
97
  # detect pattern "Smith J.", but not "Smith, John K."
95
- author = author.gsub(/[[:space:]]([A-Z]\.)?(-?[A-Z]\.)$/, ', \1\2') unless author.include?(",")
98
+ unless author.include?(',')
99
+ author = author.gsub(/[[:space:]]([A-Z]\.)?(-?[A-Z]\.)$/, ', \1\2')
100
+ end
96
101
 
97
102
  # remove spaces around hyphens
98
- author = author.gsub(" - ", "-")
103
+ author = author.gsub(' - ', '-')
99
104
 
100
105
  # titleize strings
101
106
  # remove non-standard space characters
@@ -103,12 +108,15 @@ module Briard
103
108
  end
104
109
 
105
110
  def is_personal_name?(author)
106
- return false if author.fetch("nameType", nil) == "Organizational"
107
- return true if Array.wrap(author.fetch("nameIdentifiers", nil)).find { |a| a["nameIdentifierScheme"] == "ORCID" }.present? ||
108
- author.fetch("familyName", "").present? ||
109
- (author.fetch("name", "").include?(",") &&
110
- author.fetch("name", "").exclude?(";")) ||
111
- name_exists?(author.fetch("name", "").split(" ").first)
111
+ return false if author.fetch('nameType', nil) == 'Organizational'
112
+ return true if Array.wrap(author.fetch('nameIdentifiers', nil)).find do |a|
113
+ a['nameIdentifierScheme'] == 'ORCID'
114
+ end.present? ||
115
+ author.fetch('familyName', '').present? ||
116
+ (author.fetch('name', '').include?(',') &&
117
+ author.fetch('name', '').exclude?(';')) ||
118
+ name_exists?(author.fetch('name', '').split.first)
119
+
112
120
  false
113
121
  end
114
122
 
@@ -126,14 +134,14 @@ module Briard
126
134
 
127
135
  def authors_as_string(authors)
128
136
  Array.wrap(authors).map do |a|
129
- if a["familyName"].present?
130
- [a["familyName"], a["givenName"]].join(", ")
131
- elsif a["type"] == "Person"
132
- a["name"]
133
- elsif a["name"].present?
134
- "{" + a["name"] + "}"
137
+ if a['familyName'].present?
138
+ [a['familyName'], a['givenName']].join(', ')
139
+ elsif a['type'] == 'Person'
140
+ a['name']
141
+ elsif a['name'].present?
142
+ "{#{a['name']}}"
135
143
  end
136
- end.join(" and ").presence
144
+ end.join(' and ').presence
137
145
  end
138
146
 
139
147
  def get_affiliations(affiliations)
@@ -144,22 +152,22 @@ module Briard
144
152
  affiliation_identifier_scheme = nil
145
153
  scheme_uri = nil
146
154
  else
147
- if a["affiliationIdentifier"].present?
148
- affiliation_identifier = a["affiliationIdentifier"]
149
- if a["schemeURI"].present?
150
- schemeURI = a["schemeURI"].end_with?("/") ? a["schemeURI"] : a["schemeURI"] + "/"
155
+ if a['affiliationIdentifier'].present?
156
+ affiliation_identifier = a['affiliationIdentifier']
157
+ if a['schemeURI'].present?
158
+ schemeURI = a['schemeURI'].end_with?('/') ? a['schemeURI'] : "#{a['schemeURI']}/"
151
159
  end
152
- affiliation_identifier = !affiliation_identifier.to_s.start_with?("https://") && schemeURI.present? ? normalize_id(schemeURI + affiliation_identifier) : normalize_id(affiliation_identifier)
160
+ affiliation_identifier = !affiliation_identifier.to_s.start_with?('https://') && schemeURI.present? ? normalize_id(schemeURI + affiliation_identifier) : normalize_id(affiliation_identifier)
153
161
  end
154
- name = a["__content__"].to_s.squish.presence
155
- affiliation_identifier_scheme = a["affiliationIdentifierScheme"]
156
- scheme_uri = a["SchemeURI"]
162
+ name = a['__content__'].to_s.squish.presence
163
+ affiliation_identifier_scheme = a['affiliationIdentifierScheme']
164
+ scheme_uri = a['SchemeURI']
157
165
  end
158
166
 
159
- { "name" => name,
160
- "affiliationIdentifier" => affiliation_identifier,
161
- "affiliationIdentifierScheme" => affiliation_identifier_scheme,
162
- "schemeUri" => scheme_uri }.compact
167
+ { 'name' => name,
168
+ 'affiliationIdentifier' => affiliation_identifier,
169
+ 'affiliationIdentifierScheme' => affiliation_identifier_scheme,
170
+ 'schemeUri' => scheme_uri }.compact
163
171
  end.presence
164
172
  end
165
173
  end