lib/traject_plus/extraction.rb in traject_plus-0.1.0 vs lib/traject_plus/extraction.rb in traject_plus-1.0.0
- old
+ new
@@ -1,16 +1,20 @@
# frozen_string_literal: true
require 'active_support/core_ext/object/blank'
+require 'deprecation'
+
module TrajectPlus
module Extraction
def self.apply_extraction_options(result, options = {})
TransformPipeline.new(options).transform(result)
end
# Pipeline for transforming extracted values into normalized values
class TransformPipeline
+ extend Deprecation
+
attr_reader :options
def initialize(options)
@options = options
end
@@ -51,10 +55,17 @@
define_method(method) do |values, *args|
values.map(&(method.to_sym))
end
end
+ # to_field 'x', append: '321' # 'abc' to 'abc321'
+ def append(values, append_string)
+ values.flat_map do |v|
+ "#{v}#{append_string}"
+ end
+ end
+
# to_field 'x', match: [/([aeiou])/, 1] # 'abc' => 'a'
def match(values, match, index)
values.flat_map do |v|
v.match(match) do |m|
m[index]
@@ -110,8 +121,13 @@
values
else
default_value
end
end
+
+ alias replace gsub
+ deprecation_deprecate replace: "use gsub instead"
+ alias trim strip
+ deprecation_deprecate trim: "use strip instead"
end
end
end