Class: TableView

Inherits:
Object
  • Object
show all
Includes:
TerminalUtils
Defined in:
lib/views.rb

Constant Summary

Constants included from TerminalUtils

TerminalUtils::ERASE_DISPLAY, TerminalUtils::GREEN, TerminalUtils::RED, TerminalUtils::RESET, TerminalUtils::RESTORE_CURSOR, TerminalUtils::SAVE_CURSOR, TerminalUtils::SCREEN_WIDTH

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ TableView

Returns a new instance of TableView.



49
50
51
# File 'lib/views.rb', line 49

def initialize(map)
  @map = map
end

Instance Method Details

#to_sObject



53
54
55
56
57
58
59
60
# File 'lib/views.rb', line 53

def to_s
  @map.map do |(key, count)|
    color = count > 0 ? GREEN : RED
    done = count > 0 ? "" : " "
    description = key.truncate(SCREEN_WIDTH - 4).ljust(SCREEN_WIDTH - 3)
    [color, done, ' ', description, count.to_s, RESET].join
  end
end