Class: RworkTrackerCli
- Inherits:
-
Object
show all
- Defined in:
- lib/rworktracker.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RworkTrackerCli.
7
8
9
10
|
# File 'lib/rworktracker.rb', line 7
def initialize(file)
@rw = RworkTracker.new(file)
@rw.loadYaml
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/rworktracker.rb', line 84
def method_missing(m, *args, &block)
if ['pr','add'].include?(m.to_s)
self.send self.public_methods.grep(/#{m}/)[0]
else
puts "There's no method called #{m} here"
help
end
end
|
Instance Method Details
#addproject ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/rworktracker.rb', line 32
def addproject
if ARGV.length > 1
@rw.addProject(ARGV[1..-1].join('_'))
@rw.writeYaml
else
warn "you need to provide a project name"
end
end
|
#help ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/rworktracker.rb', line 12
def help
puts "Welcome to RworkTracker: Work Time Tracking Interface"
puts "Available Commands are:"
puts "\t pr, projects: list active projects"
puts "\t add, addproject <projectname>, Add a new project"
puts "\t start <project name>, Start tracking a project"
puts "\t stop <project name>, Stop tracking a project"
puts "\t stats, show total projects stats"
puts "\t stat <project name>, show total project stats"
end
|
#projects ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/rworktracker.rb', line 24
def projects
puts "Active project are:"
@rw.projects.each do |e|
puts e + " - running now" if @rw.started?(e)
puts e + " - not running now" if !@rw.started?(e)
end
end
|
#start ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/rworktracker.rb', line 41
def start
if ARGV.length > 1
if @rw.start(ARGV[1..-1].join('_'))
@rw.writeYaml
else
warn "please create the project first"
end
else
warn "you need to provide a project name"
end
end
|
#stat(pro = ARGV[1..-1].join('_')) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rworktracker.rb', line 65
def stat(pro = ARGV[1..-1].join('_'))
if pro
tot = @rw.elapsed(pro)
if tot
puts "Project #{pro} took #{Time.at(tot).gmtime.strftime('%R:%S')} hours"
else
warn "please provide a valid project"
end
else
warn "you need to provide a project name"
end
end
|
#stats ⇒ Object
78
79
80
81
82
|
# File 'lib/rworktracker.rb', line 78
def stats
@rw.projects.each do |e|
stat(e)
end
end
|
#stop ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/rworktracker.rb', line 53
def stop
if ARGV.length > 1
if @rw.stop(ARGV[1..-1].join('_'))
@rw.writeYaml
else
warn "please create the project first or start it !"
end
else
warn "you need to provide a project name"
end
end
|