Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ https://github.com/lyrasis/kiba-extend/pull/252[PR#252]
https://github.com/lyrasis/kiba-extend/pull/255[PR#255]
* :recursive_nuke option to `:pre_job_task_action` setting
https://github.com/lyrasis/kiba-extend/pull/258[PR#258]
* [FCAR chute functionality](https://lyrasis.github.io/kiba-extend/file.fcar_chute.html)
* https://lyrasis.github.io/kiba-extend/file.fcar_chute.html[FCAR chute functionality]
https://github.com/lyrasis/kiba-extend/pull/259[PR#259]
* [`Replace::GlobalReversible` transform](https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Replace/GlobalReversible.html)
* https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Replace/GlobalReversible.html[`Replace::GlobalReversible` transform]
https://github.com/lyrasis/kiba-extend/pull/260[PR#260]
* [`Replace::GlobalReverse` transform](https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Replace/GlobalReverse.html)
* https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Replace/GlobalReverse.html[`Replace::GlobalReverse` transform]
https://github.com/lyrasis/kiba-extend/pull/260[PR#260]
* Add handling of `omit_from_all_fields` param to [`Allable` transform mixin](https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Allable.html)
* Add handling of `omit_from_all_fields` param to https://lyrasis.github.io/kiba-extend/Kiba/Extend/Transforms/Allable.html[`Allable` transform mixin] and all transforms that use it
https://github.com/lyrasis/kiba-extend/pull/260[PR#260]

=== Bugfixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,17 @@ class RegexpFindReplaceFieldVals
# @param debug [Boolean] if true, will put replacement value in a new
# field. New field name is same as old field name, with "_repl"
# suffix added
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(fields:, find:, replace:, casesensitive: true,
multival: omitted = true, sep: nil, delim: nil,
debug: false)
debug: false, omit_from_all_fields: [])
@fields = [fields].flatten
@find = build_pattern(find, casesensitive)
@replace = replace
@debug = debug
@omit_from_all_fields = omit_from_all_fields
@mv = if omitted && delim
true
else
Expand Down
8 changes: 6 additions & 2 deletions lib/kiba/extend/transforms/clean/strip_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ module Clean
class StripFields
include Allable

# @param fields [Array<Symbol>,Symbol,:all, nil] in which to
# @param fields [Array<Symbol>,Symbol,:all] in which to
# strip values
# @param delim [nil,String] if given, switches to multivalue mode, in
# which each value in a multivalued string is stripped
def initialize(fields:, delim: nil)
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(fields:, delim: nil, omit_from_all_fields: [])
@fields = [fields].flatten
@delim = delim
@omit_from_all_fields = omit_from_all_fields
end

# @param row [Hash{ Symbol => String, nil }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ module CombineValues
class FromFieldsWithDelimiter
include Allable # since 4.0.0

# @param sources [Array<Symbol>, :all] Fields whose values are to be
# combined
# @param sources [Array<Symbol>, Symbol, :all] Fields whose values are
# to be combined
# @param target [Symbol] Field into which the combined value will be
# written. May be one of the source fields
# @param delim [String] Value used to separate individual field values
Expand All @@ -184,16 +184,20 @@ class FromFieldsWithDelimiter
# values for deduplication. Can be omitted if this is the same as
# `delim` value, as that will also be applied AFTER this value by
# default.
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(sources: :all, target: :index, delim: " ",
prepend_source_field_name: false, delete_sources: true,
deduplicate: false, dedupe_delim: nil)
deduplicate: false, dedupe_delim: nil, omit_from_all_fields: [])
@fields = [sources].flatten
@target = target
@delim = delim
@del = delete_sources
@prepend = prepend_source_field_name
@deduplicate = deduplicate
@dedupe_delim = dedupe_delim
@omit_from_all_fields = omit_from_all_fields

if prepend && deduplicate
raise Kiba::Extend::UnsafeParameterComboError,
Expand Down
23 changes: 15 additions & 8 deletions lib/kiba/extend/transforms/delete/delimiter_only_field_values.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

# rubocop:todo Layout/LineLength

module Kiba
module Extend
module Transforms
module Delete
# rubocop:todo Layout/LineLength

# @since 2.9.0
#
# Converts any value in given field(s) to nil if that value is `empty?`, or consists only
Expand Down Expand Up @@ -112,20 +112,28 @@ module Delete
# ]
# ~~~
class DelimiterOnlyFieldValues
# rubocop:enable Layout/LineLength

include Allable

# @param fields [:all, Symbol, Array(Symbol)] in which to delete delimiter-only-values. See
# {Transforms} for more on fields parameter.
# @param fields [:all, Symbol, Array(Symbol)] in which to delete
# delimiter-only-values. See {Transforms} for more on fields
# parameter.
# @param delim [String]
# @param treat_as_null [nil, String, Array(String)] values to treat as though they were null in
# determining whether to delete the field value or not
# @param treat_as_null [nil, String, Array(String)] values to treat as
# though they were null in determining whether to delete the field
# value or not
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(fields: :all, delim: Kiba::Extend.delim,
treat_as_null: nil)
treat_as_null: nil, omit_from_all_fields: [])
@fields = [fields].flatten
@delim = delim
@treat_as_null = treat_as_null
@checker = Helpers::DelimOnlyChecker.new(delim: delim,
treat_as_null: treat_as_null)
@omit_from_all_fields = omit_from_all_fields
end

