ddr-models 3.0.0.rc5 → 3.0.0.rc6
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 +4 -4
- data/lib/ddr/index.rb +0 -2
- data/lib/ddr/index/csv_query_result.rb +37 -20
- data/lib/ddr/models/version.rb +1 -1
- data/spec/index/csv_query_result_spec.rb +12 -10
- metadata +2 -4
- data/lib/ddr/index/csv_options.rb +0 -12
- data/lib/ddr/index/solr_csv_options.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6221b58e1c08d584587392c482d43567bebfca21
|
4
|
+
data.tar.gz: 83d4109b5fda3dc2bcb73cf0200b86c2323c1cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c88cf0d218192ab7bbc26ae5552df1d087cc4d9d67c2cdd35bfd2fa674760c97db298ccfaf117b7583df5f3301b955d8cc6482df4218e462363c3fd13e56bb2e
|
7
|
+
data.tar.gz: 024ea216efe3f4172d02a60e8e2e4f9523cc930b3e2bf374a0fa2298d40d0bc82e8428fb416f8a69bbe9f8fcf017e411861e93dbd52a822be4c6cc1397fbdf5d
|
data/lib/ddr/index.rb
CHANGED
@@ -4,7 +4,6 @@ module Ddr
|
|
4
4
|
|
5
5
|
autoload :AbstractQueryResult
|
6
6
|
autoload :Connection
|
7
|
-
autoload :CSVOptions
|
8
7
|
autoload :CSVQueryResult
|
9
8
|
autoload :DocumentBuilder
|
10
9
|
autoload :Field
|
@@ -18,7 +17,6 @@ module Ddr
|
|
18
17
|
autoload :QueryParams
|
19
18
|
autoload :QueryResult
|
20
19
|
autoload :Response
|
21
|
-
autoload :SolrCSVOptions
|
22
20
|
autoload :SortOrder
|
23
21
|
autoload :UniqueKeyField
|
24
22
|
|
@@ -3,57 +3,74 @@ require "csv"
|
|
3
3
|
module Ddr::Index
|
4
4
|
class CSVQueryResult < AbstractQueryResult
|
5
5
|
|
6
|
-
|
6
|
+
MAX_ROWS = 10**8
|
7
|
+
CSV_MV_SEPARATOR = ";"
|
8
|
+
|
9
|
+
DESCMD_HEADER_CONVERTER = lambda { |header|
|
10
|
+
if term = Ddr::Models::DescriptiveMetadata.mapping[header.to_sym]
|
11
|
+
term.unqualified_name.to_s
|
12
|
+
else
|
13
|
+
header
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
delegate :headers, :to_s, :to_csv, to: :table
|
7
18
|
|
8
19
|
def delete_empty_columns!
|
9
|
-
mode = table.mode
|
10
20
|
table.by_col!.delete_if { |c, vals| vals.all?(&:nil?) }
|
11
|
-
table.send("by_#{mode}!")
|
12
21
|
end
|
13
22
|
|
14
23
|
def each(&block)
|
15
24
|
table.by_row!.each(&block)
|
16
25
|
end
|
17
26
|
|
27
|
+
def [](index_or_header)
|
28
|
+
table.by_col_or_row![index_or_header]
|
29
|
+
end
|
30
|
+
|
18
31
|
def table
|
19
|
-
@table ||= CSV.parse(data, csv_opts
|
32
|
+
@table ||= CSV.parse(data, csv_opts)
|
20
33
|
end
|
21
34
|
|
22
35
|
def csv_opts
|
23
|
-
|
36
|
+
{ headers: csv_headers,
|
37
|
+
return_headers: false,
|
38
|
+
write_headers: true,
|
39
|
+
header_converters: [ DESCMD_HEADER_CONVERTER ],
|
40
|
+
}
|
24
41
|
end
|
25
42
|
|
26
43
|
def solr_csv_opts
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
44
|
+
{ "csv.mv.separator" => CSV_MV_SEPARATOR,
|
45
|
+
"csv.header" => solr_csv_header?,
|
46
|
+
"rows" => solr_csv_rows,
|
47
|
+
"wt" => "csv",
|
48
|
+
}
|
31
49
|
end
|
32
50
|
|
33
|
-
def
|
34
|
-
|
51
|
+
def query_field_headings
|
52
|
+
query.fields.map { |f| f.respond_to?(:heading) ? f.heading : f.to_s }
|
35
53
|
end
|
36
54
|
|
37
55
|
def csv_headers
|
38
|
-
|
39
|
-
:first_row
|
40
|
-
else
|
41
|
-
headers
|
42
|
-
end
|
56
|
+
query.fields.empty? ? :first_row : query_field_headings
|
43
57
|
end
|
44
58
|
|
45
|
-
def solr_csv_header
|
59
|
+
def solr_csv_header?
|
46
60
|
csv_headers == :first_row
|
47
61
|
end
|
48
62
|
|
63
|
+
def solr_csv_rows
|
64
|
+
query.rows || MAX_ROWS
|
65
|
+
end
|
66
|
+
|
49
67
|
def solr_csv_params
|
50
|
-
params.merge(solr_csv_opts
|
68
|
+
params.merge(solr_csv_opts)
|
51
69
|
end
|
52
70
|
|
53
71
|
def data
|
54
72
|
raw = conn.get("select", params: solr_csv_params)
|
55
|
-
|
56
|
-
raw.gsub(/\\#{mv_sep}/, mv_sep)
|
73
|
+
raw.gsub(/\\#{CSV_MV_SEPARATOR}/, CSV_MV_SEPARATOR)
|
57
74
|
end
|
58
75
|
|
59
76
|
end
|
data/lib/ddr/models/version.rb
CHANGED
@@ -20,21 +20,23 @@ module Ddr::Index
|
|
20
20
|
}
|
21
21
|
|
22
22
|
specify {
|
23
|
-
expect(subject["
|
24
|
-
expect(subject["
|
25
|
-
expect(subject["
|
26
|
-
expect(subject["
|
27
|
-
expect(subject.
|
23
|
+
expect(subject["title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
|
24
|
+
expect(subject["identifier"]).to contain_exactly("test1", "test2", nil)
|
25
|
+
expect(subject["description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
|
26
|
+
expect(subject["creator"]).to contain_exactly(nil, nil, nil)
|
27
|
+
expect(subject.headers).to include("creator")
|
28
|
+
expect(subject.to_s).to match(/creator/)
|
28
29
|
}
|
29
30
|
|
30
31
|
describe "#delete_empty_columns!" do
|
31
32
|
specify {
|
32
33
|
subject.delete_empty_columns!
|
33
|
-
expect(subject["
|
34
|
-
expect(subject["
|
35
|
-
expect(subject["
|
36
|
-
expect(subject["
|
37
|
-
expect(subject.
|
34
|
+
expect(subject["title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
|
35
|
+
expect(subject["identifier"]).to contain_exactly("test1", "test2", nil)
|
36
|
+
expect(subject["description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
|
37
|
+
expect(subject["creator"]).to contain_exactly(nil, nil, nil)
|
38
|
+
expect(subject.headers).to contain_exactly("pid", "title", "identifier", "description")
|
39
|
+
expect(subject.to_s).not_to match(/creator/)
|
38
40
|
}
|
39
41
|
end
|
40
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-05-
|
12
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -499,7 +499,6 @@ files:
|
|
499
499
|
- lib/ddr/index.rb
|
500
500
|
- lib/ddr/index/abstract_query_result.rb
|
501
501
|
- lib/ddr/index/connection.rb
|
502
|
-
- lib/ddr/index/csv_options.rb
|
503
502
|
- lib/ddr/index/csv_query_result.rb
|
504
503
|
- lib/ddr/index/document_builder.rb
|
505
504
|
- lib/ddr/index/field.rb
|
@@ -512,7 +511,6 @@ files:
|
|
512
511
|
- lib/ddr/index/query_params.rb
|
513
512
|
- lib/ddr/index/query_result.rb
|
514
513
|
- lib/ddr/index/response.rb
|
515
|
-
- lib/ddr/index/solr_csv_options.rb
|
516
514
|
- lib/ddr/index/sort_order.rb
|
517
515
|
- lib/ddr/index/unique_key_field.rb
|
518
516
|
- lib/ddr/jobs.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require "csv"
|
2
|
-
require "hashie"
|
3
|
-
|
4
|
-
module Ddr::Index
|
5
|
-
class CSVOptions < Hashie::Dash
|
6
|
-
property :headers, default: CSV::DEFAULT_OPTIONS[:headers]
|
7
|
-
property :return_headers, default: false
|
8
|
-
property :write_headers, default: true
|
9
|
-
property :col_sep, default: CSV::DEFAULT_OPTIONS[:col_sep]
|
10
|
-
property :quote_char, default: CSV::DEFAULT_OPTIONS[:quote_char]
|
11
|
-
end
|
12
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "hashie"
|
2
|
-
|
3
|
-
module Ddr::Index
|
4
|
-
class SolrCSVOptions < Hashie::Trash
|
5
|
-
|
6
|
-
MAX_ROWS = 10**8
|
7
|
-
CSV_MV_SEPARATOR = ";"
|
8
|
-
|
9
|
-
property "csv.header", from: :header, default: false
|
10
|
-
property "csv.separator", from: :col_sep, default: ","
|
11
|
-
property "csv.encapsulator", from: :quote_char, default: '"'
|
12
|
-
property "csv.mv.separator", default: CSV_MV_SEPARATOR
|
13
|
-
property :wt, default: "csv"
|
14
|
-
property :rows, default: MAX_ROWS
|
15
|
-
|
16
|
-
def params
|
17
|
-
to_h.reject { |k, v| v.nil? }
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|