Thanks, Steve! Thought I had tried that, but it's exactly what I was looking 
for.

Jason

Jason Stirnaman
Lead, Library Technology Services
University of Kansas Medical Center
jstirna...@kumc.edu
913-588-7319

On Sep 12, 2014, at 8:06 AM, Steve Meyer <steve.e.me...@gmail.com> wrote:

> Since the fields property of a MARC::Record is a MARC::FieldMap, which is a
> subclass of Array, I use the Array.sort_by! method:
> 
> record.fields.sort_by! {|f| f.tag}
> 
> 
> 
> On Fri, Sep 12, 2014 at 12:28 AM, Jason Stirnaman <jstirna...@kumc.edu>
> wrote:
> 
>> Ruby-marc sages,
>> What's the best way to re-sequence fields in a record after appending to
>> it?  This seems to work ok, but feels wrong.
>> 
>> 
>>  for record in reader
>>    # Return a record with new field appended.
>>    newrecord = add_control_number(record)
>> 
>>    ### Re-sort fields by tag and copy them to a new record. ###
>>    sortedrecord = MARC::Record.new
>>    sortedrecord.leader = newrecord.leader
>>    newrecord.sort_by{|f| f.tag}.each {|tag| sortedrecord.append(tag)}
>> 
>>     writer.write(sortedrecord)
>>  end
>> 
>> 
>> Thanks,
>> Jason
>> 
>> Jason Stirnaman
>> Lead, Library Technology Services
>> University of Kansas Medical Center
>> jstirna...@kumc.edu
>> 913-588-7319
>> 

Reply via email to