Method: Wod::Helpers#display_formatted
- Defined in:
- lib/wod/helpers.rb
#display_formatted(hashes, columns) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wod/helpers.rb', line 24 def display_formatted hashes, columns column_lengths = columns.map do |c| hashes.map { |h| h[c].length }.max end sorted = hashes.sort_by {|h| h[columns.first] } sorted.each do |row| column_index = 0 puts " " + columns.map{ |column| text = row[column].ljust(column_lengths[column_index]); column_index += 1; text }.join(" | ") end end |