Sha256: c057c0aca0c6454625d9c0db6bd1582760053d52f880d14127f3fe12e1366eb3

Contents?: true

Size: 785 Bytes

Versions: 1

Compression:

Stored size: 785 Bytes

Contents

module Wod
  module Helpers
    def home_directory
      ENV['HOME']
    end
    
    def wod_directory
      File.join home_directory, ".wod"
    end
    
    def last_page_file
      File.join wod_directory, "last_page.html"
    end
        
    def error(msg)
      STDERR.puts(msg)
      exit 1
    end
    
    def ask
      gets.strip
    end
    
    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
    
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wod-0.0.4 lib/wod/helpers.rb