Class: Console

Inherits:
Object
  • Object
show all
Defined in:
lib/console.rb

Class Method Summary collapse

Class Method Details

.announce_task_end(task, elapsed_str) ⇒ Object



13
14
15
16
17
18
# File 'lib/console.rb', line 13

def self.announce_task_end task, elapsed_str
  line = "==" + Color.cyan + "[:" + Color.yellow + task + Color.cyan + "]" + Color.clear +
      " completed in " + Color.bright_green + elapsed_str + Color.clear
  puts line + Color.clear
  puts " "
end

.announce_task_start(task) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/console.rb', line 5

def self.announce_task_start task
  line = "==" + Color.cyan + "[:" + Color.yellow + task + Color.cyan + "]" + Color.clear
  while(line.length < 80) do
 line = line + "="
  end
  puts line + Color.clear
end


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/console.rb', line 39

def self.print_array(prefix,key,array)
  array.each do |v|
    if v.kind_of?(Hash)
   puts Color.bright_yellow + prefix + Color.clear
      print_hash( prefix + " ".rjust(max_length),v)
    else
      puts Color.white + prefix + " " + Color.green + v.to_s + Color.clear if v.kind_of?(String)
#prefix = indent + " ".rjust(max_length-1)

#prefix = " ".rjust(indent.length+max_length-1)

words = prefix.split(' ')
prefix = " ".rjust(prefix.length)
    end
  end
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/console.rb', line 20

def self.print_hash(indent,hash)
  max_length=0
  hash.each { |name,value| max_length=name.to_s.length if name.to_s.length > max_length }
  max_length=max_length+1
  index=0
  hash.each do |name,value|
 prefix = "#{indent}#{name.to_s}".rjust(max_length)
    if value.kind_of?(Hash)
      print_hash(prefix+" ",value)
    elsif value.kind_of?(Array)
   Console.print_array prefix,name,value
    else
   puts Color.white + prefix + " " + Color.green + value.to_s + Color.clear
    end
    index+=1
    indent=" ".rjust(indent.length)
  end
end