Re: ruby-marc: how to sort fields after append?

From: Jason Stirnaman <jstirnaman_at_nyob>
Date: Fri, 12 Sep 2014 14:32:11 +0000
To: CODE4LIB_at_LISTSERV.ND.EDU
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
jstirnaman_at_kumc.edu
913-588-7319

On Sep 12, 2014, at 8:06 AM, Steve Meyer <steve.e.meyer_at_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 <jstirnaman_at_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
>> jstirnaman_at_kumc.edu
>> 913-588-7319
>> 
Received on Fri Sep 12 2014 - 14:33:20 EDT