def split_name(name)
      name ||= ''
      if name.include?(',')
        last,first = name.split(',', 2)
        first,middle = first.to_s.strip.split(' ', 2)
      else
        first,middle,last = name.split(' ', 3)
        if middle && !last
          middle,last = last,middle
        end
      end
      [ first.to_s.strip, middle.to_s.strip, last.to_s.strip ]
    end
def split_name(name)
      name ||= ''
      if name.include?(',')
        last,first = name.split(',', 2)
        first,middle = first.to_s.strip.split(' ', 2)
      else
        first,middle,last = name.split(' ', 3)
        if middle && !last
          middle,last = last,middle
        end
      end
      [ first.to_s.strip, middle.to_s.strip, last.to_s.strip ]
    end
Splits a name into First, Middle, and Last parts.

 Returns an array containing [ First, Middle, Last ]
 Any part that is missing will be nil.

   'John Doe'          => [ 'John', nil, 'Doe' ]
   'Doe, John'         => [ 'John', nil, 'Doe' ]
   'John A. Doe'       => [ 'John', 'A.', 'Doe' ]
   'Doe, John A.'      => [ 'John', 'A.', 'Doe' ]
   'John A. Doe Jr.'   => [ 'John', 'A.', 'Doe Jr.' ]
   'Doe Jr., John A.'  => [ 'John', 'A.', 'Doe Jr.' ]

 Since it doesn't check very hard, there are some known bugs as well.

   'John Doe Jr.'      => [ 'John', 'Doe', 'Jr.' ]
   'John Doe, Jr.'     => [ 'Jr.', nil, 'John Doe' ]
   'Doe, John A., Jr.' => [ 'John', 'A., Jr.', 'Doe' ]

 It should work in most cases.