Class: TableView

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

Constant Summary collapse

CHECKMARK_CHARS_OFFSET =
2
COUNT_CHARS_OFFSET =
5

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



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

def to_s
  @map.map do |(key, count)|
    color = count > 0 ? GREEN : RED
    done = count > 0 ? "" : " "
    description = key.at_width(SCREEN_WIDTH - COUNT_CHARS_OFFSET - CHECKMARK_CHARS_OFFSET)
    [color, done, ' ', description, count.to_s.rjust(COUNT_CHARS_OFFSET), RESET].join
  end
end