traject_plus 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -2
- data/README.md +1 -0
- data/lib/traject_plus/extraction.rb +16 -0
- data/lib/traject_plus/indexer/step.rb +2 -0
- data/lib/traject_plus/macros/csv.rb +1 -0
- data/lib/traject_plus/macros.rb +3 -2
- data/lib/traject_plus/version.rb +1 -1
- data/traject_plus.gemspec +3 -1
- metadata +33 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 586e90e7cb12df2dce7019884f218d1438a0493f4a982da874b0a566f163fb15
|
4
|
+
data.tar.gz: 1a54f1a1f29fba7669f746266861687836678d376348f796d8442799ec2f8e0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a72f9d3fab511ca29b2f01995bfca990953c2b28ba3bc9d33a09bc56c2c769c7f665c95776720c51c38278fc781d1beefeba00f21e35009ca442fb7f3e79e44e
|
7
|
+
data.tar.gz: ca6c5f9ab9e060c9883c66f75d061877279cc13288b4832faed6779cf36b107e96e537a36c6a7bafd2f57a605ce3395af49087102487cde446ad56cc2d95e22d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'deprecation'
|
5
|
+
|
4
6
|
module TrajectPlus
|
5
7
|
module Extraction
|
6
8
|
def self.apply_extraction_options(result, options = {})
|
@@ -9,6 +11,8 @@ module TrajectPlus
|
|
9
11
|
|
10
12
|
# Pipeline for transforming extracted values into normalized values
|
11
13
|
class TransformPipeline
|
14
|
+
extend Deprecation
|
15
|
+
|
12
16
|
attr_reader :options
|
13
17
|
|
14
18
|
def initialize(options)
|
@@ -53,6 +57,13 @@ module TrajectPlus
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
# to_field 'x', append: '321' # 'abc' to 'abc321'
|
61
|
+
def append(values, append_string)
|
62
|
+
values.flat_map do |v|
|
63
|
+
"#{v}#{append_string}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
56
67
|
# to_field 'x', match: [/([aeiou])/, 1] # 'abc' => 'a'
|
57
68
|
def match(values, match, index)
|
58
69
|
values.flat_map do |v|
|
@@ -112,6 +123,11 @@ module TrajectPlus
|
|
112
123
|
default_value
|
113
124
|
end
|
114
125
|
end
|
126
|
+
|
127
|
+
alias replace gsub
|
128
|
+
deprecation_deprecate replace: "use gsub instead"
|
129
|
+
alias trim strip
|
130
|
+
deprecation_deprecate trim: "use strip instead"
|
115
131
|
end
|
116
132
|
end
|
117
133
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module TrajectPlus
|
2
2
|
module Indexer
|
3
3
|
class ToFieldStep < Traject::Indexer::ToFieldStep
|
4
|
+
# @param single [Bool] if true, this outputs a scalar value (rather than an Array)
|
5
|
+
# by default Traject only outputs arrays.
|
4
6
|
def initialize(fieldname, procs, block, source_location, single: false)
|
5
7
|
super(fieldname, procs, block, source_location)
|
6
8
|
|
@@ -4,6 +4,7 @@ module TrajectPlus
|
|
4
4
|
module Macros
|
5
5
|
# Macros for extracting values from CSV rows
|
6
6
|
module Csv
|
7
|
+
# Retrieve the value of the column with the given header or index.
|
7
8
|
# @param header_or_index [String] the field header or index to accumulate
|
8
9
|
def column(header_or_index, options = {})
|
9
10
|
lambda do |row, accumulator, _context|
|
data/lib/traject_plus/macros.rb
CHANGED
@@ -62,8 +62,9 @@ module TrajectPlus
|
|
62
62
|
fields.each { |field| to_field field, mapping_method }
|
63
63
|
end
|
64
64
|
|
65
|
-
def to_field(field_name,
|
66
|
-
|
65
|
+
def to_field(field_name, *procs, extract: nil, transform: nil, **namedArgs, &block)
|
66
|
+
procs = [extract, transform] if procs.empty?
|
67
|
+
@index_steps << TrajectPlus::Indexer::ToFieldStep.new(field_name, procs, block, Traject::Util.extract_caller_location(caller.first), **namedArgs)
|
67
68
|
end
|
68
69
|
|
69
70
|
def compose(fieldname = nil, aLambda = nil, extract: nil, transform: nil, &block)
|
data/lib/traject_plus/version.rb
CHANGED
data/traject_plus.gemspec
CHANGED
@@ -23,8 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'activesupport'
|
24
24
|
spec.add_dependency 'jsonpath'
|
25
25
|
spec.add_dependency 'traject', '~> 3.0'
|
26
|
+
spec.add_dependency 'deprecation'
|
26
27
|
|
27
|
-
spec.add_development_dependency "bundler",
|
28
|
+
spec.add_development_dependency "bundler", '>= 1.15'
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency 'byebug'
|
30
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traject_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -55,18 +55,32 @@ dependencies:
|
|
55
55
|
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '3.0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: deprecation
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
58
72
|
- !ruby/object:Gem::Dependency
|
59
73
|
name: bundler
|
60
74
|
requirement: !ruby/object:Gem::Requirement
|
61
75
|
requirements:
|
62
|
-
- - "
|
76
|
+
- - ">="
|
63
77
|
- !ruby/object:Gem::Version
|
64
78
|
version: '1.15'
|
65
79
|
type: :development
|
66
80
|
prerelease: false
|
67
81
|
version_requirements: !ruby/object:Gem::Requirement
|
68
82
|
requirements:
|
69
|
-
- - "
|
83
|
+
- - ">="
|
70
84
|
- !ruby/object:Gem::Version
|
71
85
|
version: '1.15'
|
72
86
|
- !ruby/object:Gem::Dependency
|
@@ -97,6 +111,20 @@ dependencies:
|
|
97
111
|
- - "~>"
|
98
112
|
- !ruby/object:Gem::Version
|
99
113
|
version: '3.0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: byebug
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
100
128
|
description: Extensions to Traject for non-MARC formats
|
101
129
|
email:
|
102
130
|
- cabeer@stanford.edu
|
@@ -151,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
179
|
version: '0'
|
152
180
|
requirements: []
|
153
181
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.6
|
182
|
+
rubygems_version: 2.7.6
|
155
183
|
signing_key:
|
156
184
|
specification_version: 4
|
157
185
|
summary: Extensions to Traject for non-MARC formats
|