Class: Checklist::UI

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

Constant Summary collapse

UTF8_MARKS =
{
:tick => '',
:cross => '' }
ASCII_MARKS =
{
:tick => '[bold]+',
:cross => '[bold]X' }

Instance Method Summary collapse

Constructor Details

#initializeUI

Returns a new instance of UI.



15
16
17
18
# File 'lib/checklist/ui.rb', line 15

def initialize
  @fmtd = Formatador.new
  @marks = Locale.charset == 'UTF-8' ? UTF8_MARKS : ASCII_MARKS
end

Instance Method Details

#complete(checklist) ⇒ Object



36
37
38
# File 'lib/checklist/ui.rb', line 36

def complete(checklist)
  fmtd.display "[green]All #{checklist.length} steps [bold]completed[/]\n"
end

#finish(step) ⇒ Object



32
33
34
# File 'lib/checklist/ui.rb', line 32

def finish(step)
  fmtd.redisplay "  [[green]#{marks[:tick]}[/]] #{step.challenge} [green]#{step.response}[/]\n"
end

#header(checklist) ⇒ Object



24
25
26
# File 'lib/checklist/ui.rb', line 24

def header(checklist)
  fmtd.display "[bold][yellow]CHECKLIST[/][yellow]:[/] [bold]#{checklist.name}[/]\n"
end

#incomplete(checklist, remaining_steps) ⇒ Object



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

def incomplete(checklist, remaining_steps)
  fmtd.redisplay "  [[red]#{marks[:cross]}[/]] #{remaining_steps.first.challenge} [red]FAILED[/]\n"
  remaining_steps[1..remaining_steps.length].each do |step|
    fmtd.display "  [ ] #{step.challenge} [yellow]PENDING[/]\n"
  end
  fmtd.display "\n[indent]#{checklist.remaining} of #{checklist.length} steps [red]NOT COMPLETED[/]:\n"

  fmtd.indent do
    fmtd.display_table(
      remaining_steps.map(&:to_hash),
      %w(Challenge Response Description))
  end
end

#say(msg = '') ⇒ Object



20
21
22
# File 'lib/checklist/ui.rb', line 20

def say(msg='')
  fmtd.display "#{msg}\n"
end

#start(step) ⇒ Object



28
29
30
# File 'lib/checklist/ui.rb', line 28

def start(step)
  fmtd.display "  [ ] [yellow]#{step.challenge}[/] ..."
end