Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def output_div_list(names)
  2.   output = Array.new
  3.   authors_length = names.length
  4.   first_column_length  = authors_length/3
  5.   second_column_length = authors_length/3
  6.   third_column_length  = authors_length/3
  7.   remainder = authors_length % 3
  8.   if remainder.eql?(1)
  9.     first_column_length  += 1
  10.   elsif remainder.eql?(2)
  11.     first_column_length  += 1
  12.     second_column_length += 1
  13.   end
  14.   3.times do |column|
  15.     output << "<div id='author_column_#{numeric_to_string(column)}'>"
  16.     output << "<ul>"
  17.       if column.eql?(0)
  18.         names[0..(first_column_length - 1)].each do |author|
  19.           output << "<li>#{author}</li>"
  20.         end
  21.       elsif column.eql?(1)
  22.         names[(first_column_length)..(first_column_length + second_column_length - 1)].each do |author|
  23.           output << "<li>#{author}</li>"
  24.         end  
  25.       elsif column.eql?(2)
  26.         names[(-third_column_length)..-1].each do |author|
  27.           output << "<li>#{author}</li>"
  28.         end
  29.       end
  30.     output << "</ul>"
  31.     output << "</div>"
  32.   end
  33.   output.join("\n")
  34. end
  35.  
  36. def numeric_to_string(number)
  37.   case number
  38.   when 0
  39.     then 'one'
  40.   when 1
  41.     then 'two'
  42.   when 2
  43.     then 'three'
  44.   end
  45. end