# @param row [Hash{ Symbol => String, nil }]
Expand All @@ -152,4 +160,3 @@ def process_fields(row)
end
end
end
# rubocop:enable Layout/LineLength
7 changes: 6 additions & 1 deletion lib/kiba/extend/transforms/delete/empty_field_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ class EmptyFieldValues
# to `Kiba::Extend.delim` if not provided.
# @param usenull [Boolean] whether to treat `Kiba::Extend.nullvalue`
# string as an empty value
def initialize(fields:, sep: nil, delim: nil, usenull: false)
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(fields:, sep: nil, delim: nil, usenull: false,
omit_from_all_fields: [])
@fields = [fields].flatten
@usenull = usenull
@omit_from_all_fields = omit_from_all_fields
if sep && delim
puts "#{Kiba::Extend.warning_label}: Do not use both `sep` "\
"and `delim`. Prefer `delim`"
Expand Down
19 changes: 11 additions & 8 deletions lib/kiba/extend/transforms/filter_rows/all_fields_populated.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# frozen_string_literal: true

# rubocop:todo Layout/LineLength

module Kiba
module Extend
module Transforms
module FilterRows
# @since 2.9.0
#
# Keep or reject rows based on whether all of the given fields are populated. Blank strings and nils count as
# not populated.
# Keep or reject rows based on whether all of the given fields are
# populated. Blank strings and nils count as not populated.
#
# ## Examples
#
Expand All @@ -26,7 +24,8 @@ module FilterRows
# Used in pipeline as:
#
# ~~~
# transform FilterRows::AllFieldsPopulated, action: :keep, fields: %i[a b]
# transform FilterRows::AllFieldsPopulated,
# action: :keep, fields: %i[a b]
# ~~~
#
# Resulting data:
Expand All @@ -51,7 +50,8 @@ module FilterRows
# Used in pipeline as:
#
# ~~~
# transform FilterRows::AllFieldsPopulated, action: :reject, fields: %i[a b]
# transform FilterRows::AllFieldsPopulated,
# action: :reject, fields: %i[a b]
# ~~~
#
# Resulting data:
Expand All @@ -67,10 +67,14 @@ class AllFieldsPopulated

# @param action [:keep, :reject] what to do with row matching criteria
# @param fields [Array<Symbol>, :all] to check populated status in
def initialize(action:, fields:)
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(action:, fields:, omit_from_all_fields: [])
validate_action_argument(action)
@action = action
@fields = [fields].flatten
@omit_from_all_fields = omit_from_all_fields
end

# @param row [Hash{ Symbol => String, nil }]
Expand Down Expand Up @@ -101,4 +105,3 @@ def all_populated?(row)
end
end
end
# rubocop:enable Layout/LineLength
19 changes: 11 additions & 8 deletions lib/kiba/extend/transforms/filter_rows/any_fields_populated.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# frozen_string_literal: true

# rubocop:todo Layout/LineLength

module Kiba
module Extend
module Transforms
module FilterRows
# @since 2.9.0
#
# Keep or reject rows based on whether any of the given fields is populated. Blank strings and nils count as
# not populated.
# Keep or reject rows based on whether any of the given fields is
# populated. Blank strings and nils count as not populated.
#
# ## Examples
#
Expand All @@ -26,7 +24,8 @@ module FilterRows
# Used in pipeline as:
#
# ~~~
# transform FilterRows::AnyFieldsPopulated, action: :keep, fields: %i[a b]
# transform FilterRows::AnyFieldsPopulated,
# action: :keep, fields: %i[a b]
# ~~~
#
# Resulting data:
Expand Down Expand Up @@ -55,7 +54,8 @@ module FilterRows
# Used in pipeline as:
#
# ~~~
# transform FilterRows::AnyFieldsPopulated, action: :reject, fields: %i[a b]
# transform FilterRows::AnyFieldsPopulated,
# action: :reject, fields: %i[a b]
# ~~~
#
# Resulting data:
Expand All @@ -70,10 +70,14 @@ class AnyFieldsPopulated

# @param action [:keep, :reject] what to do with row matching criteria
# @param fields [Array<Symbol>, :all] to check populated status in
def initialize(action:, fields:)
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields; does nothing if individual field values
# are passed in
def initialize(action:, fields:, omit_from_all_fields: [])
validate_action_argument(action)
@action = action
@fields = [fields].flatten
@omit_from_all_fields = omit_from_all_fields
end

# @param row [Hash{ Symbol => String, nil }]
Expand Down Expand Up @@ -104,4 +108,3 @@ def any_populated?(row)
end
end
end
# rubocop:enable Layout/LineLength
6 changes: 5 additions & 1 deletion lib/kiba/extend/transforms/replace/global_reverse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ module Replace
# expect(result).to eq(expected)
# Kiba::Extend::ProjectConfig.reset_config
class GlobalReverse
def initialize
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields
def initialize(omit_from_all_fields: [])
@omit_from_all_fields = omit_from_all_fields
@replacers =
Kiba::Extend::ProjectConfig.global_reversible_replacements
.values
.reject { |config| config[:replace] == config[:reversed] }
.map do |config|
Clean::RegexpFindReplaceFieldVals.new(
fields: :all,
omit_from_all_fields: omit_from_all_fields,
find: Regexp.new(config[:replace]),
replace: config[:reversed]
)
Expand Down
6 changes: 5 additions & 1 deletion lib/kiba/extend/transforms/replace/global_reversible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ module Replace
# expect(result).to eq(expected)
# Kiba::Extend::ProjectConfig.reset_config
class GlobalReversible
def initialize
# @param omit_from_all_fields [Array<Symbol>] fields to omit from
# inclusion in "all" fields
def initialize(omit_from_all_fields: [])
@omit_from_all_fields = omit_from_all_fields
@replacers =
Kiba::Extend::ProjectConfig.global_reversible_replacements
.map do |pattern, config|
Clean::RegexpFindReplaceFieldVals.new(
fields: :all,
omit_from_all_fields: omit_from_all_fields,
find: pattern,
replace: config[:replace]
)
Expand Down
Loading