Skip to content

Commit

Permalink
rubocop autocorrects
Browse files Browse the repository at this point in the history
  • Loading branch information
kspurgin committed Jan 20, 2022
1 parent 32bd7d1 commit dddd277
Show file tree
Hide file tree
Showing 42 changed files with 867 additions and 685 deletions.
6 changes: 3 additions & 3 deletions collectionspace-mapper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'

spec.required_ruby_version = '>= 2.7.4'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
Expand Down Expand Up @@ -53,6 +53,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rubocop', '~> 1.18.3'

# Uncomment these if you need to use the scripts in utils/benchmarking
#spec.add_development_dependency 'ruby-prof', '~> 1.4.3'
#spec.add_development_dependency 'time_up', '~> 0.0.7'
# spec.add_development_dependency 'ruby-prof', '~> 1.4.3'
# spec.add_development_dependency 'time_up', '~> 0.0.7'
end
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Mapper
# :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,
:record_type
:check_record_status, :check_terms, :date_format, :two_digit_year_handling, :transforms, :default_values,
:record_type
# todo: move default config in here
include Tools::Symbolizable

Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/mapper/data_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def set_record_status(response)
status = searchresult[:status]
response.record_status = status
return if status == :new

response.csid = searchresult[:csid]
response.uri = searchresult[:uri]
response.refname = searchresult[:refname]
Expand Down
20 changes: 10 additions & 10 deletions lib/collectionspace/mapper/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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

Expand Down Expand Up @@ -153,7 +153,7 @@ def do_subgroup_splits(xphash)
@response.split_data[column] = CollectionSpace::Mapper::SubgroupSplitter.new(data, config).result
end
end

def do_transforms(xphash)
splitdata = @response.split_data
targetdata = @response.transformed_data
Expand Down Expand Up @@ -255,10 +255,10 @@ def structured_date_transform(data)
@cache,
@handler.mapper.batchconfig).mappable
else
d.map{ |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v,
@client,
@cache,
@handler.mapper.batchconfig).mappable }
d.map do |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v,
@client,
@cache,
@handler.mapper.batchconfig).mappable end
end
end
end
Expand All @@ -271,10 +271,10 @@ def unstructured_date_transform(data)
@cache,
@handler.mapper.batchconfig).stamp
else
d.map{ |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v,
@client,
@cache,
@handler.mapper.batchconfig).stamp }
d.map do |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v,
@client,
@cache,
@handler.mapper.batchconfig).stamp end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_rec_csid(id, type)
instance_variable_set(:@type, type)
obj_csid(id, type)
end

def transform_terms
%w[item1_id item2_id].each_with_index do |field, i|
transformed = @response.split_data[field].map{ |id| get_rec_csid(id, @types[i]) }
Expand Down
3 changes: 1 addition & 2 deletions lib/collectionspace/mapper/term_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def handle_term(val)
field: column
}


if in_cache?(val)
refname_urn = cached_term(val, :refname)
if refname_urn
Expand Down Expand Up @@ -110,7 +109,7 @@ def add_new_unknown_term(val, term_report)

def add_known_unknown_term(val, term_report)
refname_url = cached_term(val, :refname, 'unknownvalue', "#{type}/#{subtype}")
#refname_url = @cache.get('unknownvalue', type_subtype, val)[:refname]
# refname_url = @cache.get('unknownvalue', type_subtype, val)[:refname]
refname_obj = CollectionSpace::Mapper::Tools::RefName.new(urn: refname_url)
@terms << term_report.merge({found: false, refname: refname_obj})
add_missing_record_error('term', val)
Expand Down
179 changes: 89 additions & 90 deletions lib/collectionspace/mapper/term_searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def cached_as_unknown?(val)
end

private def type_subtype
"#{type}/#{subtype}"
"#{type}/#{subtype}"
end

