Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created August 2, 2008 16:30
Show Gist options
  • Save ELLIOTTCABLE/3748 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/3748 to your computer and use it in GitHub Desktop.
# Arrays all currently kown bars, returning a two-dimensional array of
# lines and bars on lines, sorting the bars as defined by #<=>, and
# splitting the bars into groups of as many as can fit within max_width.
def self.array max_width
@@bars.sort!
@@bars.each {|b| b.reindex! }
total = 0
arr = [[]]
@@bars.each do |bar|
arr << [] if (total + bar.width) > max_width
arr.last << bar
total += bar.width
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment