diff --git a/lib/collectionspace/mapper/data_prepper.rb b/lib/collectionspace/mapper/data_prepper.rb index c346d887..d027aa18 100644 --- a/lib/collectionspace/mapper/data_prepper.rb +++ b/lib/collectionspace/mapper/data_prepper.rb @@ -226,7 +226,7 @@ def do_term_handling(xpath) data: data, handler: handler, response: response - ) + ).call end end diff --git a/lib/collectionspace/mapper/date_details/data_prepper.rb b/lib/collectionspace/mapper/date_details/data_prepper.rb index 9afe433e..2800fb23 100644 --- a/lib/collectionspace/mapper/date_details/data_prepper.rb +++ b/lib/collectionspace/mapper/date_details/data_prepper.rb @@ -136,7 +136,7 @@ def handle_term_fields data: data, handler: handler, response: response - ) + ).call end end diff --git a/lib/collectionspace/mapper/term_handler.rb b/lib/collectionspace/mapper/term_handler.rb index 88c953c2..590d7281 100644 --- a/lib/collectionspace/mapper/term_handler.rb +++ b/lib/collectionspace/mapper/term_handler.rb @@ -5,6 +5,21 @@ module Mapper class TermHandler include TermSearchable + class << self + # @param mapping [CollectionSpace::Mapper::ColumnMapping] + # @param data [Array] + # @param handler [CollectionSpace::Mapper::DataHandler] + # @param response [CollectionSpace::Mapper::Response] + def call(mapping:, data:, handler:, response:) + new( + mapping: mapping, + data: data, + handler: handler, + response: response + ).call + end + end + # @param mapping [CollectionSpace::Mapper::ColumnMapping] # @param data [Array] # @param handler [CollectionSpace::Mapper::DataHandler] @@ -14,26 +29,39 @@ def initialize(mapping:, data:, handler:, response:) @data = data @handler = handler @response = response + end - @column = mapping.datacolumn - @field = mapping.fieldname - @source_type = mapping.source_type.to_sym - case @source_type - when :authority - authconfig = mapping.transforms[:authority] - @type = authconfig[0] - @subtype = authconfig[1] - when :vocabulary - @type = "vocabularies" - @subtype = mapping.transforms[:vocabulary] - end + def call response.transformed_data[column] = handle_terms end private - attr_reader :mapping, :data, :handler, :response, :column, :source_type, - :type, :subtype + attr_reader :mapping, :data, :handler, :response + + def column = @column ||= mapping.datacolumn + + # def field = @field ||= mapping.fieldname + + def source_type = @source_type ||= mapping.source_type.to_sym + + def type + return @type if instance_variable_defined?(:@type) + + case @source_type + when :authority then mapping.transforms[:authority][0] + when :vocabulary then "vocabularies" + end + end + + def subtype + return @subtype if instance_variable_defined?(:@subtype) + + case @source_type + when :authority then mapping.transforms[:authority][1] + when :vocabulary then mapping.transforms[:vocabulary] + end + end def handle_terms if data.first.is_a?(String) diff --git a/spec/collectionspace/mapper/term_handler_spec.rb b/spec/collectionspace/mapper/term_handler_spec.rb index 235383ef..52550e04 100644 --- a/spec/collectionspace/mapper/term_handler_spec.rb +++ b/spec/collectionspace/mapper/term_handler_spec.rb @@ -9,7 +9,7 @@ data: data, handler: handler, response: response - ) + ).call end let(:handler) do @@ -119,7 +119,7 @@ data: data, handler: handler, response: new_resp - ) + ).call chk = new_resp.terms.select { |h| !h.found? } expect(chk.length).to eq(1)