# returns refName of cached term
Expand All @@ -32,62 +32,61 @@ def cached_term(val, return_key = :refname, termtype = type, termsubtype = subty
end

private def convert_cached_value(cache_response)
return cache_response if cache_response.is_a?(Hash)
return cache_response if cache_response.is_a?(Hash)

instance_eval(cache_response)
instance_eval(cache_response)
end

# returns refName of searched (term)
def searched_term(val, return_key = :refname)
response = term_search_response(val)

rec = rec_from_response('term', val, response)
return nil unless rec

cache_value = { refname: rec['refName'], csid: rec['csid'] }
cache_value = {refname: rec['refName'], csid: rec['csid']}
@cache.put(type, subtype, val, cache_value)
cache_value[return_key]
end

private def case_swap(string)
string.match?(/[A-Z]/) ? string.downcase : string.capitalize
string.match?(/[A-Z]/) ? string.downcase : string.capitalize
end


private def term_search_response(val)
as_is = get_term_response(val)
return as_is if term_response_usable?(as_is)
as_is = get_term_response(val)
return as_is if term_response_usable?(as_is)

get_term_response(case_swap(val))
get_term_response(case_swap(val))
end

private def get_term_response(val)
response = @client.find(
type: type,
subtype: subtype,
value: val,
field: search_field
)
rescue StandardError => e
puts e.message
nil
else
parse_response(response)
response = @client.find(
type: type,
subtype: subtype,
value: val,
field: search_field
)
rescue StandardError => e
puts e.message
nil
else
parse_response(response)
end

private def parse_response(response)
parsed = response.parsed['abstract_common_list']
rescue StandardError => e
puts e.message
nil
else
parsed
parsed = response.parsed['abstract_common_list']
rescue StandardError => e
puts e.message
nil
else
parsed
end

def obj_csid(objnum, type)
cached = @cache.get(type, '', objnum, search: false)
return convert_cached_value(cached)[:csid] if cached

lookup_obj_or_procedure_csid(objnum, type)
end

Expand All @@ -99,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 << {
Expand All @@ -122,76 +121,76 @@ def term_csid(term)
end

private def term_response_usable?(response)
ct = response_item_count(response)
return false unless ct
return false if ct == 0
ct = response_item_count(response)
return false unless ct
return false if ct == 0

true
true
end

private def response_item_count(response)
ct = response.dig('totalItems')
return ct.to_i if ct
ct = response.dig('totalItems')
return ct.to_i if ct

nil
nil
end

private def add_missing_record_error(category, val)
datacolumn = column ||= 'data'
errors << {
category: "no_records_found_for_#{category}".to_sym,
field: '',
type: '',
subtype: '',
value: val,
message: "#{val} (#{type_subtype} in #{datacolumn} column)"
}
datacolumn = column ||= 'data'

errors << {
category: "no_records_found_for_#{category}".to_sym,
field: '',
type: '',
subtype: '',
value: val,
message: "#{val} (#{type_subtype} in #{datacolumn} column)"
}
end

private def rec_from_response(category, val, response)
term_ct = response_item_count(response)

unless term_ct
errors << {
category: "unsuccessful_csid_lookup_for_#{category}".to_sym,
field: '',
type: type,
subtype: subtype,
value: val,
message: "Problem with search for #{val}"
}
return nil
end

case term_ct
when 0
add_missing_record_error(category, val)
rec = nil
when 1
rec = response['list_item']
else
rec = response['list_item'][0]
using_uri = "#{@client.config.base_uri}#{rec['uri']}"
warnings << {
category: "multiple_records_found_for_#{category}".to_sym,
field: '',
type: type,
subtype: subtype,
value: val,
message: "#{term_ct} records found. Using #{using_uri}"
}
end

rec
term_ct = response_item_count(response)

unless term_ct
errors << {
category: "unsuccessful_csid_lookup_for_#{category}".to_sym,
field: '',
type: type,
subtype: subtype,
value: val,
message: "Problem with search for #{val}"
}
return nil
end

case term_ct
when 0
add_missing_record_error(category, val)
rec = nil
when 1
rec = response['list_item']
else
rec = response['list_item'][0]
using_uri = "#{@client.config.base_uri}#{rec['uri']}"
warnings << {
category: "multiple_records_found_for_#{category}".to_sym,
field: '',
type: type,
subtype: subtype,
value: val,
message: "#{term_ct} records found. Using #{using_uri}"
}
end

rec
end

private def search_field
field = CollectionSpace::Service.get(type: type)[:term]
rescue StandardError => e
puts e.message
else
field
field = CollectionSpace::Service.get(type: type)[:term]
rescue StandardError => e
puts e.message
else
field
end

# added toward refactoring that isn't done yet
Expand Down
8 changes: 4 additions & 4 deletions lib/collectionspace/mapper/tools/record_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def lookup(value)

item = response.parsed[@response_top][@response_nested].first
num_found = response.parsed[@response_top][@response_nested].length
reportable_result(item).merge({ multiple_recs_found: num_found})
reportable_result(item).merge({multiple_recs_found: num_found})
end
end

private

def reportable_result(item = nil)
return { status: :new } unless item
return {status: :new} unless item

{
status: :existing,
Expand All @@ -62,7 +62,7 @@ def reportable_result(item = nil)
refname: item['refName']
}
end

def lookup_non_relationship(value)
@client.find(
type: @mapper.config.service_path,
Expand All @@ -77,7 +77,7 @@ def use_first?

false
end

def count_results(response)
unless response.result.success?
raise CollectionSpace::RequestError, response.result.body
Expand Down
Loading

0 comments on commit dddd277

Please sign in to comment.