
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.19 KB | hits: 17 | expires: Never
def output_div_list(names)
output = Array.new
authors_length = names.length
first_column_length = authors_length/3
second_column_length = authors_length/3
third_column_length = authors_length/3
remainder = authors_length % 3
if remainder.eql?(1)
first_column_length += 1
elsif remainder.eql?(2)
first_column_length += 1
second_column_length += 1
end
3.times do |column|
output << "<div id='author_column_#{numeric_to_string(column)}'>"
output << "<ul>"
if column.eql?(0)
names[0..(first_column_length - 1)].each do |author|
output << "<li>#{author}</li>"
end
elsif column.eql?(1)
names[(first_column_length)..(first_column_length + second_column_length - 1)].each do |author|
output << "<li>#{author}</li>"
end
elsif column.eql?(2)
names[(-third_column_length)..-1].each do |author|
output << "<li>#{author}</li>"
end
end
output << "</ul>"
output << "</div>"
end
output.join("\n")
end
def numeric_to_string(number)
case number
when 0
then 'one'
when 1
then 'two'
when 2
then 'three'
end
end