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

From: Steve Meyer <steve.e.meyer_at_nyob>
Date: Fri, 12 Sep 2014 09:06:55 -0400
To: CODE4LIB_at_LISTSERV.ND.EDU
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 - 13:07:30 EDT