module Travis::Client::States

def canceled?

def canceled?
  check_state
  state == 'canceled'
end

def check_state

def check_state
  raise Error, "unknown state %p for %p" % [state, self] unless STATES.include? state
end

def color

def color
  case state
  when 'created', 'queued', 'received', 'started' then 'yellow'
  when 'passed', 'ready'                then 'green'
  when 'errored', 'canceled', 'failed'  then 'red'
  end
end

def created?

def created?
  check_state
  !!state
end

def errored?

def errored?
  check_state
  state == 'errored'
end

def failed?

def failed?
  check_state
  state == 'failed'
end

def finished?

def finished?
  not pending?
end

def green?

def green?
  color == 'green'
end

def passed?

def passed?
  check_state
  state == 'passed'
end

def pending?

def pending?
  check_state
  %w[created started queued received ].include? state
end

def queued?

def queued?
  check_state
  state != 'created'
end

def ready?

def ready?
  state == 'ready'
end

def received?

def received?
  check_state
  state != 'created' and state != 'queued'
end

def red?

def red?
  color == 'red'
end

def running?

def running?
  state == 'started'
end

def started?

def started?
  check_state
  state != 'created' and state != 'received' and state != 'queued'
end

def unsuccessful?

def unsuccessful?
  errored? or failed? or canceled?
end

def yellow?

def yellow?
  color == 'yellow'
end