From fab88330fd2f5f8cc6a5dda5de4043444a557280 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Thu, 20 Jan 2022 17:55:37 -0500 Subject: [PATCH] rubocopping --- Gemfile | 2 +- collectionspace-mapper.gemspec | 8 +- doc/batch_configuration.adoc | 17 -- lib/collectionspace/mapper.rb | 2 +- .../mapper/authority_hierarchy_prepper.rb | 4 +- .../mapper/authority_transformer.rb | 5 +- .../mapper/behrensmeyer_transformer.rb | 4 +- .../mapper/boolean_transformer.rb | 1 - lib/collectionspace/mapper/column_mapping.rb | 1 + lib/collectionspace/mapper/column_mappings.rb | 1 + lib/collectionspace/mapper/column_value.rb | 1 - lib/collectionspace/mapper/config.rb | 28 ++- lib/collectionspace/mapper/data_handler.rb | 29 +-- lib/collectionspace/mapper/data_mapper.rb | 42 ++-- lib/collectionspace/mapper/data_prepper.rb | 71 +++---- .../mapper/data_quality_checker.rb | 2 +- lib/collectionspace/mapper/data_splitter.rb | 1 + lib/collectionspace/mapper/data_validator.rb | 8 +- .../mapper/date_stamp_transformer.rb | 4 +- .../mapper/downcase_transformer.rb | 4 +- .../mapper/find_replace_operation.rb | 3 +- .../mapper/find_replace_transformer.rb | 1 - .../mapper/group_column_value.rb | 1 - .../mapper/group_multival_column_value.rb | 1 - .../identifiers/authority_short_identifier.rb | 2 - .../mapper/identifiers/short_identifier.rb | 2 - .../mapper/multival_column_value.rb | 1 - .../non_hierarchical_relationship_prepper.rb | 4 +- .../mapper/object_hierarchy_data_prepper.rb | 4 +- lib/collectionspace/mapper/record_mapper.rb | 1 - .../mapper/regex_find_replace_operation.rb | 1 - lib/collectionspace/mapper/response.rb | 2 +- lib/collectionspace/mapper/row_data.rb | 2 +- lib/collectionspace/mapper/row_fields.rb | 3 +- .../mapper/structured_date_transformer.rb | 4 +- .../mapper/subgroup_column_value.rb | 1 - lib/collectionspace/mapper/term_handler.rb | 27 ++- lib/collectionspace/mapper/term_searchable.rb | 25 ++- lib/collectionspace/mapper/tools/dates.rb | 46 +++-- .../mapper/tools/record_status_service.rb | 19 +- lib/collectionspace/mapper/tools/refname.rb | 13 +- .../mapper/tools/symbolizable.rb | 3 +- lib/collectionspace/mapper/transformer.rb | 8 +- lib/collectionspace/mapper/transformers.rb | 1 - .../mapper/value_transformer.rb | 2 +- .../mapper/vocabulary_transformer.rb | 5 +- lib/collectionspace/mapper/xml_template.rb | 1 - spec/anthro_helpers.rb | 2 +- spec/bonsai_helpers.rb | 2 +- spec/botgarden_helpers.rb | 2 +- .../mapper/column_mapping_spec.rb | 8 +- .../mapper/column_mappings_spec.rb | 183 +++++++++--------- .../mapper/column_value_spec.rb | 23 ++- spec/collectionspace/mapper/config_spec.rb | 10 +- .../mapper/data_handler_spec.rb | 46 ++--- .../mapper/data_mapper_core_spec.rb | 34 ++-- .../mapper/data_mapper_spec.rb | 5 +- .../mapper/data_prepper_spec.rb | 18 +- .../mapper/data_quality_checker_spec.rb | 68 ++++--- .../mapper/data_splitter_spec.rb | 54 +++--- .../mapper/data_validator_spec.rb | 14 +- .../mapper/find_replace_operation_spec.rb | 5 +- .../mapper/find_replace_transformer_spec.rb | 11 +- .../mapper/group_column_value_spec.rb | 21 +- .../group_multival_column_value_spec.rb | 21 +- .../identifiers/short_identifier_spec.rb | 1 - .../mapper/multival_column_value_spec.rb | 21 +- .../mapper/record_mapper_config_spec.rb | 20 +- .../regex_find_replace_operation_spec.rb | 3 +- spec/collectionspace/mapper/row_data_spec.rb | 18 +- .../mapper/subgroup_column_value_spec.rb | 21 +- .../mapper/term_handler_spec.rb | 86 ++++---- .../mapper/term_searchable_spec.rb | 4 +- .../tools/record_status_service_spec.rb | 46 +++-- .../mapper/tools/refname_spec.rb | 7 +- .../mapper/tools/symbolizable_spec.rb | 13 +- .../mapper/transformer_spec.rb | 22 ++- .../mapper/transformers_spec.rb | 18 +- .../mapper/value_transformer_spec.rb | 24 +-- spec/collectionspace/mapper_spec.rb | 11 +- spec/core_helpers.rb | 4 +- spec/fcart_helpers.rb | 4 +- spec/helpers.rb | 15 +- spec/lhmc_helpers.rb | 2 +- utils/benchmarking/profile.rb | 4 +- utils/csv-to-datahashes.rb | 4 +- utils/datahash_to_csv.rb | 4 +- 87 files changed, 649 insertions(+), 648 deletions(-) diff --git a/Gemfile b/Gemfile index 3ac88b98..30e6525f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true source 'https://rubygems.org' -git_source(:github){|repo_name| "https://github.com/#{repo_name}" } +git_source(:github){ |repo_name| "https://github.com/#{repo_name}" } ruby '2.7.4' diff --git a/collectionspace-mapper.gemspec b/collectionspace-mapper.gemspec index 1c143924..6d0eed94 100644 --- a/collectionspace-mapper.gemspec +++ b/collectionspace-mapper.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'collectionspace/mapper/version' @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.authors = ['Kristina Spurgin'] spec.email = ['kristina.spurgin@lyrasis.org'] - spec.summary = %q{Generic mapper turns hash of data into CollectionSpace XML} + spec.summary = 'Generic mapper turns hash of data into CollectionSpace XML' spec.homepage = 'https://github.com/lyrasis/collectionspace-mapper' spec.license = 'MIT' @@ -26,12 +26,12 @@ Gem::Specification.new do |spec| spec.metadata['changelog_uri'] = 'https://github.com/lyrasis/collectionspace-mapper' else raise 'RubyGems 2.0 or newer is required to protect against ' \ - 'public gem pushes.' + 'public gem pushes.' end # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject{ |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = 'exe' diff --git a/doc/batch_configuration.adoc b/doc/batch_configuration.adoc index 283ba3d9..f9acdbf3 100644 --- a/doc/batch_configuration.adoc +++ b/doc/batch_configuration.adoc @@ -24,7 +24,6 @@ A JSON config hash may be passed to a new `Mapper::DataHandler` to control vario "response_mode": "verbose", "strip_id_values": true, "multiple_recs_found": "fail", - "check_terms" : true, "check_record_status" : true, "force_defaults": false, "date_format": "month day year", @@ -118,22 +117,6 @@ While it is possible to use this setting to batch update existing records that d - *Data type*: string - *Allowed values*: `fail`, `use_first` -== check_terms - -If `true`, looks up each term via `collectionspace-refcache`. If found, uses existing refname. If not found, searches for term via cspace-services API and uses existing refname if found. If term not found in refcache or services API, builds a new refname, uses that in the record, adds it to refcache, and returns the term with `found=false` in `Response::Terms`. - -If `false`, never searches services API for the term. Uses refcache refname if it exists, otherwise builds a new refname and adds it to refcache. Returns all terms with `found=false` in `Response::Terms`. - -[NOTE] -==== -Set this to false only if you are certain no terms from your data exist in CollectionSpace, and all of the terms need to be created as new. Otherwise, you may end up with duplicate terms being added to CollectionSpace, due to the fact that `collectionspace-mapper` does not generate exactly the same hashed short identifier value for use in the refname as the CollectionSpace application does. -==== - -- *Required?:* yes -- *Defaults to:* true -- *Data type*: boolean -- *Allowed values*: `true`, `false` - == check_record_status If `true`, looks up each record via cspace-services API and sets `Response.record_status` to `:exists` if the record is found, or `:new` if it is not. diff --git a/lib/collectionspace/mapper.rb b/lib/collectionspace/mapper.rb index 98a9077a..befe90d4 100644 --- a/lib/collectionspace/mapper.rb +++ b/lib/collectionspace/mapper.rb @@ -36,6 +36,7 @@ module Errors class UnprocessableDataError < StandardError UnprocessableDataError = CollectionSpace::Mapper::Errors::UnprocessableDataError attr_reader :input + def initialize(message, input) super(message) @input = input @@ -76,6 +77,5 @@ def merge_default_values(data, batchconfig) def term_key(term) "#{term[:refname].type}-#{term[:refname].subtype}-#{term[:refname].display_name}" end - end end diff --git a/lib/collectionspace/mapper/authority_hierarchy_prepper.rb b/lib/collectionspace/mapper/authority_hierarchy_prepper.rb index a52218ed..9086ffa0 100644 --- a/lib/collectionspace/mapper/authority_hierarchy_prepper.rb +++ b/lib/collectionspace/mapper/authority_hierarchy_prepper.rb @@ -54,9 +54,7 @@ def transform_terms end @response.split_data.each do |field, value| - unless @response.transformed_data.key?(field) - @response.transformed_data[field] = value - end + @response.transformed_data[field] = value unless @response.transformed_data.key?(field) end end diff --git a/lib/collectionspace/mapper/authority_transformer.rb b/lib/collectionspace/mapper/authority_transformer.rb index c8587d46..82572423 100644 --- a/lib/collectionspace/mapper/authority_transformer.rb +++ b/lib/collectionspace/mapper/authority_transformer.rb @@ -4,10 +4,8 @@ module CollectionSpace module Mapper - # transforms authority display name into RefName class AuthorityTransformer < Transformer - def initialize(opts) super @type = opts[:transform][0] @@ -16,8 +14,7 @@ def initialize(opts) @csclient = opts[:recmapper].csclient end - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/behrensmeyer_transformer.rb b/lib/collectionspace/mapper/behrensmeyer_transformer.rb index 7c9e026a..ac3b4257 100644 --- a/lib/collectionspace/mapper/behrensmeyer_transformer.rb +++ b/lib/collectionspace/mapper/behrensmeyer_transformer.rb @@ -4,11 +4,9 @@ module CollectionSpace module Mapper - # transforms digit into full Behrensmeyer scale vocabulary term class BehrensmeyerTransformer < Transformer - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/boolean_transformer.rb b/lib/collectionspace/mapper/boolean_transformer.rb index 6623b5fb..ad407162 100644 --- a/lib/collectionspace/mapper/boolean_transformer.rb +++ b/lib/collectionspace/mapper/boolean_transformer.rb @@ -4,7 +4,6 @@ module CollectionSpace module Mapper - # transforms a variety of binary values into Boolean string values for CS class BooleanTransformer < Transformer def transform(value) diff --git a/lib/collectionspace/mapper/column_mapping.rb b/lib/collectionspace/mapper/column_mapping.rb index 55066239..3c5768de 100644 --- a/lib/collectionspace/mapper/column_mapping.rb +++ b/lib/collectionspace/mapper/column_mapping.rb @@ -10,6 +10,7 @@ module Mapper class ColumnMapping attr_reader :recmapper, :data_type, :fieldname, :in_repeating_group, :is_group, :namespace, :opt_list_values, :repeats, :source_type, :transforms, :xpath + def initialize(mapping_hash, recmapper) @recmapper = recmapper mapping_hash.each do |key, value| diff --git a/lib/collectionspace/mapper/column_mappings.rb b/lib/collectionspace/mapper/column_mappings.rb index 7b6f4ce2..d44f1a4c 100644 --- a/lib/collectionspace/mapper/column_mappings.rb +++ b/lib/collectionspace/mapper/column_mappings.rb @@ -10,6 +10,7 @@ class ColumnMappings extend Forwardable attr_reader :config + def_delegators :@all, :each, :length, :map, :reject!, :select def initialize(opts = {}) diff --git a/lib/collectionspace/mapper/column_value.rb b/lib/collectionspace/mapper/column_value.rb index 013cba6a..f14794fa 100644 --- a/lib/collectionspace/mapper/column_value.rb +++ b/lib/collectionspace/mapper/column_value.rb @@ -2,7 +2,6 @@ module CollectionSpace module Mapper - # represents a row of data from a CSV. class ColumnValue def initialize(column:, value:, recmapper:, mapping:) diff --git a/lib/collectionspace/mapper/config.rb b/lib/collectionspace/mapper/config.rb index 2c49dee0..15a95934 100644 --- a/lib/collectionspace/mapper/config.rb +++ b/lib/collectionspace/mapper/config.rb @@ -4,15 +4,15 @@ module CollectionSpace module Mapper - # This is the default config, which is modified for object or authority hierarchy, # or non-hierarchichal relationships via module extension # :reek:InstanceVariableAssumption - instance variables are set during initialization class Config attr_reader :delimiter, :subgroup_delimiter, :response_mode, :strip_id_values, :multiple_recs_found, :force_defaults, - :check_record_status, :check_terms, :date_format, :two_digit_year_handling, :transforms, :default_values, + :check_record_status, :date_format, :two_digit_year_handling, :transforms, :default_values, :record_type - # todo: move default config in here + + # TODO: move default config in here include Tools::Symbolizable DEFAULT_CONFIG = {delimiter: '|', @@ -20,21 +20,22 @@ class Config response_mode: 'normal', strip_id_values: true, multiple_recs_found: 'fail', - check_terms: true, check_record_status: true, force_defaults: false, date_format: 'month day year', - two_digit_year_handling: 'coerce' - } + two_digit_year_handling: 'coerce'} class ConfigKeyMissingError < StandardError attr_reader :keys + def initialize(message, keys) super(message) @keys = keys end end + class ConfigResponseModeError < StandardError; end + class UnhandledConfigFormatError < StandardError; end def initialize(opts = {}) @@ -57,7 +58,7 @@ def initialize(opts = {}) end def hash - config = self.to_h + config = to_h config = symbolize(config) transforms = config[:transforms] return config unless transforms @@ -97,13 +98,13 @@ def set_instance_variables(hash) def validate begin has_required_attributes - rescue ConfigKeyMissingError => err - err.keys.each{ |key| instance_variable_set("@#{key}", DEFAULT_CONFIG[key]) } + rescue ConfigKeyMissingError => e + e.keys.each{ |key| instance_variable_set("@#{key}", DEFAULT_CONFIG[key]) } end begin valid_response_mode - rescue ConfigResponseModeError => err + rescue ConfigResponseModeError => e replacement_value = DEFAULT_CONFIG[:response_mode] @response_mode = replacement_value end @@ -112,16 +113,14 @@ def validate def valid_response_mode valid = %w[normal verbose] unless valid.any?(@response_mode) - raise ConfigResponseModeError.new("Invalid response_mode value in config: #{@response_mode}") + raise ConfigResponseModeError, "Invalid response_mode value in config: #{@response_mode}" end end def has_required_attributes required_keys = DEFAULT_CONFIG.keys remaining_keys = required_keys - hash.keys - unless remaining_keys.empty? - raise ConfigKeyMissingError.new('Config missing key', remaining_keys) - end + raise ConfigKeyMissingError.new('Config missing key', remaining_keys) unless remaining_keys.empty? end def special_defaults @@ -130,4 +129,3 @@ def special_defaults end end end - diff --git a/lib/collectionspace/mapper/data_handler.rb b/lib/collectionspace/mapper/data_handler.rb index d4ee80ad..fbede43f 100644 --- a/lib/collectionspace/mapper/data_handler.rb +++ b/lib/collectionspace/mapper/data_handler.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # given a RecordMapper hash and a data hash, returns CollectionSpace XML document class DataHandler # this is an accessor rather than a reader until I refactor away the hideous @@ -32,7 +31,7 @@ def process(data) end def prep(data) - response = CollectionSpace::Mapper::setup_data(data, @mapper.batchconfig) + response = CollectionSpace::Mapper.setup_data(data, @mapper.batchconfig) if response.valid? case @mapper.record_type when 'authorityhierarchy' @@ -74,7 +73,7 @@ def service_type end def validate(data) - response = CollectionSpace::Mapper::setup_data(data, @mapper.batchconfig) + response = CollectionSpace::Mapper.setup_data(data, @mapper.batchconfig) validator.validate(response) end @@ -116,12 +115,12 @@ def xpath_hash # populate parent of all non-top xpaths h.each do |xpath, ph| - if xpath['/'] - keys = h.keys - [xpath] - keys = keys.select{ |k| xpath[k] } - keys = keys.sort{ |a, b| b.length <=> a.length } - ph[:parent] = keys[0] unless keys.empty? - end + next unless xpath['/'] + + keys = h.keys - [xpath] + keys = keys.select{ |k| xpath[k] } + keys = keys.sort{ |a, b| b.length <=> a.length } + ph[:parent] = keys[0] unless keys.empty? end # populate children @@ -145,13 +144,15 @@ def xpath_hash if v.size > 1 puts "WARNING: #{xpath} has fields with different :in_repeating_group values (#{v}). Defaulting to treating NOT as a group" end - ph[:is_group] = -true if ct == 1 && v == ['as part of larger repeating group'] && ph[:mappings][0].repeats == 'y' + if ct == 1 && v == ['as part of larger repeating group'] && ph[:mappings][0].repeats == 'y' + ph[:is_group] = + true + end end # populate is_subgroup subgroups = [] - h.each{ |k, v| subgroups << v[:subgroups] } + h.each{ |_k, v| subgroups << v[:subgroups] } subgroups = subgroups.flatten.uniq h.keys.each{ |k| h[k][:is_subgroup] = true if subgroups.include?(k) } h @@ -202,10 +203,10 @@ def tag_terms(result) return if terms.empty? terms.select{ |t| !t[:found] }.each do |term| - @new_terms[CollectionSpace::Mapper::term_key(term)] = nil + @new_terms[CollectionSpace::Mapper.term_key(term)] = nil end terms.select{ |t| t[:found] }.each do |term| - term[:found] = false if @new_terms.key?(CollectionSpace::Mapper::term_key(term)) + term[:found] = false if @new_terms.key?(CollectionSpace::Mapper.term_key(term)) end result.terms = terms diff --git a/lib/collectionspace/mapper/data_mapper.rb b/lib/collectionspace/mapper/data_mapper.rb index bdd81af9..f504b56d 100644 --- a/lib/collectionspace/mapper/data_mapper.rb +++ b/lib/collectionspace/mapper/data_mapper.rb @@ -5,6 +5,7 @@ module Mapper class DataMapper attr_reader :handler, :xphash attr_accessor :doc, :response + def initialize(response, handler, xphash) @response = response @handler = handler @@ -122,15 +123,16 @@ def populate_simple_field_data(field_name, data, parent) def populate_group_field_data(index, data, parent) data.each do |field, values| - if values[index] - child = Nokogiri::XML::Node.new(field, @doc) - if values[index].is_a?(Hash) - map_structured_date(child, values[index]) - else values[index] - child.content = values[index] - end - parent.add_child(child) + next unless values[index] + + child = Nokogiri::XML::Node.new(field, @doc) + if values[index].is_a?(Hash) + map_structured_date(child, values[index]) + else + values[index] + child.content = values[index] end + parent.add_child(child) end end @@ -177,7 +179,7 @@ def map_group(xpath, targetnode, thisdata) end def even_subgroup_field_values?(data) - data.values.map(&:flatten).map(&:length).uniq.length == 1 ? true : false + data.values.map(&:flatten).map(&:length).uniq.length == 1 end def add_uneven_subgroup_warning(parent_path:, intervening_path:, subgroup:) @@ -204,7 +206,7 @@ def add_too_many_subgroups_warning(parent_path:, intervening_path:, subgroup:) def group_accommodates_subgroup?(groupdata, subgroupdata) sg_max_length = subgroupdata.values.map(&:length).max - sg_max_length <= groupdata.length ? true : false + sg_max_length <= groupdata.length end # EXAMPLE: creates empty titleTranslationSubGroupList as a child of titleGroup @@ -222,7 +224,7 @@ def create_intermediate_subgroup_hierarchy(grp, subgroup_path) # returns the count of field values for the subgroup field with the mosty values # we need to know this in order to create enough empty subgroup elements to hold the data def maximum_subgroup_values(data) - data.map{ |field, values| subgroup_value_count(values) }.flatten.max + data.map{ |_field, values| subgroup_value_count(values) }.flatten.max end def subgroup_value_count(values) @@ -250,12 +252,16 @@ def map_subgroup(xphash, thisdata) groups[i] = {parent: p, data: {}} end - add_uneven_subgroup_warning(parent_path: parent_path, - intervening_path: subgroup_path, - subgroup: subgroup) unless even_subgroup_field_values?(thisdata) - add_too_many_subgroups_warning(parent_path: parent_path, - intervening_path: subgroup_path, - subgroup: subgroup) unless group_accommodates_subgroup?(groups, thisdata) + unless even_subgroup_field_values?(thisdata) + add_uneven_subgroup_warning(parent_path: parent_path, + intervening_path: subgroup_path, + subgroup: subgroup) + end + unless group_accommodates_subgroup?(groups, thisdata) + add_too_many_subgroups_warning(parent_path: parent_path, + intervening_path: subgroup_path, + subgroup: subgroup) + end thisdata.each{ |field, subgroups| assign_subgroup_values_to_group_hash_data(groups, field, subgroups) } @@ -263,7 +269,7 @@ def map_subgroup(xphash, thisdata) max_ct = maximum_subgroup_values(thisdata) - groups.each do |i, data| + groups.each do |i, _data| max_ct.times do target = @doc.xpath("//#{parent_path}/#{subgroup_path.join('/')}") target[i].add_child(Nokogiri::XML::Node.new(subgroup, @doc)) diff --git a/lib/collectionspace/mapper/data_prepper.rb b/lib/collectionspace/mapper/data_prepper.rb index cf2ab421..5cc3d7de 100644 --- a/lib/collectionspace/mapper/data_prepper.rb +++ b/lib/collectionspace/mapper/data_prepper.rb @@ -5,16 +5,15 @@ module Mapper class DataPrepper attr_reader :data, :handler, :config, :cache, :client attr_accessor :response, :xphash + def initialize(data, handler) @handler = handler @config = @handler.mapper.batchconfig @cache = @handler.mapper.termcache @client = @handler.mapper.csclient - @response = CollectionSpace::Mapper::setup_data(data, @config) + @response = CollectionSpace::Mapper.setup_data(data, @config) drop_empty_fields - if @response.valid? - process_xpaths - end + process_xpaths if @response.valid? end def prep @@ -29,12 +28,12 @@ def prep end def split_data - @xphash.each{ |xpath, hash| do_splits(hash) } + @xphash.each{ |_xpath, hash| do_splits(hash) } @response.split_data end def transform_data - @xphash.each{ |xpath, hash| do_transforms(hash) } + @xphash.each{ |_xpath, hash| do_transforms(hash) } @response.transformed_data end @@ -44,14 +43,14 @@ def transform_date_fields end def handle_term_fields - @xphash.each{ |xpath, hash| do_term_handling(hash) } + @xphash.each{ |_xpath, hash| do_term_handling(hash) } @response.warnings.flatten! @response.errors.flatten! @response.transformed_data end def check_data - @xphash.each{ |xpath, hash| check_data_quality(hash) } + @xphash.each{ |_xpath, hash| check_data_quality(hash) } @response.warnings.flatten! @response.warnings end @@ -76,7 +75,7 @@ def push_errors_and_warnings end def drop_empty_fields - @response.merged_data = @response.merged_data.delete_if{ |k, v| v.blank? } + @response.merged_data = @response.merged_data.delete_if{ |_k, v| v.blank? } end def process_xpaths @@ -89,7 +88,7 @@ def process_xpaths @xphash = mappings.map{ |mapper| mapper.fullpath }.uniq # hash with xpath as key and xpath info hash from DataHandler as value @xphash = @xphash.map{ |xpath| [xpath, @handler.mapper.xpath[xpath].clone] }.to_h - @xphash.each do |xpath, hash| + @xphash.each do |_xpath, hash| hash[:mappings] = hash[:mappings].select do |mapping| mapping.fieldname == 'shortIdentifier' || @response.merged_data.key?(mapping.datacolumn) end @@ -117,7 +116,7 @@ def do_non_group_splits(xphash) next if data.nil? || data.empty? @response.split_data[column] = non_group_splitter(mapping, data) - # mapping.repeats == 'y' ? CollectionSpace::Mapper::SimpleSplitter.new(data, config).result : [data.strip] + # mapping.repeats == 'y' ? CollectionSpace::Mapper::SimpleSplitter.new(data, config).result : [data.strip] end end @@ -162,17 +161,17 @@ def do_transforms(xphash) data = splitdata.fetch(column, nil) next if data.blank? - if mapping.transforms.blank? - targetdata[column] = data - else - targetdata[column] = data.map do |d| - if d.is_a?(String) - transform_value(d, mapping.transforms, column) - else - d.map{ |val| transform_value(val, mapping.transforms, column) } - end - end - end + targetdata[column] = if mapping.transforms.blank? + data + else + data.map do |d| + if d.is_a?(String) + transform_value(d, mapping.transforms, column) + else + d.map{ |val| transform_value(val, mapping.transforms, column) } + end + end + end end end @@ -189,7 +188,7 @@ def transform_value(value, transforms, column) vt.result end - def do_date_transforms(xpath, xphash) + def do_date_transforms(_xpath, xphash) sourcedata = @response.transformed_data xphash[:mappings].each do |mapping| @@ -242,8 +241,6 @@ def get_source_type(source_type_string) source_type_string.to_sym when 'vocabulary' source_type_string.to_sym - else - nil end end @@ -255,10 +252,12 @@ def structured_date_transform(data) @cache, @handler.mapper.batchconfig).mappable else - d.map do |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, - @client, - @cache, - @handler.mapper.batchconfig).mappable end + d.map do |v| + CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, + @client, + @cache, + @handler.mapper.batchconfig).mappable + end end end end @@ -271,10 +270,12 @@ def unstructured_date_transform(data) @cache, @handler.mapper.batchconfig).stamp else - d.map do |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, - @client, - @cache, - @handler.mapper.batchconfig).stamp end + d.map do |v| + CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, + @client, + @cache, + @handler.mapper.batchconfig).stamp + end end end end @@ -322,12 +323,12 @@ def combine_data_values(xpath, xphash) elsif chk.empty? next else - raise StandardError.new('Mixed class types in multi-authority field set') + raise StandardError, 'Mixed class types in multi-authority field set' end end end - @response.combined_data[xpath].select{ |fieldname, val| val.blank? }.keys.each do |fieldname| + @response.combined_data[xpath].select{ |_fieldname, val| val.blank? }.keys.each do |fieldname| @response.combined_data[xpath].delete(fieldname) unless fieldname == 'shortIdentifier' @xphash[xpath][:mappings].delete_if{ |mapping| mapping.fieldname == fieldname } diff --git a/lib/collectionspace/mapper/data_quality_checker.rb b/lib/collectionspace/mapper/data_quality_checker.rb index 43466a28..8e9dd0cc 100644 --- a/lib/collectionspace/mapper/data_quality_checker.rb +++ b/lib/collectionspace/mapper/data_quality_checker.rb @@ -4,6 +4,7 @@ module CollectionSpace module Mapper class DataQualityChecker attr_reader :mapping, :data, :warnings, :terms + def initialize(mapping, data) @mapping = mapping @column = mapping.datacolumn @@ -77,4 +78,3 @@ def check_opt_list_val(val) end end end - diff --git a/lib/collectionspace/mapper/data_splitter.rb b/lib/collectionspace/mapper/data_splitter.rb index 76dceac9..72477277 100644 --- a/lib/collectionspace/mapper/data_splitter.rb +++ b/lib/collectionspace/mapper/data_splitter.rb @@ -4,6 +4,7 @@ module CollectionSpace module Mapper class DataSplitter attr_reader :data, :result + def initialize(data, config) @data = data.strip @config = config diff --git a/lib/collectionspace/mapper/data_validator.rb b/lib/collectionspace/mapper/data_validator.rb index f6e46e76..869669f0 100644 --- a/lib/collectionspace/mapper/data_validator.rb +++ b/lib/collectionspace/mapper/data_validator.rb @@ -69,6 +69,7 @@ class DataValidator class IdFieldNotInMapperError < StandardError; end attr_reader :mapper, :cache, :required_fields + def initialize(record_mapper, cache) @mapper = record_mapper @cache = cache @@ -82,7 +83,7 @@ def initialize(record_mapper, cache) end def validate(data) - response = CollectionSpace::Mapper::setup_data(data) + response = CollectionSpace::Mapper.setup_data(data) if response.valid? data = response.merged_data.transform_keys!(&:downcase) res = check_required_fields(data) unless @required_fields.empty? @@ -118,11 +119,11 @@ def check_required_fields(data) @required_fields.each do |field, columns| if columns.length == 1 checkfield = SingleColumnRequiredField.new(field, columns) - errs << checkfield.missing_message if !checkfield.present_in?(data) + errs << checkfield.missing_message unless checkfield.present_in?(data) errs << checkfield.empty_message if checkfield.present_in?(data) && !checkfield.populated_in?(data) elsif columns.length > 1 checkfield = MultiColumnRequiredField.new(field, columns) - errs << checkfield.missing_message if !checkfield.present_in?(data) + errs << checkfield.missing_message unless checkfield.present_in?(data) errs << checkfield.empty_message if checkfield.present_in?(data) && !checkfield.populated_in?(data) end end @@ -131,4 +132,3 @@ def check_required_fields(data) end end end - diff --git a/lib/collectionspace/mapper/date_stamp_transformer.rb b/lib/collectionspace/mapper/date_stamp_transformer.rb index 39699d15..2a28def9 100644 --- a/lib/collectionspace/mapper/date_stamp_transformer.rb +++ b/lib/collectionspace/mapper/date_stamp_transformer.rb @@ -4,11 +4,9 @@ module CollectionSpace module Mapper - # converts date string to CS date stamp class DateStampTransformer < Transformer - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/downcase_transformer.rb b/lib/collectionspace/mapper/downcase_transformer.rb index c87aea3b..66238074 100644 --- a/lib/collectionspace/mapper/downcase_transformer.rb +++ b/lib/collectionspace/mapper/downcase_transformer.rb @@ -4,11 +4,9 @@ module CollectionSpace module Mapper - # downcases field values class DowncaseTransformer < Transformer - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/find_replace_operation.rb b/lib/collectionspace/mapper/find_replace_operation.rb index 1e3e828c..4962059c 100644 --- a/lib/collectionspace/mapper/find_replace_operation.rb +++ b/lib/collectionspace/mapper/find_replace_operation.rb @@ -2,7 +2,6 @@ module CollectionSpace module Mapper - # a single find/replace operation -- one step in a FindReplaceTransformer class FindReplaceOperation def initialize(opts) @@ -19,7 +18,7 @@ def perform(value) def self.create(opts) case opts[:type] when 'plain' - self.new(opts) + new(opts) when 'regex' RegexFindReplaceOperation.new(opts) end diff --git a/lib/collectionspace/mapper/find_replace_transformer.rb b/lib/collectionspace/mapper/find_replace_transformer.rb index 88ab1c56..95dec545 100644 --- a/lib/collectionspace/mapper/find_replace_transformer.rb +++ b/lib/collectionspace/mapper/find_replace_transformer.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # carries out a find/replace operation on a given value class FindReplaceTransformer < Transformer def initialize(transform:) diff --git a/lib/collectionspace/mapper/group_column_value.rb b/lib/collectionspace/mapper/group_column_value.rb index 155f4a8a..212edca6 100644 --- a/lib/collectionspace/mapper/group_column_value.rb +++ b/lib/collectionspace/mapper/group_column_value.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # a column value destined for a field in a repeating field group class GroupColumnValue < ColumnValue include Repeatable diff --git a/lib/collectionspace/mapper/group_multival_column_value.rb b/lib/collectionspace/mapper/group_multival_column_value.rb index a48ad894..b52ca070 100644 --- a/lib/collectionspace/mapper/group_multival_column_value.rb +++ b/lib/collectionspace/mapper/group_multival_column_value.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # a column value destined for a single/non-subgrouped repeating field within a repeating field group class GroupMultivalColumnValue < ColumnValue include Subgroupable diff --git a/lib/collectionspace/mapper/identifiers/authority_short_identifier.rb b/lib/collectionspace/mapper/identifiers/authority_short_identifier.rb index 85e19f4f..116dd98d 100644 --- a/lib/collectionspace/mapper/identifiers/authority_short_identifier.rb +++ b/lib/collectionspace/mapper/identifiers/authority_short_identifier.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper module Identifiers - class AuthorityShortIdentifier < ShortIdentifier def initialize(**opts) super @@ -24,4 +23,3 @@ def hashed_term end end end - diff --git a/lib/collectionspace/mapper/identifiers/short_identifier.rb b/lib/collectionspace/mapper/identifiers/short_identifier.rb index e3147f22..16ba145d 100644 --- a/lib/collectionspace/mapper/identifiers/short_identifier.rb +++ b/lib/collectionspace/mapper/identifiers/short_identifier.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper module Identifiers - class ShortIdentifier def initialize(term:) @term = term @@ -22,4 +21,3 @@ def prepped_term end end end - diff --git a/lib/collectionspace/mapper/multival_column_value.rb b/lib/collectionspace/mapper/multival_column_value.rb index 64457ed0..4ff738fc 100644 --- a/lib/collectionspace/mapper/multival_column_value.rb +++ b/lib/collectionspace/mapper/multival_column_value.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # a column value destined for a multivalue field nested directly under a namespace element class MultivalColumnValue < ColumnValue include Repeatable diff --git a/lib/collectionspace/mapper/non_hierarchical_relationship_prepper.rb b/lib/collectionspace/mapper/non_hierarchical_relationship_prepper.rb index 72925f0f..fa9227a4 100644 --- a/lib/collectionspace/mapper/non_hierarchical_relationship_prepper.rb +++ b/lib/collectionspace/mapper/non_hierarchical_relationship_prepper.rb @@ -78,9 +78,7 @@ def transform_terms end @response.split_data.each do |field, value| - unless @response.transformed_data.key?(field) - @response.transformed_data[field] = value - end + @response.transformed_data[field] = value unless @response.transformed_data.key?(field) end end end diff --git a/lib/collectionspace/mapper/object_hierarchy_data_prepper.rb b/lib/collectionspace/mapper/object_hierarchy_data_prepper.rb index cd9c59d6..22044cea 100644 --- a/lib/collectionspace/mapper/object_hierarchy_data_prepper.rb +++ b/lib/collectionspace/mapper/object_hierarchy_data_prepper.rb @@ -54,9 +54,7 @@ def transform_terms end @response.split_data.each do |field, value| - unless @response.transformed_data.key?(field) - @response.transformed_data[field] = value - end + @response.transformed_data[field] = value unless @response.transformed_data.key?(field) end end diff --git a/lib/collectionspace/mapper/record_mapper.rb b/lib/collectionspace/mapper/record_mapper.rb index bf9cc6d6..e5ef66bc 100644 --- a/lib/collectionspace/mapper/record_mapper.rb +++ b/lib/collectionspace/mapper/record_mapper.rb @@ -4,7 +4,6 @@ module CollectionSpace module Mapper - # Represents a JSON RecordMapper containing the config, field mappings, and template # for transforming a hash of data into CollectionSpace XML # The RecordMapper bundles up all the info needed by various other classes in order diff --git a/lib/collectionspace/mapper/regex_find_replace_operation.rb b/lib/collectionspace/mapper/regex_find_replace_operation.rb index f9fe5204..1656a6e2 100644 --- a/lib/collectionspace/mapper/regex_find_replace_operation.rb +++ b/lib/collectionspace/mapper/regex_find_replace_operation.rb @@ -2,7 +2,6 @@ module CollectionSpace module Mapper - # a single find/replace operation -- one step in a FindReplaceTransformer class RegexFindReplaceOperation < FindReplaceOperation def perform(value) diff --git a/lib/collectionspace/mapper/response.rb b/lib/collectionspace/mapper/response.rb index 97ee071a..3eb615fc 100644 --- a/lib/collectionspace/mapper/response.rb +++ b/lib/collectionspace/mapper/response.rb @@ -6,6 +6,7 @@ class Response attr_reader :orig_data attr_accessor :split_data, :merged_data, :transformed_data, :combined_data, :doc, :errors, :warnings, :identifier, :terms, :record_status, :csid, :uri, :refname + def initialize(data_hash) @orig_data = data_hash @merged_data = {} @@ -48,4 +49,3 @@ def add_multi_rec_found_warning(num_found) end end end - diff --git a/lib/collectionspace/mapper/row_data.rb b/lib/collectionspace/mapper/row_data.rb index c874e0f2..f1a45567 100644 --- a/lib/collectionspace/mapper/row_data.rb +++ b/lib/collectionspace/mapper/row_data.rb @@ -2,11 +2,11 @@ module CollectionSpace module Mapper - # represents a row of data from a CSV. # ends up having some responsibility for coordinating the processing of the row class RowData attr_reader :columns + def initialize(datahash, recmapper) @recmapper = recmapper @columns = datahash.map do |column, value| diff --git a/lib/collectionspace/mapper/row_fields.rb b/lib/collectionspace/mapper/row_fields.rb index 86fb7a17..4ad01e31 100644 --- a/lib/collectionspace/mapper/row_fields.rb +++ b/lib/collectionspace/mapper/row_fields.rb @@ -5,8 +5,7 @@ module Mapper # aggregate class to work with all of a RecordMapper's CollectionSpace fields in an # Arrayish-fashion class RowFields - def initialize() - end + def initialize; end end end end diff --git a/lib/collectionspace/mapper/structured_date_transformer.rb b/lib/collectionspace/mapper/structured_date_transformer.rb index da6505c8..6c134d4c 100644 --- a/lib/collectionspace/mapper/structured_date_transformer.rb +++ b/lib/collectionspace/mapper/structured_date_transformer.rb @@ -4,11 +4,9 @@ module CollectionSpace module Mapper - # converts date string to CS structured date XML snippet class StructuredDateTransformer < Transformer - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/subgroup_column_value.rb b/lib/collectionspace/mapper/subgroup_column_value.rb index d22c4aff..4113387c 100644 --- a/lib/collectionspace/mapper/subgroup_column_value.rb +++ b/lib/collectionspace/mapper/subgroup_column_value.rb @@ -5,7 +5,6 @@ module CollectionSpace module Mapper - # a column value destined for repeating subgroups of fields within a repeating field group class SubgroupColumnValue < ColumnValue include Subgroupable diff --git a/lib/collectionspace/mapper/term_handler.rb b/lib/collectionspace/mapper/term_handler.rb index 78477d80..d7a207ce 100644 --- a/lib/collectionspace/mapper/term_handler.rb +++ b/lib/collectionspace/mapper/term_handler.rb @@ -10,6 +10,7 @@ class TermHandler attr_reader :result, :terms, :warnings, :errors, :column, :source_type, :type, :subtype attr_accessor :value + def initialize(mapping:, data:, client:, cache:, mapper:) @mapping = mapping @data = data @@ -39,11 +40,11 @@ def initialize(mapping:, data:, client:, cache:, mapper:) private def handle_terms - if @data.first.is_a?(String) - @result = @data.map{ |val| handle_term(val) } - else - @result = @data.map{ |arr| arr.map{ |val| handle_term(val)} } - end + @result = if @data.first.is_a?(String) + @data.map{ |val| handle_term(val) } + else + @data.map{ |arr| arr.map{ |val| handle_term(val) } } + end end def handle_term(val) @@ -68,12 +69,10 @@ def handle_term(val) refname_urn = add_known_unknown_term(val, term_report) added = true else # not in cache - if @config.check_terms - refname_urn = searched_term(val, :refname) - if refname_urn - add_found_term(refname_urn, term_report) - added = true - end + refname_urn = searched_term(val, :refname) + if refname_urn + add_found_term(refname_urn, term_report) + added = true end end @@ -84,7 +83,7 @@ def handle_term(val) def add_found_term(refname_urn, term_report) refname_obj = CollectionSpace::Mapper::Tools::RefName.new(urn: refname_urn) - found = @config.check_terms ? true : false + found = true @terms << term_report.merge({found: found, refname: refname_obj}) end @@ -99,7 +98,8 @@ def add_new_unknown_term(val, term_report) type: type, subtype: subtype, term: val, - cache: @cache) + cache: @cache + ) @terms << term_report.merge({found: false, refname: refname_obj}) refname_url = refname_obj.urn @@ -118,4 +118,3 @@ def add_known_unknown_term(val, term_report) end end end - diff --git a/lib/collectionspace/mapper/term_searchable.rb b/lib/collectionspace/mapper/term_searchable.rb index beb9f969..9d7552f1 100644 --- a/lib/collectionspace/mapper/term_searchable.rb +++ b/lib/collectionspace/mapper/term_searchable.rb @@ -20,7 +20,7 @@ def cached_as_unknown?(val) private def type_subtype "#{type}/#{subtype}" - end + end # returns refName of cached term def cached_term(val, return_key = :refname, termtype = type, termsubtype = subtype) @@ -35,7 +35,7 @@ def cached_term(val, return_key = :refname, termtype = type, termsubtype = subty return cache_response if cache_response.is_a?(Hash) instance_eval(cache_response) - end + end # returns refName of searched (term) def searched_term(val, return_key = :refname) @@ -51,14 +51,14 @@ def searched_term(val, return_key = :refname) private def case_swap(string) string.match?(/[A-Z]/) ? string.downcase : string.capitalize - end + end private def term_search_response(val) as_is = get_term_response(val) return as_is if term_response_usable?(as_is) get_term_response(case_swap(val)) - end + end private def get_term_response(val) response = @client.find( @@ -72,7 +72,7 @@ def searched_term(val, return_key = :refname) nil else parse_response(response) - end + end private def parse_response(response) parsed = response.parsed['abstract_common_list'] @@ -81,7 +81,7 @@ def searched_term(val, return_key = :refname) nil else parsed - end + end def obj_csid(objnum, type) cached = @cache.get(type, '', objnum, search: false) @@ -98,7 +98,7 @@ def lookup_obj_or_procedure_csid(objnum, type) return nil unless rec csid = rec['csid'] - @cache.put(type, '', objnum, {refname: rec['refName'], csid: csid} ) + @cache.put(type, '', objnum, {refname: rec['refName'], csid: csid}) csid else errors << { @@ -109,7 +109,7 @@ def lookup_obj_or_procedure_csid(objnum, type) value: objnum, message: "Problem with search for #{objnum}." } - return nil + nil end end @@ -126,14 +126,14 @@ def term_csid(term) return false if ct == 0 true - end + end private def response_item_count(response) ct = response.dig('totalItems') return ct.to_i if ct nil - end + end private def add_missing_record_error(category, val) datacolumn = column ||= 'data' @@ -146,7 +146,7 @@ def term_csid(term) value: val, message: "#{val} (#{type_subtype} in #{datacolumn} column)" } - end + end private def rec_from_response(category, val, response) term_ct = response_item_count(response) @@ -183,7 +183,7 @@ def term_csid(term) end rec - end + end private def search_field field = CollectionSpace::Service.get(type: type)[:term] @@ -204,7 +204,6 @@ def get_vocabulary_term(vocab:, term:) @cache.get('vocabularies', vocab, term.capitalize, search: true) end end - end end end diff --git a/lib/collectionspace/mapper/tools/dates.rb b/lib/collectionspace/mapper/tools/dates.rb index 6de3caba..3c1c5fe7 100644 --- a/lib/collectionspace/mapper/tools/dates.rb +++ b/lib/collectionspace/mapper/tools/dates.rb @@ -36,7 +36,7 @@ def initialize(date_string, client, cache, config) service_parseable_month_formats = [ '^\w+ \d{4}$', - '^\d{4} \w+$', + '^\d{4} \w+$' ].map{ |f| Regexp.new(f) } other_month_formats = [ @@ -49,8 +49,7 @@ def initialize(date_string, client, cache, config) elsif date_string == THE_BOMB @timestamp = date_string blow_up_date - elsif - date_formats.any?{ |re| @date_string.match?(re) } + elsif date_formats.any?{ |re| @date_string.match?(re) } try_chronic_parse(@date_string) @timestamp ? create_mappable_date : try_services_query elsif two_digit_year_date_formats.any?{ |re| @date_string.match?(re) } @@ -78,23 +77,23 @@ def coerced_year_date val = @date_string.gsub('/', '-').split('-') yr = val.pop this_year = Time.now.year.to_s - this_year_century = this_year[0,2] - this_year_last_two = this_year[2,2].to_i - - if yr.to_i > this_year_last_two - val << "#{this_year_century.to_i - 1}#{yr}" - else - val << "#{this_year_century}#{yr}" - end + this_year_century = this_year[0, 2] + this_year_last_two = this_year[2, 2].to_i + + val << if yr.to_i > this_year_last_two + "#{this_year_century.to_i - 1}#{yr}" + else + "#{this_year_century}#{yr}" + end val.join('-') end def try_chronic_parse(string) - if @config.date_format == 'day month year' - @timestamp = Chronic.parse(string, endian_precedence: :little) - else - @timestamp = Chronic.parse(string) - end + @timestamp = if @config.date_format == 'day month year' + Chronic.parse(string, endian_precedence: :little) + else + Chronic.parse(string) + end end def create_mappable_passthrough @@ -172,24 +171,23 @@ def try_services_query @mappable = fix_services_scalars(result) else @mappable = {'dateDisplayDate' => date_string, - 'scalarValuesComputed' => 'false' - } + 'scalarValuesComputed' => 'false'} end end def fix_services_scalars(services_result) new_hash = {} services_result.each do |k, v| - if k.end_with?('ScalarValue') - new_hash[k] = "#{v}#{@timestamp_suffix}" - else - new_hash[k] = v - end + new_hash[k] = if k.end_with?('ScalarValue') + "#{v}#{@timestamp_suffix}" + else + v + end end new_hash end - def map(doc, parentnode, groupname) + def map(_doc, _parentnode, _groupname) @parser_result.each do |datefield, value| value = DateTime.parse(value).iso8601(3).sub('+00:00', 'Z') if datefield['ScalarValue'] end diff --git a/lib/collectionspace/mapper/tools/record_status_service.rb b/lib/collectionspace/mapper/tools/record_status_service.rb index 581b9d8b..a0c77b50 100644 --- a/lib/collectionspace/mapper/tools/record_status_service.rb +++ b/lib/collectionspace/mapper/tools/record_status_service.rb @@ -4,6 +4,7 @@ module CollectionSpace module Mapper class MultipleCsRecordsFoundError < StandardError attr_reader :message + def initialize(count) @message = "#{count} matching records found in CollectionSpace. Cannot determine which to update." end @@ -16,7 +17,7 @@ class RecordStatusService def initialize(client, mapper) @client = client @mapper = mapper - @is_authority = @mapper.config.service_type == 'authority' ? true : false + @is_authority = @mapper.config.service_type == 'authority' service = get_service @search_field = @is_authority ? service[:term] : service[:field] @ns_prefix = service[:ns_prefix] @@ -30,11 +31,11 @@ def initialize(client, mapper) # collectionspace-client code. # Tests in examples/search.rb def lookup(value) - if @ns_prefix == 'relations' - response = @client.find_relation(subject_csid: value[:sub], object_csid: value[:obj]) - else - response = lookup_non_relationship(value) - end + response = if @ns_prefix == 'relations' + @client.find_relation(subject_csid: value[:sub], object_csid: value[:obj]) + else + lookup_non_relationship(value) + end ct = count_results(response) if ct == 0 @@ -42,7 +43,7 @@ def lookup(value) elsif ct == 1 reportable_result(response.parsed[@response_top][@response_nested]) elsif ct > 1 - raise CollectionSpace::Mapper::MultipleCsRecordsFoundError.new(ct) unless use_first? + raise CollectionSpace::Mapper::MultipleCsRecordsFoundError, ct unless use_first? item = response.parsed[@response_top][@response_nested].first num_found = response.parsed[@response_top][@response_nested].length @@ -79,9 +80,7 @@ def use_first? end def count_results(response) - unless response.result.success? - raise CollectionSpace::RequestError, response.result.body - end + raise CollectionSpace::RequestError, response.result.body unless response.result.success? response.parsed[@response_top]['totalItems'].to_i end diff --git a/lib/collectionspace/mapper/tools/refname.rb b/lib/collectionspace/mapper/tools/refname.rb index fc6fbe71..80708eed 100644 --- a/lib/collectionspace/mapper/tools/refname.rb +++ b/lib/collectionspace/mapper/tools/refname.rb @@ -4,7 +4,7 @@ module CollectionSpace module Mapper module Tools class RefNameArgumentError < ArgumentError - def initialize(msg='Arguments requires either :urn OR :source_type, :type, :subtype, :term, :cache values') + def initialize(msg = 'Arguments requires either :urn OR :source_type, :type, :subtype, :term, :cache values') super end end @@ -24,7 +24,7 @@ def initialize(args) new_from_urn elsif args_given == term_args cache = args[:cache] - @domain = cache.domain.sub(/https?:\/\//, '').sub('/cspace-services', '') + @domain = cache.domain.sub(%r{https?://}, '').sub('/cspace-services', '') @type = args[:type] @subtype = args[:subtype] @display_name = args[:term] @@ -43,7 +43,6 @@ def build_urn end def new_from_term - @identifier = CollectionSpace::Mapper::Identifiers::ShortIdentifier.new(term: @display_name).value end @@ -52,9 +51,9 @@ def new_from_authority_term end def new_from_urn - if /^urn:cspace:([^:]+):([^:]+):name\(([^\)]+)\):item:name\(([^\)]+)\)'/.match?(@urn) + if /^urn:cspace:([^:]+):([^:]+):name\(([^)]+)\):item:name\(([^)]+)\)'/.match?(@urn) term_parts_from_urn - elsif /^urn:cspace:([^:]+):([^:]+):id\(([^\)]+)\)(.*)/.match?(@urn) + elsif /^urn:cspace:([^:]+):([^:]+):id\(([^)]+)\)(.*)/.match?(@urn) non_term_parts_from_urn else raise CS::Mapper::Tools::UnparseableUrnError @@ -62,7 +61,7 @@ def new_from_urn end def term_parts_from_urn - parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):name\(([^\)]+)\):item:name\(([^\)]+)\)'/) + parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):name\(([^)]+)\):item:name\(([^)]+)\)'/) @domain = parts[1] @type = parts[2] @subtype = parts[3] @@ -71,7 +70,7 @@ def term_parts_from_urn end def non_term_parts_from_urn - parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):id\(([^\)]+)\)(.*)/) + parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):id\(([^)]+)\)(.*)/) @domain = parts[1] @type = parts[2] @subtype = nil diff --git a/lib/collectionspace/mapper/tools/symbolizable.rb b/lib/collectionspace/mapper/tools/symbolizable.rb index 44228739..955fea88 100644 --- a/lib/collectionspace/mapper/tools/symbolizable.rb +++ b/lib/collectionspace/mapper/tools/symbolizable.rb @@ -11,7 +11,7 @@ def symbolize(hash) end def symbolize_transforms(transforms) - transforms.each do |field, fieldtransform| + transforms.each do |_field, fieldtransform| fieldtransform.transform_keys!(&:to_sym) next unless replacements?(fieldtransform) @@ -30,4 +30,3 @@ def replacements?(fieldtransform) end end end - diff --git a/lib/collectionspace/mapper/transformer.rb b/lib/collectionspace/mapper/transformer.rb index f6a30e8c..2313e0c2 100644 --- a/lib/collectionspace/mapper/transformer.rb +++ b/lib/collectionspace/mapper/transformer.rb @@ -2,18 +2,16 @@ module CollectionSpace module Mapper - # parent class of the data value Transformer class hierarchy class Transformer attr_reader :precedence, :warnings - def initialize(opts = {}) + def initialize(_opts = {}) @precedence = lookup_precedence @warnings = [] end - def transform(value) - end + def transform(value); end def <=>(other) @precedence <=> other.precedence @@ -35,7 +33,7 @@ def lookup_precedence ].find_index(self.class) end - def self.create(type:, transform: {}, recmapper:) + def self.create(type:, recmapper:, transform: {}) case type.to_sym when :authority AuthorityTransformer.new(transform: transform, recmapper: recmapper) diff --git a/lib/collectionspace/mapper/transformers.rb b/lib/collectionspace/mapper/transformers.rb index 5d972058..ce98f9c8 100644 --- a/lib/collectionspace/mapper/transformers.rb +++ b/lib/collectionspace/mapper/transformers.rb @@ -2,7 +2,6 @@ module CollectionSpace module Mapper - # aggregate representation of transformers associated with a ColumnMapping (queue) # Performs a factory function by creating the appropriate individual Transformers for a given # ColumnMapping based on data_type diff --git a/lib/collectionspace/mapper/value_transformer.rb b/lib/collectionspace/mapper/value_transformer.rb index c2ed8216..f68d1072 100644 --- a/lib/collectionspace/mapper/value_transformer.rb +++ b/lib/collectionspace/mapper/value_transformer.rb @@ -5,6 +5,7 @@ module Mapper class ValueTransformer include TermSearchable attr_reader :orig, :result, :warnings, :errors + def initialize(value, transforms, prepper) @value = value @orig = @value.clone @@ -99,4 +100,3 @@ def process_behrensmeyer end end end - diff --git a/lib/collectionspace/mapper/vocabulary_transformer.rb b/lib/collectionspace/mapper/vocabulary_transformer.rb index d438236c..0416fba8 100644 --- a/lib/collectionspace/mapper/vocabulary_transformer.rb +++ b/lib/collectionspace/mapper/vocabulary_transformer.rb @@ -4,10 +4,8 @@ module CollectionSpace module Mapper - # transforms vocabulary term into RefName class VocabularyTransformer < Transformer - def initialize(opts) super @type = 'vocabularies' @@ -17,8 +15,7 @@ def initialize(opts) @csclient = mapper.csclient end - def transform(value) - end + def transform(value); end end end end diff --git a/lib/collectionspace/mapper/xml_template.rb b/lib/collectionspace/mapper/xml_template.rb index 132a1736..783d3f7e 100644 --- a/lib/collectionspace/mapper/xml_template.rb +++ b/lib/collectionspace/mapper/xml_template.rb @@ -2,7 +2,6 @@ module CollectionSpace module Mapper - # The XML document structure for a given record type. # Knows the structure as a Hash provided by initial JSON record mapper # Provides a blank XML document with all namespace and field group elements diff --git a/spec/anthro_helpers.rb b/spec/anthro_helpers.rb index 698158ad..fcbf8d58 100644 --- a/spec/anthro_helpers.rb +++ b/spec/anthro_helpers.rb @@ -179,7 +179,7 @@ def populate_anthro(cache) ['personauthorities', 'person', 'praya', {refname: "urn:cspace:anthro.collectionspace.org:personauthorities:name(person):item:name(praya1599821095120)'praya'", csid: '1111-2222-3333-4444'}], ['personauthorities', 'person', 'jijoe', - {refname: "urn:cspace:anthro.collectionspace.org:personauthorities:name(person):item:name(jijoe1599821246989)'jijoe'", csid: '1111-2222-3333-4444'}], + {refname: "urn:cspace:anthro.collectionspace.org:personauthorities:name(person):item:name(jijoe1599821246989)'jijoe'", csid: '1111-2222-3333-4444'}] ] populate(cache, terms) end diff --git a/spec/bonsai_helpers.rb b/spec/bonsai_helpers.rb index 0a836d98..3a705217 100644 --- a/spec/bonsai_helpers.rb +++ b/spec/bonsai_helpers.rb @@ -42,7 +42,7 @@ def populate_bonsai(cache) ['vocabularies', 'deaccessionapprovalstatus', 'not required', {refname: "urn:cspace:bonsai.collectionspace.org:vocabularies:name(deaccessionapprovalstatus):item:name(not_required)'not required'", csid: '1111-2222-3333-4444'}], ['vocabularies', 'disposalmethod', 'public auction', - {refname: "urn:cspace:bonsai.collectionspace.org:vocabularies:name(disposalmethod):item:name(public_auction)'public auction'", csid: '1111-2222-3333-4444'}], + {refname: "urn:cspace:bonsai.collectionspace.org:vocabularies:name(disposalmethod):item:name(public_auction)'public auction'", csid: '1111-2222-3333-4444'}] ] populate(cache, terms) end diff --git a/spec/botgarden_helpers.rb b/spec/botgarden_helpers.rb index f7aef6e8..3acc6ac2 100644 --- a/spec/botgarden_helpers.rb +++ b/spec/botgarden_helpers.rb @@ -76,7 +76,7 @@ def populate_botgarden(cache) ['vocabularies', 'taxontermflag', 'invalid', {refname: "urn:cspace:botgarden.collectionspace.org:vocabularies:name(taxontermflag):item:name(invalid)'invalid'", csid: '1111-2222-3333-4444'}], ['vocabularies', 'taxontermflag', 'valid', - {refname: "urn:cspace:botgarden.collectionspace.org:vocabularies:name(taxontermflag):item:name(valid)'valid'", csid: '1111-2222-3333-4444'}], + {refname: "urn:cspace:botgarden.collectionspace.org:vocabularies:name(taxontermflag):item:name(valid)'valid'", csid: '1111-2222-3333-4444'}] ] populate(cache, terms) end diff --git a/spec/collectionspace/mapper/column_mapping_spec.rb b/spec/collectionspace/mapper/column_mapping_spec.rb index 05785faa..6c3bf914 100644 --- a/spec/collectionspace/mapper/column_mapping_spec.rb +++ b/spec/collectionspace/mapper/column_mapping_spec.rb @@ -27,10 +27,12 @@ end describe '#fullpath' do - let(:hash) do { + let(:hash) do + { namespace: 'collectionobjects_common', - xpath: ['otherNumberList', 'otherNumber'], - } end + xpath: %w[otherNumberList otherNumber] + } + end it 'returns full xpath to target CollectionSpace field' do expected = 'collectionobjects_common/otherNumberList/otherNumber' expect(mapping.fullpath).to eq(expected) diff --git a/spec/collectionspace/mapper/column_mappings_spec.rb b/spec/collectionspace/mapper/column_mappings_spec.rb index b981d742..bb314631 100644 --- a/spec/collectionspace/mapper/column_mappings_spec.rb +++ b/spec/collectionspace/mapper/column_mappings_spec.rb @@ -3,74 +3,78 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::ColumnMappings do - let(:mappings) do [ - {fieldname: 'objectNumber', - transforms: {}, - source_type: 'na', - source_name: nil, - namespace: 'collectionobjects_common', - xpath: [], - data_type: 'string', - repeats: 'n', - in_repeating_group: 'n/a', - opt_list_values: [], - datacolumn: 'objectNumber', - required: 'y'}, - {fieldname: 'numberOfObjects', - transforms: {}, - source_type: 'na', - source_name: nil, - namespace: 'collectionobjects_common', - xpath: [], - data_type: 'integer', - repeats: 'n', - in_repeating_group: 'n/a', - opt_list_values: [], - datacolumn: 'numberOfObjects', - required: 'n'}, - {fieldname: 'numberValue', - transforms: {}, - source_type: 'na', - source_name: nil, - namespace: 'collectionobjects_common', - xpath: ['otherNumberList', 'otherNumber'], - data_type: 'string', - repeats: 'n', - in_repeating_group: 'y', - opt_list_values: [], - datacolumn: 'numberValue', - required: 'n'}, - {fieldname: 'numberType', - transforms: {}, - source_type: 'optionlist', - source_name: 'numberTypes', - namespace: 'collectionobjects_common', - xpath: ['otherNumberList', 'otherNumber'], - data_type: 'string', - repeats: 'n', - in_repeating_group: 'y', - opt_list_values: ['lender', 'obsolete', 'previous', 'serial', 'unknown'], - datacolumn: 'numberType', - required: 'n'}, - {datacolumn: 'otherRequired', - required: 'y'} - ] end + let(:mappings) do + [ + {fieldname: 'objectNumber', + transforms: {}, + source_type: 'na', + source_name: nil, + namespace: 'collectionobjects_common', + xpath: [], + data_type: 'string', + repeats: 'n', + in_repeating_group: 'n/a', + opt_list_values: [], + datacolumn: 'objectNumber', + required: 'y'}, + {fieldname: 'numberOfObjects', + transforms: {}, + source_type: 'na', + source_name: nil, + namespace: 'collectionobjects_common', + xpath: [], + data_type: 'integer', + repeats: 'n', + in_repeating_group: 'n/a', + opt_list_values: [], + datacolumn: 'numberOfObjects', + required: 'n'}, + {fieldname: 'numberValue', + transforms: {}, + source_type: 'na', + source_name: nil, + namespace: 'collectionobjects_common', + xpath: %w[otherNumberList otherNumber], + data_type: 'string', + repeats: 'n', + in_repeating_group: 'y', + opt_list_values: [], + datacolumn: 'numberValue', + required: 'n'}, + {fieldname: 'numberType', + transforms: {}, + source_type: 'optionlist', + source_name: 'numberTypes', + namespace: 'collectionobjects_common', + xpath: %w[otherNumberList otherNumber], + data_type: 'string', + repeats: 'n', + in_repeating_group: 'y', + opt_list_values: %w[lender obsolete previous serial unknown], + datacolumn: 'numberType', + required: 'n'}, + {datacolumn: 'otherRequired', + required: 'y'} + ] + end let(:recordmapper){ instance_double('CS::Mapper::RecordMapper') } let(:mapperconfig){ instance_double('CS::Mapper::RecordMapperConfig') } let(:mappingsobj){ dc = described_class.new(mappings: mappings, mapper: recordmapper) } - let(:added_field) do { - fieldname: 'addedField', - namespace: 'persons_common', - data_type: 'string', - xpath: [], - required: 'not in input data', - repeats: 'n', - in_repeating_group: 'n/a', - datacolumn: 'addedfield' - } end + let(:added_field) do + { + fieldname: 'addedField', + namespace: 'persons_common', + data_type: 'string', + xpath: [], + required: 'not in input data', + repeats: 'n', + in_repeating_group: 'n/a', + datacolumn: 'addedfield' + } + end before do allow(recordmapper).to receive(:config).and_return(mapperconfig) @@ -94,32 +98,34 @@ end context 'when initialized from media RecordMapper' do - let(:mappings) do [ - {fieldname: 'identificationNumber', - transforms: {}, - source_type: 'na', - source_name: nil, - namespace: 'media_common', - xpath: [], - data_type: 'string', - repeats: 'n', - in_repeating_group: 'n/a', - opt_list_values: [], - datacolumn: 'identificationNumber', - required: 'y'}, - {fieldname: 'title', - transforms: {}, - source_type: 'na', - source_name: nil, - namespace: 'media_common', - xpath: [], - data_type: 'string', - repeats: 'n', - in_repeating_group: 'n/a', - opt_list_values: [], - datacolumn: 'title', - required: 'n'} - ] end + let(:mappings) do + [ + {fieldname: 'identificationNumber', + transforms: {}, + source_type: 'na', + source_name: nil, + namespace: 'media_common', + xpath: [], + data_type: 'string', + repeats: 'n', + in_repeating_group: 'n/a', + opt_list_values: [], + datacolumn: 'identificationNumber', + required: 'y'}, + {fieldname: 'title', + transforms: {}, + source_type: 'na', + source_name: nil, + namespace: 'media_common', + xpath: [], + data_type: 'string', + repeats: 'n', + in_repeating_group: 'n/a', + opt_list_values: [], + datacolumn: 'title', + required: 'n'} + ] + end it 'adds mediaFileURI to mappings' do allow(mapperconfig).to receive(:common_namespace).and_return('media_common') @@ -158,4 +164,3 @@ end end end - diff --git a/spec/collectionspace/mapper/column_value_spec.rb b/spec/collectionspace/mapper/column_value_spec.rb index f92760f2..8a8c5830 100644 --- a/spec/collectionspace/mapper/column_value_spec.rb +++ b/spec/collectionspace/mapper/column_value_spec.rb @@ -3,19 +3,23 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::ColumnValue do - let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json'} + let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } let(:recmapper){ get_record_mapper_object(mapperpath, core_cache) } let(:mapping){ recmapper.mappings.lookup(colname) } - let(:colval) do described_class.new(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:colval) do + described_class.new(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end describe '.create' do - let(:creator) do described_class.create(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:creator) do + described_class.create(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end context 'given core collectionobject collection value' do let(:colname){ 'collection' } @@ -67,4 +71,3 @@ end end end - diff --git a/spec/collectionspace/mapper/config_spec.rb b/spec/collectionspace/mapper/config_spec.rb index d38b07bc..a64644a0 100644 --- a/spec/collectionspace/mapper/config_spec.rb +++ b/spec/collectionspace/mapper/config_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::Config do - let(:configstr) do '{ + let(:configstr) do + '{ "delimiter": ";", "subgroup_delimiter": "^^", "response_mode": "verbose", @@ -36,8 +37,9 @@ let(:with_nothing){ described_class.new } let(:with_array){ described_class.new(config: [2, 3]) } let(:expected_hash) do - {delimiter: ';', subgroup_delimiter: '^^', response_mode: 'verbose', strip_id_values: true, - multiple_recs_found: 'fail', force_defaults: false, check_record_status: true, check_terms: true, date_format: 'month day year', two_digit_year_handling: 'convert to four digit', transforms: {'collection' => {special: ['downcase_value'], replacements: [{find: ' ', replace: '-', type: 'plain'}]}}, default_values: {'publishto' => 'DPLA;Omeka', 'collection' => 'library-collection'}} end + {delimiter: ';', subgroup_delimiter: '^^', response_mode: 'verbose', strip_id_values: true, + multiple_recs_found: 'fail', force_defaults: false, check_record_status: true, check_terms: true, date_format: 'month day year', two_digit_year_handling: 'convert to four digit', transforms: {'collection' => {special: ['downcase_value'], replacements: [{find: ' ', replace: '-', type: 'plain'}]}}, default_values: {'publishto' => 'DPLA;Omeka', 'collection' => 'library-collection'}} + end let(:invalid_response){ {response_mode: 'mouthy'} } let(:with_invalid_response){ described_class.new(config: invalid_response) } @@ -149,5 +151,3 @@ # end # end end - - diff --git a/spec/collectionspace/mapper/data_handler_spec.rb b/spec/collectionspace/mapper/data_handler_spec.rb index 880a91a3..922590b1 100644 --- a/spec/collectionspace/mapper/data_handler_spec.rb +++ b/spec/collectionspace/mapper/data_handler_spec.rb @@ -7,7 +7,7 @@ let(:cache){ core_cache_search } let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } let(:mapper){ get_json_record_mapper(mapperpath) } - let(:config){ {"delimiter": '|'} } + let(:config){ {delimiter: '|'} } let(:handler) do CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, client: client, @@ -16,41 +16,38 @@ end # these make services api calls to find terms not in cache - context 'when config has check_terms = false', services_call: true do - let(:config){ '{"check_terms": false}' } + context 'with some terms found and some terms not found', services_call: true do let(:result){ handler.process(data).terms.reject{ |t| t[:found] } } context 'with terms in instance but not in cache' do let(:data) do - {'objectNumber' => '20CS.001.0002', - 'titleLanguage' => 'English', # vocabulary, in instance, in cache - 'namedCollection' => 'Test Collection', # authority, not in instance, not in cache - 'collection' => 'rando'} + { + 'objectNumber' => '20CS.001.0002', + 'titleLanguage' => 'English', # vocabulary, in instance, in cache + 'namedCollection' => 'Test Collection' # authority, in instance (caseswapped), not in cache + } end - it 'returns found = false for all terms, even if they exist in client', skip: 'deprecating check_terms' do - res = @handler.process(@data) + it 'returns expected found values' do + res = handler.process(data) not_found = res.terms.reject{ |t| t[:found] } - expect(not_found.length).to eq(2) + expect(not_found.length).to eq(0) end end context 'with terms in instance but not in cache, and not in instance' do let(:data) do - {'objectNumber' => '20CS.001.0001', - 'numberOfObjects' => '1', - 'numberValue' => '123456|98765', - 'numberType' => 'lender|obsolete', - 'title' => 'A Man| A Woman', - 'titleLanguage' => 'English| Klingon', - 'namedCollection' => 'Test collection', - 'collection' => 'permanent collection'} + { + 'objectNumber' => '20CS.001.0001', + 'titleLanguage' => 'English| Klingon', # English is in cache; Klingon is not in instance or cache + 'namedCollection' => 'Test collection' # In instance (caseswapped) + } end - it 'returns found = false for all terms, even if they exist in client', skip: 'deprecating check_terms' do - res = @handler.process(@data2) + it 'returns expected found values' do + res = handler.process(data) not_found = res.terms.reject{ |t| t[:found] } - expect(not_found.length).to eq(3) + expect(not_found.length).to eq(1) end end end @@ -59,7 +56,7 @@ data1 = { 'objectNumber' => '1', 'publishTo' => 'All', # vocabulary - in instance, not in cache - 'namedCollection' => 'QA TARGET Work', # authority - in instance, not in cache + 'namedCollection' => 'QA TARGET Work' # authority - in instance, not in cache } data2 = { 'objectNumber' => '2', @@ -175,7 +172,8 @@ context 'xpath ending with mortuaryTreatmentGroup' do let(:xpath) do - 'collectionobjects_anthro/commingledRemainsGroupList/commingledRemainsGroup/mortuaryTreatmentGroupList/mortuaryTreatmentGroup' end + 'collectionobjects_anthro/commingledRemainsGroupList/commingledRemainsGroup/mortuaryTreatmentGroupList/mortuaryTreatmentGroup' + end it 'is_group = true' do expect(result[:is_group]).to be true @@ -351,5 +349,3 @@ end end end - - diff --git a/spec/collectionspace/mapper/data_mapper_core_spec.rb b/spec/collectionspace/mapper/data_mapper_core_spec.rb index 9d9789e2..2f060213 100644 --- a/spec/collectionspace/mapper/data_mapper_core_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_core_spec.rb @@ -8,10 +8,12 @@ context 'core profile' do let(:client){ core_client } let(:cache){ core_cache } - let(:handler) do CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, - client: client, - cache: cache, - config: config) end + let(:handler) do + CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, + client: client, + cache: cache, + config: config) + end let(:datahash){ get_datahash(path: hashpath) } let(:response){ handler.process(datahash) } let(:mapped_doc){ remove_namespaces(response.doc) } @@ -25,9 +27,11 @@ # These tests are prone to failing if one of the records used in the test in core.dev is deleted # If a UUID is expected but you get blank, recreate the record in core.dev, rerun the test to # get the UUID for the new record, and replace the old UUID in both fixture XML files used. - let(:mapper) do get_json_record_mapper( - 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_nonhierarchicalrelationship.json' - ) end + let(:mapper) do + get_json_record_mapper( + 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_nonhierarchicalrelationship.json' + ) + end context 'when all IDs found' do let(:hashpath){ 'spec/fixtures/files/datahashes/core/nonHierarchicalRelationship1.json' } @@ -132,7 +136,8 @@ context 'authority hierarchy record', services_call: true do let(:mapper) do - get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_authorityhierarchy.json') end + get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_authorityhierarchy.json') + end context 'with existing terms' do let(:hashpath){ 'spec/fixtures/files/datahashes/core/authorityHierarchy1.json' } @@ -248,7 +253,8 @@ context 'collectionobject record' do let(:mapper) do - get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json') end + get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json') + end context 'record 1' do let(:hashpath){ 'spec/fixtures/files/datahashes/core/collectionobject1.json' } @@ -305,7 +311,8 @@ context 'conditioncheck record', services_call: true do let(:mapper) do - get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_conditioncheck.json') end + get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_conditioncheck.json') + end context 'record 1' do let(:hashpath){ 'spec/fixtures/files/datahashes/core/conditioncheck1.json' } @@ -327,7 +334,8 @@ context 'conservation record', services_call: true do let(:mapper) do - get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_conservation.json') end + get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_conservation.json') + end context 'record 1' do let(:hashpath){ 'spec/fixtures/files/datahashes/core/conservation1.json' } @@ -372,7 +380,7 @@ let(:mapper){ get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_group.json') } context 'record 1' do - let(:hashpath){ 'spec/fixtures/files/datahashes/core/group1.json'} + let(:hashpath){ 'spec/fixtures/files/datahashes/core/group1.json' } let(:fixturepath){ 'core/group1.xml' } it 'does not map unexpected fields' do @@ -507,7 +515,7 @@ it 'maps as expected' do fixture_xpaths.each do |xpath| - # todo - why is this next clause here? + # TODO: - why is this next clause here? next if xpath.start_with?('/document/objectexit_common/exitDateGroup') fixture_node = standardize_value(fixture_doc.xpath(xpath).text) diff --git a/spec/collectionspace/mapper/data_mapper_spec.rb b/spec/collectionspace/mapper/data_mapper_spec.rb index a09ddb77..1825fd07 100644 --- a/spec/collectionspace/mapper/data_mapper_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_spec.rb @@ -27,7 +27,8 @@ data = [data1, data2, data3] preppers = data.map{ |d| CollectionSpace::Mapper::DataPrepper.new(d, @handler) } mappers = preppers.map do |prepper| - CollectionSpace::Mapper::DataMapper.new(prepper.prep.response, @handler, prepper.xphash) end + CollectionSpace::Mapper::DataMapper.new(prepper.prep.response, @handler, prepper.xphash) + end docs = mappers.map{ |mapper| remove_namespaces(mapper.response.doc) } docxpaths = docs.map{ |doc| list_xpaths(doc) } @@ -219,7 +220,7 @@ default_values: { 'publishTo' => 'DPLA;Omeka', 'collection' => 'library-collection' - }, + } } @recmapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject.json') diff --git a/spec/collectionspace/mapper/data_prepper_spec.rb b/spec/collectionspace/mapper/data_prepper_spec.rb index 4a2e8861..0d9d6cea 100644 --- a/spec/collectionspace/mapper/data_prepper_spec.rb +++ b/spec/collectionspace/mapper/data_prepper_spec.rb @@ -10,7 +10,7 @@ let(:mapper){ get_json_record_mapper(mapperpath) } let(:config) do { - delimiter: delimiter, + delimiter: delimiter } end let(:handler) do @@ -43,7 +43,7 @@ { delimiter: ';', default_values: { - 'publishTo' => 'DPLA;Omeka', + 'publishTo' => 'DPLA;Omeka' } } end @@ -75,7 +75,7 @@ { delimiter: ';', default_values: { - 'publishTo' => 'DPLA;Omeka', + 'publishTo' => 'DPLA;Omeka' }, force_defaults: true } @@ -137,7 +137,7 @@ { 'objectnumber' => '123', 'annotationdate' => '12/19/2019;12/10/2019', - 'identdategroup' => '2019-09-30;4/5/2020', + 'identdategroup' => '2019-09-30;4/5/2020' } end context 'when field is a structured date' do @@ -238,7 +238,7 @@ } end - # todo: why does this call services api? + # TODO: why does this call services api? it 'combines values properly', services_call: true do result = prepper.prep.response.combined_data[xpath]['measuredBy'] expected = [ @@ -246,10 +246,11 @@ "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Gomongo1599463746195)'Gomongo'", "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Comodore1599463826401)'Comodore'", "urn:cspace:core.collectionspace.org:orgauthorities:name(organization):item:name(Cuckoo1599463786824)'Cuckoo'", - ''], + '' + ], [ "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Gomongo1599463746195)'Gomongo'", - "urn:cspace:core.collectionspace.org:orgauthorities:name(organization):item:name(Cuckoo1599463786824)'Cuckoo'", + "urn:cspace:core.collectionspace.org:orgauthorities:name(organization):item:name(Cuckoo1599463786824)'Cuckoo'" ] ] expect(result).to eq(expected) @@ -280,7 +281,8 @@ "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Gomongo1599463746195)'Gomongo'", "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Comodore1599463826401)'Comodore'", "urn:cspace:core.collectionspace.org:orgauthorities:name(organization):item:name(Cuckoo1599463786824)'Cuckoo'", - ''], + '' + ] ] expect(result).to eq(expected) end diff --git a/spec/collectionspace/mapper/data_quality_checker_spec.rb b/spec/collectionspace/mapper/data_quality_checker_spec.rb index 560aa333..403f43ac 100644 --- a/spec/collectionspace/mapper/data_quality_checker_spec.rb +++ b/spec/collectionspace/mapper/data_quality_checker_spec.rb @@ -7,39 +7,43 @@ let(:mapping){ CollectionSpace::Mapper::ColumnMapping.new(maphash, recordmapper) } context 'when source_type = optionlist' do - let(:maphash) do { + let(:maphash) do + { fieldname: 'collection', datacolumn: 'collection', transforms: {}, source_type: 'optionlist', - opt_list_values: [ - 'library-collection', - 'permanent-collection', - 'study-collection', - 'teaching-collection' + opt_list_values: %w[ + library-collection + permanent-collection + study-collection + teaching-collection ] - } end - it 'returns expected warnings' do - data = [ - 'Permanent Collection', # not a valid option, should return warning - '%NULLVALUE%', # indicates placeholder blank value, should be skipped - 'permanent-collection', # valid option - '' # non-placeholder blank value, should be skipped - ] - res = CollectionSpace::Mapper::DataQualityChecker.new(mapping, data).warnings - expect(res.size).to eq(1) - end + } end + it 'returns expected warnings' do + data = [ + 'Permanent Collection', # not a valid option, should return warning + '%NULLVALUE%', # indicates placeholder blank value, should be skipped + 'permanent-collection', # valid option + '' # non-placeholder blank value, should be skipped + ] + res = CollectionSpace::Mapper::DataQualityChecker.new(mapping, data).warnings + expect(res.size).to eq(1) + end + end context 'when datacolumn contains `refname`' do context 'and source_type = vocabulary' do - let(:maphash) do { - fieldname: 'nagprainventoryname', - datacolumn: 'nagprainventorynamerefname', - transforms: {}, - source_type: 'vocabulary', - opt_list_values: [] - } end + let(:maphash) do + { + fieldname: 'nagprainventoryname', + datacolumn: 'nagprainventorynamerefname', + transforms: {}, + source_type: 'vocabulary', + opt_list_values: [] + } + end context 'and value is not well-formed refname' do it 'returns warning' do data = ["urn:pahma.cspace.berkeley.edu:vocabularies:name(nagpraPahmaInventoryNames):item:name(nagpraPahmaInventoryNames01)'AK-Alaska'"] @@ -57,13 +61,15 @@ end context 'and source_type = authority' do - let(:maphash) do { - fieldname: 'nagpradetermculture', - datacolumn: 'nagpradetermculturerefname', - transforms: {}, - source_type: 'authority', - opt_list_values: [] - } end + let(:maphash) do + { + fieldname: 'nagpradetermculture', + datacolumn: 'nagpradetermculturerefname', + transforms: {}, + source_type: 'authority', + opt_list_values: [] + } + end context 'and value is not well-formed refname' do it 'returns warning' do data = ["urn:cspace:pahma.cspace.berkeley.edu:orgauthorities:name(organization):item:name(Chumash1607458832492)'Chumash"] diff --git a/spec/collectionspace/mapper/data_splitter_spec.rb b/spec/collectionspace/mapper/data_splitter_spec.rb index 0ff7d64d..e9829753 100644 --- a/spec/collectionspace/mapper/data_splitter_spec.rb +++ b/spec/collectionspace/mapper/data_splitter_spec.rb @@ -49,33 +49,33 @@ RSpec.describe CollectionSpace::Mapper::SubgroupSplitter do before(:all) do - @config = CS::Mapper::Config.new(config: {delimiter: ';', subgroup_delimiter: '^^'}) - end + @config = CS::Mapper::Config.new(config: {delimiter: ';', subgroup_delimiter: '^^'}) + end describe '#result' do - context 'when "a^^b;c^^d"' do - it 'returns [["a", "b"], ["c", "d"]]' do - s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^b;c^^d', @config) - expect(s.result).to eq([%w[a b], %w[c d]]) - end - end - context 'when "a;c"' do - it 'returns [["a"], ["c"]]' do - s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c', @config) - expect(s.result).to eq([%w[a], %w[c]]) - end - end - context 'when "a;c^^d"' do - it 'returns [["a"], ["c", "d"]]' do - s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c^^d', @config) - expect(s.result).to eq([%w[a], %w[c d]]) - end - end - context 'when "a^^;c^^d"' do - it 'returns [["a", ""], ["c", "d"]]' do - s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^;c^^d', @config) - expect(s.result).to eq([['a', ''], %w[c d]]) - end - end - end + context 'when "a^^b;c^^d"' do + it 'returns [["a", "b"], ["c", "d"]]' do + s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^b;c^^d', @config) + expect(s.result).to eq([%w[a b], %w[c d]]) + end + end + context 'when "a;c"' do + it 'returns [["a"], ["c"]]' do + s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c', @config) + expect(s.result).to eq([%w[a], %w[c]]) + end + end + context 'when "a;c^^d"' do + it 'returns [["a"], ["c", "d"]]' do + s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c^^d', @config) + expect(s.result).to eq([%w[a], %w[c d]]) + end + end + context 'when "a^^;c^^d"' do + it 'returns [["a", ""], ["c", "d"]]' do + s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^;c^^d', @config) + expect(s.result).to eq([['a', ''], %w[c d]]) + end + end + end end diff --git a/spec/collectionspace/mapper/data_validator_spec.rb b/spec/collectionspace/mapper/data_validator_spec.rb index 9f1b96f1..49bd4755 100644 --- a/spec/collectionspace/mapper/data_validator_spec.rb +++ b/spec/collectionspace/mapper/data_validator_spec.rb @@ -94,14 +94,17 @@ before(:all) do @anthro_object_mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject.json') @anthro_dv = CollectionSpace::Mapper::DataValidator.new( -CollectionSpace::Mapper::RecordMapper.new(mapper: @anthro_object_mapper, termcache: anthro_cache), anthro_cache) + CollectionSpace::Mapper::RecordMapper.new(mapper: @anthro_object_mapper, termcache: anthro_cache), anthro_cache + ) @botgarden_loanout_mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2-0-1_loanout.json') @botgarden_dv = CollectionSpace::Mapper::DataValidator.new( -CollectionSpace::Mapper::RecordMapper.new(mapper: @botgarden_loanout_mapper, - termcache: botgarden_cache), botgarden_cache) + CollectionSpace::Mapper::RecordMapper.new(mapper: @botgarden_loanout_mapper, + termcache: botgarden_cache), botgarden_cache + ) @core_authhier_mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_authorityhierarchy.json') @core_authhier_dv = CollectionSpace::Mapper::DataValidator.new( -CollectionSpace::Mapper::RecordMapper.new(mapper: @core_authhier_mapper, termcache: core_cache), core_cache) + CollectionSpace::Mapper::RecordMapper.new(mapper: @core_authhier_mapper, termcache: core_cache), core_cache + ) end describe '#validate' do @@ -114,7 +117,8 @@ before(:all) do @mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_movement.json') @validator = CollectionSpace::Mapper::DataValidator.new( -CollectionSpace::Mapper::RecordMapper.new(mapper: @mapper, termcache: core_cache), core_cache) + CollectionSpace::Mapper::RecordMapper.new(mapper: @mapper, termcache: core_cache), core_cache + ) end it 'validates' do data = {'movementReferenceNumber' => '1', 'currentLocationLocationLocal' => 'Loc'} diff --git a/spec/collectionspace/mapper/find_replace_operation_spec.rb b/spec/collectionspace/mapper/find_replace_operation_spec.rb index bc0c4579..c0f0995b 100644 --- a/spec/collectionspace/mapper/find_replace_operation_spec.rb +++ b/spec/collectionspace/mapper/find_replace_operation_spec.rb @@ -9,7 +9,7 @@ let(:creator){ described_class.create(opspec) } context 'given a plain operation' do - let(:opspec){ {find: ' ', replace:'-', type: 'plain'} } + let(:opspec){ {find: ' ', replace: '-', type: 'plain'} } it 'returns a FindReplaceOperation' do expect(creator).to be_a(CS::Mapper::FindReplaceOperation) end @@ -24,7 +24,7 @@ end describe '#perform' do - let(:opspec){ {find: ' ', replace:'-', type: 'plain'} } + let(:opspec){ {find: ' ', replace: '-', type: 'plain'} } let(:result){ operation.perform(value) } context 'given blank value' do let(:value){ '' } @@ -41,4 +41,3 @@ end end end - diff --git a/spec/collectionspace/mapper/find_replace_transformer_spec.rb b/spec/collectionspace/mapper/find_replace_transformer_spec.rb index f15f2fc4..0bef2818 100644 --- a/spec/collectionspace/mapper/find_replace_transformer_spec.rb +++ b/spec/collectionspace/mapper/find_replace_transformer_spec.rb @@ -3,10 +3,12 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::FindReplaceTransformer do - let(:transform) do [ - {find: ' ', replace:'-', type: 'plain'}, - {find: '(\d)-A', replace: '\1 A', type: 'regex'} - ] end + let(:transform) do + [ + {find: ' ', replace: '-', type: 'plain'}, + {find: '(\d)-A', replace: '\1 A', type: 'regex'} + ] + end let(:transformer){ described_class.new(transform: transform) } describe '#precedence' do @@ -33,4 +35,3 @@ end end end - diff --git a/spec/collectionspace/mapper/group_column_value_spec.rb b/spec/collectionspace/mapper/group_column_value_spec.rb index 503432d5..54888525 100644 --- a/spec/collectionspace/mapper/group_column_value_spec.rb +++ b/spec/collectionspace/mapper/group_column_value_spec.rb @@ -5,21 +5,24 @@ RSpec.describe CollectionSpace::Mapper::GroupColumnValue do let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } let(:config){ {delimiter: '|', subgroup_delimiter: '^^'} } - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), - batchconfig: config, - termcache: core_cache) end + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), + batchconfig: config, + termcache: core_cache) + end let(:mapping){ recmapper.mappings.lookup(colname) } - let(:colval) do described_class.new(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:colval) do + described_class.new(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end describe '#split' do let(:colname){ 'title' } let(:colvalue){ 'blah| blah' } it 'returns value as stripped element(s) in Array' do - expect(colval.split).to eq(['blah', 'blah']) + expect(colval.split).to eq(%w[blah blah]) end end end - diff --git a/spec/collectionspace/mapper/group_multival_column_value_spec.rb b/spec/collectionspace/mapper/group_multival_column_value_spec.rb index b13d21ea..93b41894 100644 --- a/spec/collectionspace/mapper/group_multival_column_value_spec.rb +++ b/spec/collectionspace/mapper/group_multival_column_value_spec.rb @@ -5,23 +5,26 @@ RSpec.describe CollectionSpace::Mapper::GroupMultivalColumnValue do let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/bonsai/bonsai_4-1-1_conservation.json' } let(:config){ {delimiter: '|', subgroup_delimiter: '^^'} } - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), - batchconfig: config, - termcache: bonsai_cache) end + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), + batchconfig: config, + termcache: bonsai_cache) + end let(:mapping){ recmapper.mappings.lookup(colname) } - let(:colval) do described_class.new(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:colval) do + described_class.new(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end describe '#split' do let(:colname){ 'fertilizerToBeUsed' } let(:colvalue){ 'a|b^^c' } it 'returns value(s) as Hash where group occurrences are the keys' do expected = {1 => ['a'], - 2 => ['b', 'c']} + 2 => %w[b c]} expect(colval.split).to eq(expected) end end end - diff --git a/spec/collectionspace/mapper/identifiers/short_identifier_spec.rb b/spec/collectionspace/mapper/identifiers/short_identifier_spec.rb index b9a3aab0..97b2d980 100644 --- a/spec/collectionspace/mapper/identifiers/short_identifier_spec.rb +++ b/spec/collectionspace/mapper/identifiers/short_identifier_spec.rb @@ -16,4 +16,3 @@ end end end - diff --git a/spec/collectionspace/mapper/multival_column_value_spec.rb b/spec/collectionspace/mapper/multival_column_value_spec.rb index ec9e7f16..5eb6e631 100644 --- a/spec/collectionspace/mapper/multival_column_value_spec.rb +++ b/spec/collectionspace/mapper/multival_column_value_spec.rb @@ -5,21 +5,24 @@ RSpec.describe CollectionSpace::Mapper::MultivalColumnValue do let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } let(:config){ {delimiter: '|', subgroup_delimiter: '^^'} } - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), - batchconfig: config, - termcache: core_cache) end + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), + batchconfig: config, + termcache: core_cache) + end let(:mapping){ recmapper.mappings.lookup(colname) } - let(:colval) do described_class.new(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:colval) do + described_class.new(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end describe '#split' do let(:colname){ 'collection' } let(:colvalue){ 'blah| blah' } it 'returns value as stripped element(s) in Array' do - expect(colval.split).to eq(['blah', 'blah']) + expect(colval.split).to eq(%w[blah blah]) end end end - diff --git a/spec/collectionspace/mapper/record_mapper_config_spec.rb b/spec/collectionspace/mapper/record_mapper_config_spec.rb index ca4a2f28..7fc4ad63 100644 --- a/spec/collectionspace/mapper/record_mapper_config_spec.rb +++ b/spec/collectionspace/mapper/record_mapper_config_spec.rb @@ -3,15 +3,17 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::RecordMapperConfig do - let(:hash) do {'ns_uri' => { - 'collectionobjects_common' => 'http://collectionspace.org/services/collectionobject', - 'collectionobjects_anthro' => 'http://collectionspace.org/services/collectionobject/domain/anthro', - 'collectionobjects_annotation' => 'http://collectionspace.org/services/collectionobject/domain/annotation', - 'collectionobjects_culturalcare' => 'http://collectionspace.org/services/collectionobject/domain/collectionobject', - 'collectionobjects_nagpra' => 'http://collectionspace.org/services/collectionobject/domain/nagpra', - 'collectionobjects_naturalhistory_extension' => 'http://collectionspace.org/services/collectionobject/domain/naturalhistory_extension', - 'somethingelse_common' => 'http://collectionspace.org/services/collectionobject/domain/nagpra' - }} end + let(:hash) do + {'ns_uri' => { + 'collectionobjects_common' => 'http://collectionspace.org/services/collectionobject', + 'collectionobjects_anthro' => 'http://collectionspace.org/services/collectionobject/domain/anthro', + 'collectionobjects_annotation' => 'http://collectionspace.org/services/collectionobject/domain/annotation', + 'collectionobjects_culturalcare' => 'http://collectionspace.org/services/collectionobject/domain/collectionobject', + 'collectionobjects_nagpra' => 'http://collectionspace.org/services/collectionobject/domain/nagpra', + 'collectionobjects_naturalhistory_extension' => 'http://collectionspace.org/services/collectionobject/domain/naturalhistory_extension', + 'somethingelse_common' => 'http://collectionspace.org/services/collectionobject/domain/nagpra' + }} + end let(:config){ described_class.new(hash) } describe '#namespaces' do it 'returns Array of namespace names' do diff --git a/spec/collectionspace/mapper/regex_find_replace_operation_spec.rb b/spec/collectionspace/mapper/regex_find_replace_operation_spec.rb index faca1d79..ce395e76 100644 --- a/spec/collectionspace/mapper/regex_find_replace_operation_spec.rb +++ b/spec/collectionspace/mapper/regex_find_replace_operation_spec.rb @@ -6,7 +6,7 @@ let(:operation){ described_class.new(opspec) } describe '#perform' do - let(:opspec){ {find: '(az|oo) ', replace:'\1-', type: 'regexp'} } + let(:opspec){ {find: '(az|oo) ', replace: '\1-', type: 'regexp'} } let(:result){ operation.perform(value) } context 'given blank value' do let(:value){ '' } @@ -38,4 +38,3 @@ end end end - diff --git a/spec/collectionspace/mapper/row_data_spec.rb b/spec/collectionspace/mapper/row_data_spec.rb index 5c034a8d..8e931f0b 100644 --- a/spec/collectionspace/mapper/row_data_spec.rb +++ b/spec/collectionspace/mapper/row_data_spec.rb @@ -3,13 +3,15 @@ require 'spec_helper' RSpec.describe CollectionSpace::Mapper::RowData do - let(:recmapper){ core_object_mapper} - let(:data_hash) do { - 'objectNumber' => '123', - 'comment' => 'blah', - 'title' => 'The title', - 'titleTranslation' => 'La title' - } end + let(:recmapper){ core_object_mapper } + let(:data_hash) do + { + 'objectNumber' => '123', + 'comment' => 'blah', + 'title' => 'The title', + 'titleTranslation' => 'La title' + } + end let(:row){ CollectionSpace::Mapper::RowData.new(data_hash, recmapper) } @@ -19,7 +21,7 @@ expect(row.columns).to be_a(Array) end it 'of ColumnValues' do - expect(row.columns.any?{ |col| !col.kind_of?(CS::Mapper::ColumnValue)}).to be false + expect(row.columns.any?{ |col| !col.is_a?(CS::Mapper::ColumnValue) }).to be false end it '2 elements long' do expect(row.columns.length).to eq(4) diff --git a/spec/collectionspace/mapper/subgroup_column_value_spec.rb b/spec/collectionspace/mapper/subgroup_column_value_spec.rb index 1643c0b7..d0efb81e 100644 --- a/spec/collectionspace/mapper/subgroup_column_value_spec.rb +++ b/spec/collectionspace/mapper/subgroup_column_value_spec.rb @@ -5,23 +5,26 @@ RSpec.describe CollectionSpace::Mapper::SubgroupColumnValue do let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } let(:config){ {delimiter: '|', subgroup_delimiter: '^^'} } - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), - batchconfig: config, - termcache: core_cache) end + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper(mapperpath), + batchconfig: config, + termcache: core_cache) + end let(:mapping){ recmapper.mappings.lookup(colname) } - let(:colval) do described_class.new(column: colname, - value: colvalue, - recmapper: recmapper, - mapping: mapping) end + let(:colval) do + described_class.new(column: colname, + value: colvalue, + recmapper: recmapper, + mapping: mapping) + end describe '#split' do let(:colname){ 'titleTranslation' } let(:colvalue){ 'a|b^^c' } it 'returns value(s) as Hash where group occurrences are the keys' do expected = {1 => ['a'], - 2 => ['b', 'c']} + 2 => %w[b c]} expect(colval.split).to eq(expected) end end end - diff --git a/spec/collectionspace/mapper/term_handler_spec.rb b/spec/collectionspace/mapper/term_handler_spec.rb index cc11aec8..94ef01a1 100644 --- a/spec/collectionspace/mapper/term_handler_spec.rb +++ b/spec/collectionspace/mapper/term_handler_spec.rb @@ -6,17 +6,21 @@ let(:client){ core_client } let(:termcache){ core_cache } let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' } - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), - csclient: client, - termcache: termcache) end + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), + csclient: client, + termcache: termcache) + end let(:colmapping){ recmapper.mappings.lookup(colname) } - let(:th) do CS::Mapper::TermHandler.new(mapping: colmapping, - data: data, - client: client, - cache: termcache, - mapper: recmapper) end - # before(:all) do -# @config = @handler.mapper.batchconfig + let(:th) do + CS::Mapper::TermHandler.new(mapping: colmapping, + data: data, + client: client, + cache: termcache, + mapper: recmapper) + end + # before(:all) do + # @config = @handler.mapper.batchconfig # @ref_mapping = CollectionSpace::Mapper::ColumnMapping.new({ # :fieldname=>"reference", # :transforms=>{:authority=>["citationauthorities", "citation"]}, @@ -53,48 +57,48 @@ # end describe '#result' do - context 'titletranslationlanguage (vocabulary, field subgroup)' do - let(:colname){ 'titleTranslationLanguage' } - let(:data){ [['%NULLVALUE%', 'Swahili'], ['Klingon', 'Spanish'], [CS::Mapper::THE_BOMB]] } + context 'titletranslationlanguage (vocabulary, field subgroup)' do + let(:colname){ 'titleTranslationLanguage' } + let(:data){ [['%NULLVALUE%', 'Swahili'], %w[Klingon Spanish], [CS::Mapper::THE_BOMB]] } - it 'result is the transformed value for mapping' do - expected = [['', - "urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(swa)'Swahili'"], - ["urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(Klingon)'Klingon'", - "urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(spa)'Spanish'"], - [CS::Mapper::THE_BOMB]] - expect(th.result).to eq(expected) - end - it 'all values are refnames, blanks, or the bomb' do - chk = th.result.flatten.select{ |v| v.start_with?('urn:') || v.empty? || v = CS::Mapper::THE_BOMB } - expect(chk.length).to eq(5) - end + it 'result is the transformed value for mapping' do + expected = [['', + "urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(swa)'Swahili'"], + ["urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(Klingon)'Klingon'", + "urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(spa)'Spanish'"], + [CS::Mapper::THE_BOMB]] + expect(th.result).to eq(expected) end + it 'all values are refnames, blanks, or the bomb' do + chk = th.result.flatten.select{ |v| v.start_with?('urn:') || v.empty? || v = CS::Mapper::THE_BOMB } + expect(chk.length).to eq(5) + end + end - context 'reference (authority, field group)' do - let(:colname){ 'referenceLocal' } - let(:data){ ['Reference 1', 'Reference 2', '%NULLVALUE%'] } + context 'reference (authority, field group)' do + let(:colname){ 'referenceLocal' } + let(:data){ ['Reference 1', 'Reference 2', '%NULLVALUE%'] } - it 'result is the transformed value for mapping' do - expected = [ - "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(Reference11143445083)'Reference 1'", - "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(Reference22573957271)'Reference 2'", - '' - ] - expect(th.result).to eq(expected) - end - it 'all values are refnames' do - chk = th.result.flatten.select{ |v| v.start_with?('urn:') } - expect(chk.length).to eq(2) - end + it 'result is the transformed value for mapping' do + expected = [ + "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(Reference11143445083)'Reference 1'", + "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(Reference22573957271)'Reference 2'", + '' + ] + expect(th.result).to eq(expected) + end + it 'all values are refnames' do + chk = th.result.flatten.select{ |v| v.start_with?('urn:') } + expect(chk.length).to eq(2) end end + end describe '#terms' do let(:terms){ th.terms } context 'titletranslationlanguage (vocabulary, field subgroup)' do let(:colname){ 'titleTranslationLanguage' } - let(:data){ [['%NULLVALUE%', 'Swahili'], ['Sanza', 'Spanish'], [CS::Mapper::THE_BOMB]] } + let(:data){ [['%NULLVALUE%', 'Swahili'], %w[Sanza Spanish], [CS::Mapper::THE_BOMB]] } context 'when new term (Sanza) is initially encountered' do it 'returns terms as expected' do diff --git a/spec/collectionspace/mapper/term_searchable_spec.rb b/spec/collectionspace/mapper/term_searchable_spec.rb index d78a2239..3401708b 100644 --- a/spec/collectionspace/mapper/term_searchable_spec.rb +++ b/spec/collectionspace/mapper/term_searchable_spec.rb @@ -5,6 +5,7 @@ class TermClass attr_reader :cache, :client attr_accessor :type, :subtype, :errors + include CS::Mapper::TermSearchable def initialize(cache, client, type, subtype) @@ -14,7 +15,6 @@ def initialize(cache, client, type, subtype) @subtype = subtype @errors = [] end - end RSpec.describe CollectionSpace::Mapper::TermSearchable do @@ -138,7 +138,7 @@ def initialize(cache, client, type, subtype) context 'when in cache' do let(:val){ 'Sample Concept 1' } it 'returns csid' do - # it 'returns csid', :skip => 'does not cause mapping to fail, so we live with technical incorrectness for now' do + # it 'returns csid', :skip => 'does not cause mapping to fail, so we live with technical incorrectness for now' do expect(result).to eq('1111-2222-3333-4444') end end diff --git a/spec/collectionspace/mapper/tools/record_status_service_spec.rb b/spec/collectionspace/mapper/tools/record_status_service_spec.rb index d526e9b6..dfc1eeb8 100644 --- a/spec/collectionspace/mapper/tools/record_status_service_spec.rb +++ b/spec/collectionspace/mapper/tools/record_status_service_spec.rb @@ -7,21 +7,26 @@ let(:service){ CollectionSpace::Mapper::Tools::RecordStatusService.new(client, mapper) } context 'when mapper service_path not handled by collectionspace-client' do - let(:mapper) do CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper( - 'spec/fixtures/files/mappers/core_6-1-0_aardvark.json' - ), termcache: core_cache) end + let(:mapper) do + CS::Mapper::RecordMapper.new(mapper: get_json_record_mapper( + 'spec/fixtures/files/mappers/core_6-1-0_aardvark.json' + ), termcache: core_cache) + end it 'raises NoClientServiceError' do expect do - CS::Mapper::Tools::RecordStatusService.new(client, mapper) end.to raise_error(CS::Mapper::NoClientServiceError) + CS::Mapper::Tools::RecordStatusService.new(client, mapper) + end.to raise_error(CS::Mapper::NoClientServiceError) end end describe '#lookup' do context 'when mapper is for an authority' do - let(:mapper) do CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( - 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_person-local.json' - ), termcache: core_cache) end + let(:mapper) do + CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( + 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_person-local.json' + ), termcache: core_cache) + end context 'and one result is found' do let(:report){ service.lookup('John Doe') } @@ -55,7 +60,8 @@ context 'with default config' do it 'raises error because we cannot know what to do with imported record' do expect do - service.lookup('Inkpot Guineafowl') end.to raise_error(CollectionSpace::Mapper::MultipleCsRecordsFoundError) + service.lookup('Inkpot Guineafowl') + end.to raise_error(CollectionSpace::Mapper::MultipleCsRecordsFoundError) end end @@ -79,9 +85,11 @@ end context 'when mapper is for an object' do - let(:mapper) do CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( - 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' - ), termcache: core_cache) end + let(:mapper) do + CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( + 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_collectionobject.json' + ), termcache: core_cache) + end it 'works the same' do res = service.lookup('2000.1') @@ -90,9 +98,11 @@ end context 'when mapper is for a procedure' do - let(:mapper) do CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( - 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_acquisition.json' - ), termcache: core_cache) end + let(:mapper) do + CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( + 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_acquisition.json' + ), termcache: core_cache) + end it 'works the same' do res = service.lookup('2000.001') @@ -101,9 +111,11 @@ end context 'when mapper is for a relationship' do - let(:mapper) do CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( - 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_objecthierarchy.json' - )) end + let(:mapper) do + CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper( + 'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_objecthierarchy.json' + )) + end it 'works the same' do res = service.lookup({sub: '56c04f5f-32b9-4f1d-8a4b', obj: '6f0ce7b3-0130-444d-8633'}) diff --git a/spec/collectionspace/mapper/tools/refname_spec.rb b/spec/collectionspace/mapper/tools/refname_spec.rb index da906255..5e4ce16e 100644 --- a/spec/collectionspace/mapper/tools/refname_spec.rb +++ b/spec/collectionspace/mapper/tools/refname_spec.rb @@ -80,7 +80,8 @@ urn: 'urn:cspace:core.collectionspace.org:weird' } expect do - CollectionSpace::Mapper::Tools::RefName.new(args) end.to raise_error(CollectionSpace::Mapper::Tools::UnparseableUrnError) + CollectionSpace::Mapper::Tools::RefName.new(args) + end.to raise_error(CollectionSpace::Mapper::Tools::UnparseableUrnError) end end end @@ -92,8 +93,8 @@ cache: @cache } expect do - CollectionSpace::Mapper::Tools::RefName.new(args) end.to raise_error(CollectionSpace::Mapper::Tools::RefNameArgumentError) + CollectionSpace::Mapper::Tools::RefName.new(args) + end.to raise_error(CollectionSpace::Mapper::Tools::RefNameArgumentError) end end end - diff --git a/spec/collectionspace/mapper/tools/symbolizable_spec.rb b/spec/collectionspace/mapper/tools/symbolizable_spec.rb index e29ee50c..47b5154d 100644 --- a/spec/collectionspace/mapper/tools/symbolizable_spec.rb +++ b/spec/collectionspace/mapper/tools/symbolizable_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe CS::Mapper::Tools::Symbolizable do - let(:config) do JSON.parse('{ + let(:config) do + JSON.parse('{ "delimiter": ";", "subgroup_delimiter": "^^", "response_mode": "verbose", "force_defaults": false, "check_record_status": true, - "check_terms": true, "date_format": "month day year", "two_digit_year_handling": "convert to four digit", "transforms": { @@ -35,20 +35,19 @@ describe '#symbolize' do it 'turns hash keys into symbols' do expected = %i[delimiter subgroup_delimiter response_mode force_defaults check_record_status - check_terms date_format two_digit_year_handling transforms default_values] + date_format two_digit_year_handling transforms default_values] expect(symconfig.keys).to eq(expected) end end describe '#symbolize_transforms' do let(:transforms){ symconfig[:transforms] } - let(:expected) do {'collection' => {special: ['downcase_value'], - replacements: [{find: ' ', replace: '-', type: 'plain'}] - }} + let(:expected) do + {'collection' => {special: ['downcase_value'], + replacements: [{find: ' ', replace: '-', type: 'plain'}]}} end it 'transforms as expected' do expect(CS::Mapper::Tools::Symbolizable.symbolize_transforms(transforms)).to eq(expected) end end end - diff --git a/spec/collectionspace/mapper/transformer_spec.rb b/spec/collectionspace/mapper/transformer_spec.rb index 57f6bd26..37fc25a8 100644 --- a/spec/collectionspace/mapper/transformer_spec.rb +++ b/spec/collectionspace/mapper/transformer_spec.rb @@ -5,19 +5,23 @@ RSpec.describe CollectionSpace::Mapper::Transformer do let(:client){ anthro_client } let(:cache){ anthro_cache } - let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject_transforms.json'} - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), - csclient: client, - termcache: cache) end + let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject_transforms.json' } + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), + csclient: client, + termcache: cache) + end describe '.create' do - let(:creator) do described_class.create(recmapper: recmapper, - type: type, - transform: transform) end + let(:creator) do + described_class.create(recmapper: recmapper, + type: type, + transform: transform) + end context 'given an authority transform' do let(:type){ :authority } - let(:transform){ ['personauthorities', 'person'] } + let(:transform){ %w[personauthorities person] } it 'returns an AuthorityTransformer' do expect(creator).to be_a(CS::Mapper::AuthorityTransformer) @@ -34,7 +38,7 @@ context 'given special transforms' do let(:type){ :special } - let(:transform){ ['downcase_value', 'boolean', 'behrensmeyer_translate'] } + let(:transform){ %w[downcase_value boolean behrensmeyer_translate] } it 'returns array of expected transformers' do expected = [CS::Mapper::DowncaseTransformer, CS::Mapper::BooleanTransformer, CS::Mapper::BehrensmeyerTransformer] diff --git a/spec/collectionspace/mapper/transformers_spec.rb b/spec/collectionspace/mapper/transformers_spec.rb index 6d9804af..c89ecc43 100644 --- a/spec/collectionspace/mapper/transformers_spec.rb +++ b/spec/collectionspace/mapper/transformers_spec.rb @@ -5,14 +5,18 @@ RSpec.describe CollectionSpace::Mapper::Transformers do let(:client){ anthro_client } let(:cache){ anthro_cache } - let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject_transforms.json'} - let(:recmapper) do CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), - csclient: client, - termcache: cache) end + let(:mapperpath){ 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject_transforms.json' } + let(:recmapper) do + CS::Mapper::RecordMapper.new(mapper: File.read(mapperpath), + csclient: client, + termcache: cache) + end let(:mapping){ recmapper.mappings.lookup(colname) } - let(:xforms) do described_class.new(colmapping: mapping, - transforms: mapping.transforms, - recmapper: recmapper) end + let(:xforms) do + described_class.new(colmapping: mapping, + transforms: mapping.transforms, + recmapper: recmapper) + end describe '#queue' do context 'when measuredByPerson column' do diff --git a/spec/collectionspace/mapper/value_transformer_spec.rb b/spec/collectionspace/mapper/value_transformer_spec.rb index 9c85d7a5..ae00bd6f 100644 --- a/spec/collectionspace/mapper/value_transformer_spec.rb +++ b/spec/collectionspace/mapper/value_transformer_spec.rb @@ -4,15 +4,15 @@ RSpec.describe CollectionSpace::Mapper::ValueTransformer do before(:all) do - client = anthro_client - cache = anthro_cache - mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject.json') - handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, - client: client, - cache: cache, - config: {}) - @prepper = CollectionSpace::Mapper::DataPrepper.new({}, handler) - end + client = anthro_client + cache = anthro_cache + mapper = get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/anthro/anthro_4-1-2_collectionobject.json') + handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, + client: client, + cache: cache, + config: {}) + @prepper = CollectionSpace::Mapper::DataPrepper.new({}, handler) + end context 'when vocabulary' do context 'and vocabulary is behrensmeyer number' do @@ -32,8 +32,7 @@ transforms = {vocabulary: 'agerange', special: %w[downcase_value], replacements: [ {find: ' - ', replace: '-', type: :plain} - ] - } + ]} res = CollectionSpace::Mapper::ValueTransformer.new(value, transforms, @prepper).result ex = 'adolescent 26-75%' expect(res).to eq(ex) @@ -57,6 +56,3 @@ end end end - - - diff --git a/spec/collectionspace/mapper_spec.rb b/spec/collectionspace/mapper_spec.rb index 99fadf5e..e2d5ab31 100644 --- a/spec/collectionspace/mapper_spec.rb +++ b/spec/collectionspace/mapper_spec.rb @@ -11,13 +11,13 @@ context 'when passed a CollectionSpace::Mapper::Response' do it 'returns that Response' do response = CollectionSpace::Mapper::Response.new({'objectNumber' => '123'}) - expect(CollectionSpace::Mapper::setup_data(response)).to eq(response) + expect(CollectionSpace::Mapper.setup_data(response)).to eq(response) end end context 'when passed a Hash' do before(:all) do @data = {'objectNumber' => '123'} - @response = CollectionSpace::Mapper::setup_data(@data) + @response = CollectionSpace::Mapper.setup_data(@data) end it 'returns a CollectionSpace::Mapper::Response with expected orig_data' do expect(@response).to be_a(CollectionSpace::Mapper::Response) @@ -26,10 +26,11 @@ end context 'when passed other class of object' do it 'returns a CollectionSpace::Mapper::Response' do - data = ['objectNumber', '123'] + data = %w[objectNumber 123] expect do - CollectionSpace::Mapper::setup_data(data) end.to raise_error(CollectionSpace::Mapper::Errors::UnprocessableDataError, - 'Cannot process a Array. Need a Hash or Mapper::Response') + CollectionSpace::Mapper.setup_data(data) + end.to raise_error(CollectionSpace::Mapper::Errors::UnprocessableDataError, + 'Cannot process a Array. Need a Hash or Mapper::Response') end end end diff --git a/spec/core_helpers.rb b/spec/core_helpers.rb index 6df0e4a2..f9379a39 100644 --- a/spec/core_helpers.rb +++ b/spec/core_helpers.rb @@ -133,7 +133,7 @@ def populate_core(cache) {refname: "urn:cspace:core.collectionspace.org:orgauthorities:name(ulan_oa):item:name(Signal1599559737158)'Signal'", csid: '1111-2222-3333-4444'}], ['orgauthorities', 'ulan_oa', 'Very fats', {refname: "urn:cspace:core.collectionspace.org:orgauthorities:name(ulan_oa):item:name(Veryfats1599645188567)'Very fats'", csid: '1111-2222-3333-4444'}], - ['personauthorities', 'person', 'Broooks', + ['personauthorities', 'person', 'Broooks', {refname: "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(Broooks1599221558583)'Broooks'", csid: '1111-2222-3333-4444'}], ['personauthorities', 'person', '2020', {refname: "urn:cspace:core.collectionspace.org:personauthorities:name(person):item:name(20201599147149106)'2020'", csid: '1111-2222-3333-4444'}], @@ -404,7 +404,7 @@ def populate_core(cache) ['vocabularies', 'uocusertypes', 'lecturer', {refname: "urn:cspace:core.collectionspace.org:vocabularies:name(uocusertypes):item:name(lecturer)'lecturer'", csid: '1111-2222-3333-4444'}], ['workauthorities', 'work', 'Makeup', - {refname: "urn:cspace:core.collectionspace.org:workauthorities:name(work):item:name(Makeup1608768998350)'Makeup'", csid: '1111-2222-3333-4444'}], + {refname: "urn:cspace:core.collectionspace.org:workauthorities:name(work):item:name(Makeup1608768998350)'Makeup'", csid: '1111-2222-3333-4444'}] ] populate(cache, terms) end diff --git a/spec/fcart_helpers.rb b/spec/fcart_helpers.rb index 549d4152..90ec898d 100644 --- a/spec/fcart_helpers.rb +++ b/spec/fcart_helpers.rb @@ -22,8 +22,8 @@ def fcart_cache def populate_fcart(cache) terms = [ ['personauthorities', 'person', 'Elizabeth', - {refname: "urn:cspace:fcart.collectionspace.org:personauthorities:name(person):item:name(Elizabeth123)'Elizabeth'", csid: '1111-2222-3333-4444'}] ] + {refname: "urn:cspace:fcart.collectionspace.org:personauthorities:name(person):item:name(Elizabeth123)'Elizabeth'", csid: '1111-2222-3333-4444'}] + ] populate(cache, terms) end - end diff --git a/spec/helpers.rb b/spec/helpers.rb index 01764788..968ae08e 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -66,9 +66,7 @@ def get_xml_fixture(filename, remove_blanks = true) rejectfields = %w[computedCurrentLocation].sort doc.traverse do |node| # Drop empty nodes - if remove_blanks - node.remove unless node.text.match?(/\S/m) - end + node.remove if remove_blanks && !node.text.match?(/\S/m) # Drop sections of the document we don't write with the mapper node.remove if node.name == 'collectionspace_core' || node.name == 'account_permission' # Drop fields created by CS application @@ -107,22 +105,20 @@ def mapper_defined_paths(xpaths, mappings) end def remove_xpath_occurrence_indicators(path) - path.match(/^(.*)\//)[1].gsub(/\[\d+\]/, '') + path.match(%r{^(.*)/})[1].gsub(/\[\d+\]/, '') end def list_xpaths(doc) xpaths = get_xpaths(doc) - xpaths = field_value_xpaths(xpaths) - xpaths + field_value_xpaths(xpaths) end def standardize_value(string) if string.start_with?('urn:cspace') - val = string.sub(/(item:name\([a-zA-Z]+)\d+(\)')/, '\1\2') + string.sub(/(item:name\([a-zA-Z]+)\d+(\)')/, '\1\2') else - val = string + string end - val end def populate(cache, terms) @@ -131,5 +127,4 @@ def populate(cache, terms) end cache end - end diff --git a/spec/lhmc_helpers.rb b/spec/lhmc_helpers.rb index 0855f2e4..4163ffaf 100644 --- a/spec/lhmc_helpers.rb +++ b/spec/lhmc_helpers.rb @@ -24,7 +24,7 @@ def populate_lhmc(cache) ['personauthorities', 'person', 'Ann Analyst', {refname: "urn:cspace:lhmc.collectionspace.org:personauthorities:name(person):item:name(AnnAnalyst1594848799340)'Ann Analyst'", csid: '1111-2222-3333-4444'}], ['vocabularies', 'agerange', 'adolescent 26-75%', - {refname: "urn:cspace:lhmc.collectionspace.org:vocabularies:name(agerange):item:name(adolescent_26_75)'adolescent 26-75%'", csid: '1111-2222-3333-4444'}], + {refname: "urn:cspace:lhmc.collectionspace.org:vocabularies:name(agerange):item:name(adolescent_26_75)'adolescent 26-75%'", csid: '1111-2222-3333-4444'}] ] populate(cache, terms) end diff --git a/utils/benchmarking/profile.rb b/utils/benchmarking/profile.rb index c6864da2..26d12602 100644 --- a/utils/benchmarking/profile.rb +++ b/utils/benchmarking/profile.rb @@ -23,9 +23,7 @@ def mapping_workflow v_result = handler.validate(datahash) - if v_result.valid? - result = handler.process(datahash) - end + result = handler.process(datahash) if v_result.valid? result end diff --git a/utils/csv-to-datahashes.rb b/utils/csv-to-datahashes.rb index fe05ffbc..2648ea9f 100644 --- a/utils/csv-to-datahashes.rb +++ b/utils/csv-to-datahashes.rb @@ -38,8 +38,8 @@ datahashes = [] -filename_stub = options[:input].sub(/^.*\//, '').sub('.csv', '') -dir = options[:input]['/'] ? options[:input].sub(/\/[^\/]+$/, '/') : '' +filename_stub = options[:input].sub(%r{^.*/}, '').sub('.csv', '') +dir = options[:input]['/'] ? options[:input].sub(%r{/[^/]+$}, '/') : '' CSV.foreach(options[:input], headers: true) do |row| datahashes << row.to_h diff --git a/utils/datahash_to_csv.rb b/utils/datahash_to_csv.rb index 347d3bdc..04e780cd 100644 --- a/utils/datahash_to_csv.rb +++ b/utils/datahash_to_csv.rb @@ -36,8 +36,8 @@ end end.parse! -dir = options[:input]['/'] ? options[:input].sub(/\/[^\/]+$/, '/') : '' -filename_stub = options[:input].sub(/^.*\//, '').sub('.json', '') +dir = options[:input]['/'] ? options[:input].sub(%r{/[^/]+$}, '/') : '' +filename_stub = options[:input].sub(%r{^.*/}, '').sub('.json', '') csv_file = "#{dir}#{filename_stub}.csv" data = JSON.parse(File.read(options[:input]))