NAME

Catmandu::Fix::Bind::marc_each - a binder that loops over MARC fields

SYNOPSIS

# Only add the 720 field to the authors when the $e subfield contains a 'promotor'
do marc_each()
    if marc_match("720e","promotor")
        marc_map("720ab",authors.$append)
    end
end

# Delete all the 500 fields
do marc_each()
    if marc_match("500",".*")
        reject()
    end
end

# Loop over all the fields with a variable (see marc_copy, marc_cut and marc_paste for the content)
do marc_each(var:this)
    if all_match(this.tag,300)
      # The '***' is short for the current tag in a marc_each loop
      marc_map(***a,test)
    end
end

DESCRIPTION

The marc_each binder will iterate over each individual MARC field and execute the fixes only in context over each individual field.

If a MARC record contains:

500  $aTest
500  $aTest2$eskip
500  $aTest3

then the fix

do marc_each()
    marc_map("500",note.$append)
end

will have the same effect as

marc_map("500",note.$append)

because marc_map by default loops over all repeated MARC fields. But the marc_each bind has the advantage to process fields in context. E.g. to only map fields where the $e doesn't contain 'skip' you can write:

do marc_each()
    unless marc_match("500e",skip)
        marc_map("500",note.$append)
    end
end

A variable name can be parsed to the marc_each, in which case an automatic marc_copy will be done into the variable name. E.g

do marc_each()
   marc_copy(***,this)
   ...
end

and

do marc_each(var:this)
   ...
end

is similar

SEE ALSO

Catmandu::Fix::Bind