berkeley_library-tind 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/tind.iml +12 -16
- data/CHANGES.md +4 -0
- data/berkeley_library-tind.gemspec +1 -0
- data/lib/berkeley_library/tind/api/api.rb +17 -11
- data/lib/berkeley_library/tind/api/collection.rb +1 -1
- data/lib/berkeley_library/tind/api/search.rb +1 -1
- data/lib/berkeley_library/tind/export/exporter.rb +1 -1
- data/lib/berkeley_library/tind/export/table.rb +1 -1
- data/lib/berkeley_library/tind/export/table_metrics.rb +1 -1
- data/lib/berkeley_library/tind/module_info.rb +1 -1
- data/lib/berkeley_library/util/ods/spreadsheet.rb +1 -1
- data/lib/berkeley_library/util/ods/xml/element_node.rb +1 -1
- metadata +16 -25
- data/lib/berkeley_library/util/arrays.rb +0 -178
- data/lib/berkeley_library/util/logging.rb +0 -1
- data/lib/berkeley_library/util/paths.rb +0 -111
- data/lib/berkeley_library/util/stringios.rb +0 -30
- data/lib/berkeley_library/util/strings.rb +0 -42
- data/lib/berkeley_library/util/sys_exits.rb +0 -15
- data/lib/berkeley_library/util/times.rb +0 -22
- data/lib/berkeley_library/util/uris/appender.rb +0 -162
- data/lib/berkeley_library/util/uris/requester.rb +0 -62
- data/lib/berkeley_library/util/uris/validator.rb +0 -32
- data/lib/berkeley_library/util/uris.rb +0 -44
- data/spec/berkeley_library/util/arrays_spec.rb +0 -340
- data/spec/berkeley_library/util/paths_spec.rb +0 -90
- data/spec/berkeley_library/util/stringios_spec.rb +0 -34
- data/spec/berkeley_library/util/strings_spec.rb +0 -27
- data/spec/berkeley_library/util/times_spec.rb +0 -39
- data/spec/berkeley_library/util/uris_spec.rb +0 -118
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c5ac2c784f31221ebf55a54b6a94852826de5604a7f84679f701280c5f6ffb
|
4
|
+
data.tar.gz: b39fcf43a9c2a02b3bb60a04b0e02de4ab16158d5aaca971d6aafefb117f2397
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7436d7db79bcffa0524adcccc3f318915509b9d5bc5321c6dfffa9586f10af7f627fe974a416f5310330beddeb751ccf21fd0974466343515c6a157a216f43
|
7
|
+
data.tar.gz: 96c1e8db0afea8db20d3f13db67e214212fa43ed0379a32a0f4a647436b7a9fdff148ea55e5806a7c0d90da7cf0b0f5fa7c518e16b8afb0c9c0d80926fb93679
|
data/.idea/tind.iml
CHANGED
@@ -17,12 +17,13 @@
|
|
17
17
|
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
18
18
|
<orderEntry type="library" scope="PROVIDED" name="amazing_print (v1.3.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
19
19
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
21
21
|
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-marc (v0.2.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-util (v0.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
22
23
|
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
23
24
|
<orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
24
25
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.14, RVM: ruby-2.7.4) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler-audit (v0.
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler-audit (v0.9.0.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
26
27
|
<orderEntry type="library" scope="PROVIDED" name="ci_reporter (v2.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
27
28
|
<orderEntry type="library" scope="PROVIDED" name="ci_reporter_rspec (v1.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
28
29
|
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
@@ -34,25 +35,23 @@
|
|
34
35
|
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20190701, RVM: ruby-2.7.4) [gem]" level="application" />
|
35
36
|
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.7.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
36
37
|
<orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
38
38
|
<orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.0.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
39
39
|
<orderEntry type="library" scope="PROVIDED" name="http-accept (v1.7.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
40
40
|
<orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
41
41
|
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.10, RVM: ruby-2.7.4) [gem]" level="application" />
|
42
42
|
<orderEntry type="library" scope="PROVIDED" name="ice_nine (v0.11.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
43
|
-
<orderEntry type="library" scope="PROVIDED" name="listen (v3.1.5, RVM: ruby-2.7.4) [gem]" level="application" />
|
44
43
|
<orderEntry type="library" scope="PROVIDED" name="lograge (v0.11.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
45
44
|
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.12.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
46
45
|
<orderEntry type="library" scope="PROVIDED" name="marc (v1.1.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
47
46
|
<orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
48
47
|
<orderEntry type="library" scope="PROVIDED" name="mime-types (v3.3.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
49
|
-
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2021.
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2021.0901, RVM: ruby-2.7.4) [gem]" level="application" />
|
50
49
|
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
51
50
|
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
52
|
-
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.12.
|
53
|
-
<orderEntry type="library" scope="PROVIDED" name="oj (v3.13.
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.12.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="oj (v3.13.7, RVM: ruby-2.7.4) [gem]" level="application" />
|
54
53
|
<orderEntry type="library" scope="PROVIDED" name="ougai (v1.9.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
55
|
-
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.
|
54
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
56
55
|
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
57
56
|
<orderEntry type="library" scope="PROVIDED" name="parslet (v2.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
58
57
|
<orderEntry type="library" scope="PROVIDED" name="public_suffix (v4.0.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
@@ -60,12 +59,10 @@
|
|
60
59
|
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
61
60
|
<orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
62
61
|
<orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, RVM: ruby-2.7.4) [gem]" level="application" />
|
63
|
-
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.
|
62
|
+
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
64
63
|
<orderEntry type="library" scope="PROVIDED" name="railties (v6.1.4.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
65
64
|
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
66
65
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.4) [gem]" level="application" />
|
67
|
-
<orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
68
|
-
<orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
69
66
|
<orderEntry type="library" scope="PROVIDED" name="rchardet (v1.8.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
70
67
|
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
71
68
|
<orderEntry type="library" scope="PROVIDED" name="request_store (v1.5.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
@@ -78,12 +75,11 @@
|
|
78
75
|
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
79
76
|
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
80
77
|
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
81
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.
|
78
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
82
79
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-rake (v0.6.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
83
80
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v2.4.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
84
81
|
<orderEntry type="library" scope="PROVIDED" name="ruby-prof (v0.17.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
85
82
|
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
86
|
-
<orderEntry type="library" scope="PROVIDED" name="ruby_dep (v1.5.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
87
83
|
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v2.3.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
88
84
|
<orderEntry type="library" scope="PROVIDED" name="scrub_rb (v1.0.1, RVM: ruby-2.7.4) [gem]" level="application" />
|
89
85
|
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
@@ -94,8 +90,8 @@
|
|
94
90
|
<orderEntry type="library" scope="PROVIDED" name="typesafe_enum (v0.3.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
95
91
|
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
96
92
|
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-2.7.4) [gem]" level="application" />
|
97
|
-
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.
|
98
|
-
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.
|
93
|
+
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8, RVM: ruby-2.7.4) [gem]" level="application" />
|
94
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
99
95
|
<orderEntry type="library" scope="PROVIDED" name="webmock (v3.14.0, RVM: ruby-2.7.4) [gem]" level="application" />
|
100
96
|
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.2, RVM: ruby-2.7.4) [gem]" level="application" />
|
101
97
|
</component>
|
@@ -110,7 +106,7 @@
|
|
110
106
|
</RakeTaskImpl>
|
111
107
|
<RakeTaskImpl description="Run all specs in spec directory, with coverage" fullCommand="coverage" id="coverage" />
|
112
108
|
<RakeTaskImpl description="Run tests, check test coverage, check code style, check for vulnerabilities, build gem" fullCommand="default" id="default" />
|
113
|
-
<RakeTaskImpl description="Build berkeley_library-tind.gemspec as berkeley_library-tind-0.4.
|
109
|
+
<RakeTaskImpl description="Build berkeley_library-tind.gemspec as berkeley_library-tind-0.4.1.gem" fullCommand="gem" id="gem" />
|
114
110
|
<RakeTaskImpl description="Run RuboCop with auto-correct, and output results to console" fullCommand="ra" id="ra" />
|
115
111
|
<RakeTaskImpl description="Run rubocop with HTML output" fullCommand="rubocop" id="rubocop" />
|
116
112
|
<RakeTaskImpl id="rubocop">
|
data/CHANGES.md
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_dependency 'berkeley_library-logging', '~> 0.2'
|
27
27
|
spec.add_dependency 'berkeley_library-marc', '~> 0.2'
|
28
|
+
spec.add_dependency 'berkeley_library-util', '~> 0.1'
|
28
29
|
spec.add_dependency 'ice_nine', '~> 0.11'
|
29
30
|
spec.add_dependency 'marc', '~> 1.0'
|
30
31
|
spec.add_dependency 'rchardet', '~> 1.8'
|
@@ -2,7 +2,7 @@ require 'stringio'
|
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
4
|
require 'berkeley_library/util/uris'
|
5
|
-
require 'berkeley_library/
|
5
|
+
require 'berkeley_library/logging'
|
6
6
|
require 'berkeley_library/tind/config'
|
7
7
|
require 'berkeley_library/tind/api/api_exception'
|
8
8
|
|
@@ -105,16 +105,22 @@ module BerkeleyLibrary
|
|
105
105
|
private
|
106
106
|
|
107
107
|
def do_get(endpoint_uri, params)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
108
|
+
headers = auth_headers(endpoint_uri, params)
|
109
|
+
URIs.get(endpoint_uri, params: params, headers: headers)
|
110
|
+
rescue RestClient::RequestFailed => e
|
111
|
+
raise APIException.wrap(e, url: endpoint_uri, params: params)
|
112
|
+
end
|
113
|
+
|
114
|
+
def auth_headers(endpoint_uri, params)
|
115
|
+
key = ensure_api_key(endpoint_uri, params)
|
116
|
+
{
|
117
|
+
'Authorization' => "Token #{key}",
|
118
|
+
'User-Agent' => user_agent
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def ensure_api_key(endpoint_uri, params)
|
123
|
+
api_key.tap { |k| raise APIKeyNotSet.new(endpoint_uri, params) if Config.blank?(k) }
|
118
124
|
end
|
119
125
|
|
120
126
|
# TODO: make real body streaming work
|
@@ -7,7 +7,7 @@ module BerkeleyLibrary
|
|
7
7
|
SUMMARY = 'TIND DA utilities for the UC Berkeley Library'.freeze
|
8
8
|
DESCRIPTION = 'UC Berkeley Library utility gem for working with the TIND DA digital archive.'.freeze
|
9
9
|
LICENSE = 'MIT'.freeze
|
10
|
-
VERSION = '0.4.
|
10
|
+
VERSION = '0.4.2'.freeze
|
11
11
|
HOMEPAGE = 'https://github.com/BerkeleyLibrary/tind'.freeze
|
12
12
|
end
|
13
13
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'zip'
|
3
|
-
require 'berkeley_library/
|
3
|
+
require 'berkeley_library/logging'
|
4
4
|
require 'berkeley_library/util/ods/xml/content_doc'
|
5
5
|
require 'berkeley_library/util/ods/xml/styles_doc'
|
6
6
|
require 'berkeley_library/util/ods/xml/manifest_doc'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berkeley_library-tind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: berkeley_library-logging
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: berkeley_library-util
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: ice_nine
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -377,8 +391,6 @@ files:
|
|
377
391
|
- lib/berkeley_library/tind/marc.rb
|
378
392
|
- lib/berkeley_library/tind/marc/xml_reader.rb
|
379
393
|
- lib/berkeley_library/tind/module_info.rb
|
380
|
-
- lib/berkeley_library/util/arrays.rb
|
381
|
-
- lib/berkeley_library/util/logging.rb
|
382
394
|
- lib/berkeley_library/util/ods/spreadsheet.rb
|
383
395
|
- lib/berkeley_library/util/ods/xml/content_doc.rb
|
384
396
|
- lib/berkeley_library/util/ods/xml/document_node.rb
|
@@ -418,15 +430,6 @@ files:
|
|
418
430
|
- lib/berkeley_library/util/ods/xml/table/table_column.rb
|
419
431
|
- lib/berkeley_library/util/ods/xml/table/table_row.rb
|
420
432
|
- lib/berkeley_library/util/ods/xml/text/p.rb
|
421
|
-
- lib/berkeley_library/util/paths.rb
|
422
|
-
- lib/berkeley_library/util/stringios.rb
|
423
|
-
- lib/berkeley_library/util/strings.rb
|
424
|
-
- lib/berkeley_library/util/sys_exits.rb
|
425
|
-
- lib/berkeley_library/util/times.rb
|
426
|
-
- lib/berkeley_library/util/uris.rb
|
427
|
-
- lib/berkeley_library/util/uris/appender.rb
|
428
|
-
- lib/berkeley_library/util/uris/requester.rb
|
429
|
-
- lib/berkeley_library/util/uris/validator.rb
|
430
433
|
- rakelib/bundle.rake
|
431
434
|
- rakelib/coverage.rake
|
432
435
|
- rakelib/gem.rake
|
@@ -451,7 +454,6 @@ files:
|
|
451
454
|
- spec/berkeley_library/tind/export/row_spec.rb
|
452
455
|
- spec/berkeley_library/tind/export/table_spec.rb
|
453
456
|
- spec/berkeley_library/tind/marc/xml_reader_spec.rb
|
454
|
-
- spec/berkeley_library/util/arrays_spec.rb
|
455
457
|
- spec/berkeley_library/util/ods/spreadsheet_spec.rb
|
456
458
|
- spec/berkeley_library/util/ods/xml/content_doc_spec.rb
|
457
459
|
- spec/berkeley_library/util/ods/xml/manifest/file_entry_spec.rb
|
@@ -461,11 +463,6 @@ files:
|
|
461
463
|
- spec/berkeley_library/util/ods/xml/style/family_spec.rb
|
462
464
|
- spec/berkeley_library/util/ods/xml/table/table_row_spec.rb
|
463
465
|
- spec/berkeley_library/util/ods/xml/table/table_spec.rb
|
464
|
-
- spec/berkeley_library/util/paths_spec.rb
|
465
|
-
- spec/berkeley_library/util/stringios_spec.rb
|
466
|
-
- spec/berkeley_library/util/strings_spec.rb
|
467
|
-
- spec/berkeley_library/util/times_spec.rb
|
468
|
-
- spec/berkeley_library/util/uris_spec.rb
|
469
466
|
- spec/data/collection-names.txt
|
470
467
|
- spec/data/collections.json
|
471
468
|
- spec/data/disjoint-records.xml
|
@@ -528,7 +525,6 @@ test_files:
|
|
528
525
|
- spec/berkeley_library/tind/export/row_spec.rb
|
529
526
|
- spec/berkeley_library/tind/export/table_spec.rb
|
530
527
|
- spec/berkeley_library/tind/marc/xml_reader_spec.rb
|
531
|
-
- spec/berkeley_library/util/arrays_spec.rb
|
532
528
|
- spec/berkeley_library/util/ods/spreadsheet_spec.rb
|
533
529
|
- spec/berkeley_library/util/ods/xml/content_doc_spec.rb
|
534
530
|
- spec/berkeley_library/util/ods/xml/manifest/file_entry_spec.rb
|
@@ -538,11 +534,6 @@ test_files:
|
|
538
534
|
- spec/berkeley_library/util/ods/xml/style/family_spec.rb
|
539
535
|
- spec/berkeley_library/util/ods/xml/table/table_row_spec.rb
|
540
536
|
- spec/berkeley_library/util/ods/xml/table/table_spec.rb
|
541
|
-
- spec/berkeley_library/util/paths_spec.rb
|
542
|
-
- spec/berkeley_library/util/stringios_spec.rb
|
543
|
-
- spec/berkeley_library/util/strings_spec.rb
|
544
|
-
- spec/berkeley_library/util/times_spec.rb
|
545
|
-
- spec/berkeley_library/util/uris_spec.rb
|
546
537
|
- spec/data/collection-names.txt
|
547
538
|
- spec/data/collections.json
|
548
539
|
- spec/data/disjoint-records.xml
|
@@ -1,178 +0,0 @@
|
|
1
|
-
module BerkeleyLibrary
|
2
|
-
module Util
|
3
|
-
module Arrays
|
4
|
-
class << self
|
5
|
-
# Clients can chose to call class methods directly, or include the module
|
6
|
-
include Arrays
|
7
|
-
end
|
8
|
-
|
9
|
-
# Recursively checks whether the specified list contains, in the
|
10
|
-
# same order, all values in the other specified list (additional codes
|
11
|
-
# in between are fine)
|
12
|
-
#
|
13
|
-
# @param subset [Array] the values to look for
|
14
|
-
# @param superset [Array] the list of values to look in
|
15
|
-
# @return boolean True if all values were found, false otherwise
|
16
|
-
def ordered_superset?(superset:, subset:)
|
17
|
-
!find_indices(in_array: superset, for_array: subset).nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
# Counts how many contiguous elements from the start of an
|
21
|
-
# sequence of values satisfy the given block.
|
22
|
-
#
|
23
|
-
# @overload count_while(arr:)
|
24
|
-
# Returns an enumerator.
|
25
|
-
# @param values [Enumerable] the values
|
26
|
-
# @return [Enumerator] the enumerator.
|
27
|
-
# @overload count_while(arr:, &block)
|
28
|
-
# Passes elements to the block until the block returns nil or false,
|
29
|
-
# then stops iterating and returns the count of matching elements.
|
30
|
-
# @param values [Enumerable] the values
|
31
|
-
# @return [Integer] the count
|
32
|
-
def count_while(values:)
|
33
|
-
return to_enum(:count_while, values: values) unless block_given?
|
34
|
-
|
35
|
-
values.inject(0) do |count, x|
|
36
|
-
matched = yield x
|
37
|
-
break count unless matched
|
38
|
-
|
39
|
-
count + 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Given two lists, one of which is a superset of the other, with elements
|
44
|
-
# in the same order (but possibly with additional elements in the superset),
|
45
|
-
# returns an array the length of the subset, containing for each element in
|
46
|
-
# the subset the index of the corresponding element in the superset.
|
47
|
-
#
|
48
|
-
# @overload find_matching_indices(for_array:, in_array:)
|
49
|
-
# For each value in `for_array`, finds the index of the first equal value
|
50
|
-
# in `in_array` after the previously matched value.
|
51
|
-
# @param in_array [Array] the list of values to look in
|
52
|
-
# @param for_array [Array] the values to look for
|
53
|
-
# @return [Array<Integer>, nil] the indices in `in_array` of each value in `for_array`,
|
54
|
-
# or `nil` if not all values could be found
|
55
|
-
#
|
56
|
-
# @overload find_matching_indices(for_array:, in_array:)
|
57
|
-
# For each value in `for_array`, finds the index of the first value
|
58
|
-
# in `in_array` after the previously matched value that matches
|
59
|
-
# the specified match function.
|
60
|
-
# @param in_array [Array] the list of values to look in
|
61
|
-
# @param for_array [Array] the values to look for
|
62
|
-
# @yieldparam source [Object] the value to compare
|
63
|
-
# @yieldparam target [Object] the value to compare against
|
64
|
-
# @return [Array<Integer>, nil] the indices in `in_array` of each value in `for_array`,
|
65
|
-
# or `nil` if not all values could be found
|
66
|
-
def find_indices(for_array:, in_array:, &block)
|
67
|
-
return find_indices_matching(for_array, in_array, &block) if block_given?
|
68
|
-
|
69
|
-
find_all_indices(for_array, in_array)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Given a block or a value, finds the index of the first matching value
|
73
|
-
# at or after the specified start index.
|
74
|
-
#
|
75
|
-
# @overload find_index(value, in_array:, start_index:)
|
76
|
-
# Finds the first index of the specified value.
|
77
|
-
# @param value [Object] the value to find
|
78
|
-
# @param in_array [Array] the array to search
|
79
|
-
# @param start_index [Integer] the index to start with
|
80
|
-
# @return [Integer, nil] the index, or `nil` if no value matches
|
81
|
-
# @overload find_index(&block)
|
82
|
-
# Finds the index of the first value matching
|
83
|
-
# the specified block.
|
84
|
-
# @param in_array [Array] the array to search
|
85
|
-
# @param start_index [Integer] the index to start with
|
86
|
-
# @yieldreturn [Boolean] whether the element matches
|
87
|
-
# @return [Integer, nil] the index, or `nil` if no value matches
|
88
|
-
# @overload find_index
|
89
|
-
# @param in_array [Array] the array to search
|
90
|
-
# @param start_index [Integer] the index to start with
|
91
|
-
# @return [Enumerator] a new enumerator
|
92
|
-
def find_index(*args, in_array:, start_index: 0, &block)
|
93
|
-
raise ArgumentError, "wrong number of arguments (given #{value.length}, expected 0..1" if args.size > 1
|
94
|
-
return Enumerator.new { |y| find_index(in_array: in_array, start_index: start_index, &y) } if args.empty? && !block_given?
|
95
|
-
return unless (relative_index = in_array[start_index..].find_index(*args, &block))
|
96
|
-
|
97
|
-
relative_index + start_index
|
98
|
-
end
|
99
|
-
|
100
|
-
# Given an array of unique integers _a<sub>1</sub>_, returns a new array
|
101
|
-
# _a<sub>2</sub>_ in which the value at each index _i<sub>2</sub>_ is the
|
102
|
-
# index _i<sub>1</sub>_ at which that value was found in _a<sub>1</sub>_.
|
103
|
-
# E.g., given `[0, 2, 3]`, returns `[0, nil, 1, 2]`. The indices need
|
104
|
-
# not be in order but must be unique.
|
105
|
-
#
|
106
|
-
# @param arr [Array<Integer>, nil] the array to invert.
|
107
|
-
# @return [Array<Integer, nil>, nil] the inverted array, or nil if the input array is nil
|
108
|
-
# @raise TypeError if `arr` is not an array of integers
|
109
|
-
# @raise ArgumentError if `arr` contains duplicate values
|
110
|
-
def invert(arr)
|
111
|
-
return unless arr
|
112
|
-
|
113
|
-
# noinspection RubyNilAnalysis
|
114
|
-
Array.new(arr.size).tap do |inv|
|
115
|
-
arr.each_with_index do |v, i|
|
116
|
-
next inv[v] = i unless (prev_index = inv[v])
|
117
|
-
|
118
|
-
raise ArgumentError, "Duplicate value #{v} at index #{i} already found at #{prev_index}"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Merges two arrays in an order-preserving manner.
|
124
|
-
# @param a1 [Array] the first array
|
125
|
-
# @param a2 [Array] the second array
|
126
|
-
# @return [Array] a merged array that is an ordered superset of both `a1` and `a2`
|
127
|
-
# @see Arrays#ordered_superset?
|
128
|
-
def merge(a1, a2)
|
129
|
-
return a1 if a2.empty?
|
130
|
-
return a2 if a1.empty?
|
131
|
-
|
132
|
-
shorter, longer = a1.size > a2.size ? [a2, a1] : [a1, a2]
|
133
|
-
do_merge(shorter, longer)
|
134
|
-
end
|
135
|
-
|
136
|
-
private
|
137
|
-
|
138
|
-
def do_merge(shorter, longer)
|
139
|
-
shorter.each_with_index do |v, ix_s|
|
140
|
-
next unless (ix_l = longer.find_index(v))
|
141
|
-
|
142
|
-
shorter_unmatched = shorter[0...ix_s]
|
143
|
-
longer_unmatched = longer[0...ix_l]
|
144
|
-
all_unmatched = sort_by_first_and_flatten(shorter_unmatched, longer_unmatched)
|
145
|
-
return (all_unmatched << v) + merge(shorter[ix_s + 1..], longer[ix_l + 1..])
|
146
|
-
end
|
147
|
-
|
148
|
-
sort_by_first_and_flatten(longer, shorter)
|
149
|
-
end
|
150
|
-
|
151
|
-
def sort_by_first_and_flatten(a1, a2)
|
152
|
-
return a1 if a2.empty?
|
153
|
-
return a2 if a1.empty?
|
154
|
-
return a2 + a1 if a1.first.respond_to?(:>) && a1.first > a2.first
|
155
|
-
|
156
|
-
a1 + a2
|
157
|
-
end
|
158
|
-
|
159
|
-
def find_all_indices(source, target)
|
160
|
-
source.each_with_object([]) do |src, target_indices|
|
161
|
-
target_offset = (target_indices.last&.+ 1) || 0
|
162
|
-
return nil unless (target_index = find_index(src, in_array: target, start_index: target_offset))
|
163
|
-
|
164
|
-
target_indices << target_index
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def find_indices_matching(source, target)
|
169
|
-
source.each_with_object([]) do |src, target_indices|
|
170
|
-
target_offset = (target_indices.last&.+ 1) || 0
|
171
|
-
return nil unless (target_index = find_index(in_array: target, start_index: target_offset) { |tgt| yield src, tgt })
|
172
|
-
|
173
|
-
target_indices << target_index
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'berkeley_library/logging'
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'berkeley_library/util/stringios'
|
2
|
-
|
3
|
-
module BerkeleyLibrary
|
4
|
-
module Util
|
5
|
-
# This module, modeled on the {https://golang.org/pkg/path/ Go `path` package},
|
6
|
-
# provides utility routines for modifying paths separated by forward slashes,
|
7
|
-
# such as URL paths. For system-dependent file paths, use
|
8
|
-
# {https://ruby-doc.org/stdlib-2.7.0/libdoc/pathname/rdoc/Pathname.html `Pathname`}
|
9
|
-
# instead.
|
10
|
-
module Paths
|
11
|
-
include BerkeleyLibrary::Util::StringIOs
|
12
|
-
|
13
|
-
class << self
|
14
|
-
include Paths
|
15
|
-
end
|
16
|
-
|
17
|
-
# Returns the shortest path name equivalent to `path` by purely lexical
|
18
|
-
# processing by:
|
19
|
-
#
|
20
|
-
# 1. replacing runs of multiple `/` with a single `/`
|
21
|
-
# 2. eliminating all `.` (current directory) elements
|
22
|
-
# 3. eliminating all `<child>/..` in favor of directly
|
23
|
-
# referencing the parent directory
|
24
|
-
# 4. replaing all `/..` at the beginning of the path
|
25
|
-
# with a single leading `/`
|
26
|
-
#
|
27
|
-
# The returned path ends in a slash only if it is the root `/`.
|
28
|
-
# @see https://9p.io/sys/doc/lexnames.html Rob Pike, "Lexical File Names in Plan 9 or Getting Dot-Dot Right"
|
29
|
-
#
|
30
|
-
# @param path [String, nil] the path to clean
|
31
|
-
# @return [String, nil] the cleaned path, or `nil` for a nil path.
|
32
|
-
def clean(path)
|
33
|
-
return unless path
|
34
|
-
return '.' if ['', '.'].include?(path)
|
35
|
-
|
36
|
-
StringIO.new.tap do |out|
|
37
|
-
out << '/' if path[0] == '/'
|
38
|
-
dotdot = (r = out.size)
|
39
|
-
r, dotdot = process_next(r, dotdot, path, out) while r < path.size
|
40
|
-
out << '.' if out.pos == 0
|
41
|
-
end.string
|
42
|
-
end
|
43
|
-
|
44
|
-
# Joins any number of path elements into a single path, separating
|
45
|
-
# them with slashes, ignoring empty elements and passing the result
|
46
|
-
# to {Paths#clean}.
|
47
|
-
#
|
48
|
-
# @param elements [Array<String>] the elements to join
|
49
|
-
# @return [String] the joined path
|
50
|
-
def join(*elements)
|
51
|
-
elements = elements.reject { |e| [nil, ''].include?(e) }
|
52
|
-
joined_raw = elements.join('/')
|
53
|
-
return '' if joined_raw == ''
|
54
|
-
|
55
|
-
clean(joined_raw)
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def process_next(r, dotdot, path, out)
|
61
|
-
# empty path element, or .
|
62
|
-
return r + 1, dotdot if empty_or_dot?(r, path)
|
63
|
-
# .. element: remove to last /
|
64
|
-
return handle_dotdot(r, dotdot, path, out) if dotdot?(r, path)
|
65
|
-
|
66
|
-
# real path element
|
67
|
-
[append_from(r, path, out), dotdot]
|
68
|
-
end
|
69
|
-
|
70
|
-
def handle_dotdot(r, dotdot, path, out)
|
71
|
-
if out.pos > dotdot
|
72
|
-
backtrack_to_dotdot(out, dotdot)
|
73
|
-
elsif path[0] != '/'
|
74
|
-
dotdot = append_dotdot(out)
|
75
|
-
end
|
76
|
-
|
77
|
-
[r + 2, dotdot]
|
78
|
-
end
|
79
|
-
|
80
|
-
def dotdot?(r, path)
|
81
|
-
path[r] == '.' && (r + 2 == path.size || path[r + 2] == '/')
|
82
|
-
end
|
83
|
-
|
84
|
-
def empty_or_dot?(r, path)
|
85
|
-
path[r] == '/' || (path[r] == '.' && (r + 1 == path.size || path[r + 1] == '/'))
|
86
|
-
end
|
87
|
-
|
88
|
-
def append_from(r, path, out)
|
89
|
-
out << '/' if (path[0] == '/' && out.pos != 1) || (path[0] != '/' && out.pos != 0)
|
90
|
-
while r < path.size && path[r] != '/'
|
91
|
-
out << path[r]
|
92
|
-
r += 1
|
93
|
-
end
|
94
|
-
r
|
95
|
-
end
|
96
|
-
|
97
|
-
def append_dotdot(out)
|
98
|
-
out << '/' if out.pos > 1
|
99
|
-
out << '..'
|
100
|
-
out.pos
|
101
|
-
end
|
102
|
-
|
103
|
-
def backtrack_to_dotdot(out, dotdot)
|
104
|
-
out.seek(-1, IO::SEEK_CUR)
|
105
|
-
out.seek(-1, IO::SEEK_CUR) while out.pos > dotdot && getbyte(out, out.pos) != 47 # '/' is ASCII 37
|
106
|
-
out.truncate(out.pos)
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|