Class: MM::Console::SimpleCommand::ToDo::Task
- Inherits:
-
Object
- Object
- MM::Console::SimpleCommand::ToDo::Task
show all
- Defined in:
- lib/mm/console/simple_command/todo.rb
Constant Summary
collapse
- COLORS =
{
:red => 31, :green => 32, :yellow => 33, :blue => 34, :pink => 35, :sky_blue => 36, :gray => 90,
:b_red => 41, :b_green => 42, :b_yellow => 43, :b_blue => 44, :b_pink => 45, :b_sky_blue => 46
}
- FONT_STYLES =
{:normal => 0, :bold => 1, :white => 2, :underscore => 4, :flash => 5, :inverse => 7}
Instance Method Summary
collapse
Constructor Details
#initialize(detail) ⇒ Task
Returns a new instance of Task.
23
24
25
26
27
|
# File 'lib/mm/console/simple_command/todo.rb', line 23
def initialize(detail)
@detail = detail
@status = []
@status << {:desc => 'todo', :next_action => 'start_work', :at => Time.now, :color => :normal_yellow}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/mm/console/simple_command/todo.rb', line 54
def method_missing(method, *args)
style, color = method.to_s.split('_').collect{|n| n.to_sym}
if style && color
"\e[#{FONT_STYLES[style]};#{COLORS[color]}m#{args.join}\e[0m"
else
super
end
end
|
Instance Method Details
#complete(runtime) ⇒ Object
39
40
41
42
43
|
# File 'lib/mm/console/simple_command/todo.rb', line 39
def complete(runtime)
@status << {:desc => 'completed', :next_action => 'delete', :at => Time.now, :color => :normal_gray}
delete(runtime)
runtime[:todo] << (self)
end
|
#delete(runtime) ⇒ Object
45
46
47
|
# File 'lib/mm/console/simple_command/todo.rb', line 45
def delete(runtime)
runtime[:todo].delete(self)
end
|
#next(runtime) ⇒ Object
29
30
31
|
# File 'lib/mm/console/simple_command/todo.rb', line 29
def next(runtime)
send(@status.last[:next_action], runtime)
end
|
#start_work(runtime) ⇒ Object
33
34
35
36
37
|
# File 'lib/mm/console/simple_command/todo.rb', line 33
def start_work(runtime)
@status << {:desc => 'working on', :next_action => 'complete', :at => Time.now, :color => :bold_red}
delete(runtime)
runtime[:todo].unshift(self)
end
|
#to_s ⇒ Object
49
50
51
52
|
# File 'lib/mm/console/simple_command/todo.rb', line 49
def to_s
st = @status.last
send(st[:color] || :normal_yellow, "#{st[:next_action].titleize}: #{@detail}")
end
|