class SLA::Formatters::TTY

Attributes

last_source[R]
screen_width[R]

Public Instance Methods

handle(action, page) click to toggle source
# File lib/sla/formatters/tty.rb, line 6
def handle(action, page)
  @screen_width = terminal_width
  @last_source = page.url if action == :source

  return unless action == :check
  @count += 1

  show_status page
end

Private Instance Methods

show_status(page) click to toggle source
# File lib/sla/formatters/tty.rb, line 22
def show_status(page)
  if page.valid?
    status = "PASS"
    color = "!txtgrn!"
  else
    @failed += 1
    status = "FAIL"
    color = "!txtred!"

    if last_source
      resay "!txtpur!SOURCE  #{last_source}"
      @last_source = nil
    end

    resay "  !txtred!FAIL!txtrst!  #{page.depth}  #{page.url}"
    resay "   !txtred!#{page.code}!txtrst!  #{page.error}" unless page.code == 404
  end

  message = "[#{failed}/#{count} @ #{page.depth}] #{status}"
  remaining_width = screen_width - message.size - 4
  url = page.url[0..remaining_width]
  resay "[#{failed}/#{count} @ #{page.depth}] #{color}#{status}!txtrst! #{url} "
end