Le 20 septembre 19:38, Jes Gabriel y Gal a rit :

/.../

> I have no time to propose a complete solution. I'll leave to you
> adding the "Sx" and "Ox" processing. This is how I'd do it it they
> were all numbers:

> irb(main):023:0> list.each_cons(2) do |x,y|

Ahha !  each_cons...

> irb(main):024:1* if (x+1) == y
> irb(main):025:2> result.last << y
> irb(main):026:2> else
> irb(main):027:2* result << [y]
> irb(main):028:2> end
> irb(main):029:1> end

M'kay.  My current iteration looks like this :

  def RAniDBTools.format_episodes_list(list)
    list.group_by { |e| ('A'..'Z') === e[0,1] ? e[0,1] : '' }.collect do |p, l|
      l = l.map { |e| e.gsub(/^[A-Z]/, '').to_i }
      format_consecutive_numbers(p, l)
    end.join(", ")
  end
  
(I'd definitely need a group_and_map function here.)  

  def RAniDBTools.format_consecutive_numbers(prefix, list)
    result = [[ list.first ]]
    list.each_cons(2) do |x, y|
      if y == x + 1
        result.last << y
      else
        result << [ y ]
      end
    ends
    result.map { |x| "#{prefix}#{x.first}" + (x.size == 1 ? "" : "-#{prefix}#{x.last}") }.join(", ")
  end

Better !  I'm still reading the other answers in the thread, though...

Thanks a lot for the ideas !
s
Fred
-- 
If I don't think about the fact that she left me,
If I don't see the pearls fall from the sky,
If I don't hear the accusations of blasphemy,
If I don't feel the tears in my eyes,
This is the best day of my life.              (Prince, 3 chains o' gold)