Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for 04x methods #130

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 35 additions & 77 deletions lib/marc_cleanup/variable_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,78 +127,35 @@ def f041_errors?(record)
f041.each do |field|
field.subfields.each do |subfield|
val = subfield.value
return true if (val.size > 3) && (val.size % 3 == 0)
return true if (val.size > 3) && (val.size % 3).zero?
end
end
false
end

# http://www.loc.gov/standards/valuelist/marcauthen.html
def auth_codes_042
def auth_codes_f042
%w[
anuc
croatica
dc
dhca
dlr
gamma
gils
gnd1
gnd2
gnd3
gnd4
gnd5
gnd6
gnd7
gndz
isds/c
issnuk
lacderived
lc
lcac
lccopycat
lccopycat-nm
lcd
lcderive
lchlas
lcllh
lcnccp
lcnitrate
lcnuc
lcode
msc
natgaz
nbr
nlc
nlmcopyc
norbibl
nsdp
nst
ntccf
nznb
pcc
premarc
reveal
sanb
scipio
toknb
ukblcatcopy
ukblderived
ukblproject
ukblsr
ukscp
xisds/c
xissnuk
xlc
xnlc
xnsdp
anuc croatica dc dhca dlr
gamma gils gnd1 gnd2 gnd3 gnd4 gnd5 gnd6 gnd7 gndz isds/c issnuk
lacderived lc lcac lccopycat lccopycat-nm lcd lcderive
lchlas lcllh lcnccp lcnitrate lcnuc lcode
msc natgaz nbr nlc nlmcopyc norbibl nsdp nst ntccf nznb
pcc premarc reveal sanb scipio toknb
ukblcatcopy ukblderived ukblproject ukblsr ukscp
xisds/c xissnuk xlc xnlc xnsdp
]
end

def auth_code_error?(record)
return false unless record['042']
return true if record.fields('042').size > 1

auth_codes_042.include?(record['042']['a']) ? false : true
record['042'].subfields.each do |subfield|
next if subfield.code != 'a'
return true unless auth_codes_f042.include?(subfield.value)
end
false
end

def invalid_indicators?(record)
Expand Down Expand Up @@ -265,8 +222,7 @@ def extra_spaces?(record)
end

def multiple_no_040?(record)
f040 = record.fields('040')
f040.size != 1
record.fields('040').size != 1
end

def multiple_no_040b?(record)
Expand All @@ -277,18 +233,19 @@ def multiple_no_040b?(record)
b040 = f040.subfields.select { |subfield| subfield.code == 'b' }
return true if b040.size != 1

b040 = b040.first.value
b040.gsub!(/[ ]/, '')
b040 == ''
b040.first.value.match?(/^\s*$/)
end

def f046_subfield_errors?(record)
def f046_errors?(record)
subf_codes = %w[b c d e]
subf_a_values = %w[r s p t x q n i k r m t x n]
f046 = record.fields('046')
return false if f046.empty?

f046.each do |field|
subf_codes = field.subfields.map { |subfield| subfield.code }
return true if field['a'].nil? && (subf_codes & %w[b c d e]).size > 0
codes = field.subfields.map(&:code)
return true if field['a'] && !subf_a_values.include?(field['a'])
return true if field['a'].nil? && (subf_codes & codes).size.positive?
end
false
end
Expand Down Expand Up @@ -559,15 +516,14 @@ def uri_escape(record)

### Make the 040 $b 'eng' if it doesn't have a value
def fix_040b(record)
f040 = record.fields('040')
return record unless f040.size == 1
return record unless record.fields('040').size == 1

f040 = f040.first
f040 = record['040']
field_index = record.fields.index(f040)
b040 = f040.subfields.select { |subfield| subfield.code == 'b' }
return record unless b040.empty?

subf_codes = f040.subfields.map { |subfield| subfield.code }
subf_codes = f040.subfields.map(&:code)
subf_index = if f040['a']
(subf_codes.index { |i| i == 'a' }) + 1
else
Expand All @@ -579,7 +535,7 @@ def fix_040b(record)
end

### Split up subfields that contain multiple 3-letter language codes
def fix_041(record)
def fix_f041(record)
f041 = record.fields('041')
return record if f041.empty?

Expand All @@ -589,11 +545,13 @@ def fix_041(record)
field.subfields.each do |subfield|
code = subfield.code
val = subfield.value
next unless val.size % 3 == 0

langs = val.scan(/.../)
langs.each do |lang|
new_field.append(MARC::Subfield.new(code, lang))
if (val.size % 3).zero?
langs = val.scan(/.../)
langs.each do |lang|
new_field.append(MARC::Subfield.new(code, lang))
end
else
new_field.append(MARC::Subfield.new(code, val))
end
end
record.fields[f_index] = new_field
Expand Down
105 changes: 0 additions & 105 deletions spec/variable_fields/040_spec.rb

This file was deleted.

Loading