Module: Wod::Helpers

Included in:
Client, Command, Command::Base
Defined in:
lib/wod/helpers.rb

Instance Method Summary collapse

Instance Method Details

#askObject



20
21
22
# File 'lib/wod/helpers.rb', line 20

def ask
  gets.strip
end

#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

#error(msg) ⇒ Object



15
16
17
18
# File 'lib/wod/helpers.rb', line 15

def error(msg)
  STDERR.puts(msg)
  exit 1
end

#home_directoryObject



3
4
5
# File 'lib/wod/helpers.rb', line 3

def home_directory
  ENV['HOME']
end

#last_page_fileObject



11
12
13
# File 'lib/wod/helpers.rb', line 11

def last_page_file
  File.join wod_directory, "last_page.html"
end

#wod_directoryObject



7
8
9
# File 'lib/wod/helpers.rb', line 7

def wod_directory
  File.join home_directory, ".wod"
end