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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 882499780ce1326eec18ff01bdead5d41dcb0819
4
- data.tar.gz: 6c9b5b6edbb3d442b2f5cf6d6d7d74ff31fe7707
3
+ metadata.gz: 6221b58e1c08d584587392c482d43567bebfca21
4
+ data.tar.gz: 83d4109b5fda3dc2bcb73cf0200b86c2323c1cbb
5
5
  SHA512:
6
- metadata.gz: fcc433f961a831d8b14bc2825a355351feb9e9be28c68c16e1348b1d5ef7bcd1be692a152026dbad6177a4f65ad7f046f9c9fe75c13e883448a230eea327f9de
7
- data.tar.gz: f9778626680a979a3d46768d6e7af65aa7f3d916c3560d0ac52394466b13f6ab377a55a4e084ddeaa61fff372699deec49a6fc798ead1aaf35e3bfe6b7f273ea
6
+ metadata.gz: c88cf0d218192ab7bbc26ae5552df1d087cc4d9d67c2cdd35bfd2fa674760c97db298ccfaf117b7583df5f3301b955d8cc6482df4218e462363c3fd13e56bb2e
7
+ data.tar.gz: 024ea216efe3f4172d02a60e8e2e4f9523cc930b3e2bf374a0fa2298d40d0bc82e8428fb416f8a69bbe9f8fcf017e411861e93dbd52a822be4c6cc1397fbdf5d
@@ -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
- delegate :[], :to_s, :to_csv, to: :table
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.to_h)
32
+ @table ||= CSV.parse(data, csv_opts)
20
33
  end
21
34
 
22
35
  def csv_opts
23
- @csv_opts ||= CSVOptions.new(headers: csv_headers)
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
- @solr_csv_opts ||= SolrCSVOptions.new(col_sep: csv_opts.col_sep,
28
- quote_char: csv_opts.quote_char,
29
- header: solr_csv_header,
30
- rows: query.rows)
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 headers
34
- @headers ||= query.fields.map { |f| f.respond_to?(:heading) ? f.heading : f.to_s }
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
- if headers.empty?
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.params)
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
- mv_sep = solr_csv_opts["csv.mv.separator"]
56
- raw.gsub(/\\#{mv_sep}/, mv_sep)
73
+ raw.gsub(/\\#{CSV_MV_SEPARATOR}/, CSV_MV_SEPARATOR)
57
74
  end
58
75
 
59
76
  end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "3.0.0.rc5"
3
+ VERSION = "3.0.0.rc6"
4
4
  end
5
5
  end
@@ -20,21 +20,23 @@ module Ddr::Index
20
20
  }
21
21
 
22
22
  specify {
23
- expect(subject["dc_title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
24
- expect(subject["dc_identifier"]).to contain_exactly("test1", "test2", nil)
25
- expect(subject["dc_description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
26
- expect(subject["dc_creator"]).to contain_exactly(nil, nil, nil)
27
- expect(subject.to_s).to match(/dc_creator/)
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["dc_title"]).to contain_exactly("Testing 1", "Testing 2", "Testing 3")
34
- expect(subject["dc_identifier"]).to contain_exactly("test1", "test2", nil)
35
- expect(subject["dc_description"]).to contain_exactly("The process of eliminating errors.", nil, nil)
36
- expect(subject["dc_creator"]).to contain_exactly(nil, nil, nil)
37
- expect(subject.to_s).not_to match(/dc_creator/)
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.rc5
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-10 00:00:00.000000000 Z
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