Code Coverage
 
Lines
Covered
92.59% covered (success)
92.59%
25 / 27
1
require 'term/ansicolor'
1
module TheFox
1
module Timr
# Used as [Task](rdoc-ref:TheFox::Timr::Model::Task) and [Track](rdoc-ref:TheFox::Timr::Model::Track) Status.
#
# - `R` running
# - `S` stopped
# - `P` paused. It's actually stopped but with an additional flag.
# - `-` (dash) not started
# - `U` unknown
1
class Status
1
include Term::ANSIColor
# Source Data
1
attr_reader :short_status
# Resolved by `short_status`. See `set_long_status` method.
1
attr_reader :long_status
1
def initialize(short_status)
32
@short_status = short_status
32
@long_status = nil
32
set_long_status
end
# Use `term/ansicolor` to colorize the Long Status.
1
def colorized
7
case @short_status
when ?R
0
green(@long_status)
when ?S
0
red(@long_status)
else
7
@long_status
end
end
# To String
1
def to_s
2
long_status
end
1
private
1
def set_long_status
32
@long_status = case @short_status
when ?-
12
'not started'
when ?R
7
'running'
when ?S
7
'stopped'
when ?P
3
'paused'
when ?U
2
'unknown'
else
1
'unknown'
end
end
end # class Status
end # module Timr
end # module TheFox