Skip to content

Instantly share code, notes, and snippets.

@jsanti
Created June 25, 2009 16:44
Show Gist options
  • Save jsanti/135966 to your computer and use it in GitHub Desktop.
Save jsanti/135966 to your computer and use it in GitHub Desktop.
class Status
STATUS_CODES = { :queued => 0,
:running => 1,
:error => 2,
:success => 3 }
STATUS_NAMES = { :queued => "En cola de espera",
:running => "En ejecución",
:error => "Terminado con errores",
:success => "Terminado sin errores" }
cattr_accessor STATUS_CODES
attr_accessor :code
def initialize(code)
@code = code
end
def to_s
status_name
end
def status_name
STATUS_NAMES[status]
end
def status
STATUS_CODES.each do |k, v|
return k if v == @code
end
end
def is_queued?; @code == STATUS_CODES[:queued] end
def is_running?; @code == STATUS_CODES[:running] end
def is_error?; @code == STATUS_CODES[:error] end
def is_success?; @code == STATUS_CODES[:success] end
def is_finished?; is_error? || is_success? end
end
def estado
Status.new(super)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment