baby-bro 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{baby-bro}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Doughty"]
12
- s.date = %q{2010-12-07}
12
+ s.date = %q{2010-12-08}
13
13
  s.default_executable = %q{bro}
14
14
  s.description = %q{Baby Bro monitors timestamp changes of files and and estimates time spent actively working in project directories.}
15
15
  s.email = %q{billdoughty@capitalthought.com}
@@ -73,7 +73,7 @@ module BabyBroExec
73
73
  # @param opts [OptionParser]
74
74
  def set_opts(opts)
75
75
  opts.banner = <<END
76
- Usage: bro [options] [command]
76
+ Usage: bro [options] [command] [date_string]
77
77
 
78
78
  Command is one of the following:
79
79
 
@@ -83,6 +83,15 @@ Command is one of the following:
83
83
  restart - restarts the monitor process (forces re-reading of config file)
84
84
  report - prints out time tracking reports
85
85
 
86
+ date_string is an optional argument for the report command and can be a
87
+ qualified date string, 'today', 'yesterday' or a number representing an
88
+ offset from today's date.
89
+
90
+ eg. 'bro report 2' would print the report for all projects from two days ago.
91
+
92
+ If date_string can't be parsed, reporter will default to today's date.
93
+
94
+ Options are as follows:
86
95
  END
87
96
 
88
97
  @options[:config_file] = "#{ENV["HOME"]}/.babybrorc"
@@ -91,7 +100,7 @@ END
91
100
  @options[:config_file] = config_file
92
101
  end
93
102
 
94
- opts.on('-t', '--tron', :NONE, 'Trace on. Show debug output and a full stack trace on error') do
103
+ opts.on('-t', '--tron', :NONE, 'Trace on. Show debug output and a full stack trace on error.') do
95
104
  @options[:tron] = true
96
105
  end
97
106
 
@@ -99,6 +108,10 @@ END
99
108
  @options[:force_start] = true
100
109
  end
101
110
 
111
+ opts.on('-b', '--brief', :NONE, "Ignore inactive projects and display daily totals without individual sessions.") do
112
+ @options[:brief] = true
113
+ end
114
+
102
115
  opts.on_tail("-?", "-h", "--help", "Show this message") do
103
116
  puts opts
104
117
  exit
@@ -132,9 +132,5 @@ module BabyBro
132
132
  def tron string
133
133
  $stdout.puts if @config && @config.tron
134
134
  end
135
-
136
- def tron string
137
- $stdout.puts if @config && @config.tron
138
- end
139
135
  end
140
136
  end
@@ -8,14 +8,31 @@ module BabyBro
8
8
  attr_accessor :data_directory, :projects, :config
9
9
 
10
10
  def initialize( options, args )
11
- @config = HashObject.new( process_base_config( options ) )
11
+ @config = HashObject.new( process_base_config( options ), true )
12
12
  process_reporting_config( @config )
13
13
  initialize_database
14
+ date_string = args.shift
15
+ if date_string == 'today'
16
+ @date = Date.today
17
+ elsif date_string == 'yesterday'
18
+ @date = Date.today - 1
19
+ elsif date_string
20
+ begin
21
+ @date = Date.parse(date_string)
22
+ rescue
23
+ @date = Date.today - date_string.to_i
24
+ end
25
+ end
14
26
  end
15
27
 
16
28
  def run
29
+ if @config.brief && @date
30
+ $stdout.puts
31
+ $stdout.puts "#{@date.strftime("%Y-%m-%d")}:"
32
+ end
33
+ @longest_project_name = @projects.inject(0){|max,p| p.name.size>max ? p.name.size : max}
17
34
  @projects.each do |project|
18
- print_project_report( project )
35
+ print_project_report( project, @date )
19
36
  end
20
37
  end
21
38
 
@@ -23,26 +40,35 @@ module BabyBro
23
40
  def process_reporting_config( config )
24
41
  end
25
42
 
26
- def print_project_report( project, date=nil )
27
- $stdout.puts
28
- $stdout.puts "#{project.name}"
29
- $stdout.puts "="*project.name.size
30
- cumulative_time = 0
43
+ def print_project_report( project, report_date=nil )
31
44
  sessions = project.sessions
32
- if sessions.any?
33
- sessions_by_date = sessions.group_by(&:start_date)
34
- sessions_by_date.keys.sort.each do |date|
35
- sessions = sessions_by_date[date].sort
36
- $stdout.puts " #{date.strftime("%Y-%m-%d")}"
37
- sessions.each do |session|
38
- $stdout.puts " #{session.start_time.strftime("%I:%M %p")} - #{session.duration_in_english}"
39
- cumulative_time += session.duration
45
+ return if @config.brief && sessions.empty?
46
+ if true
47
+ if @config.brief && report_date
48
+ $stdout.print " #{project.name}#{" "*(@longest_project_name - project.name.size)} :"
49
+ else
50
+ $stdout.puts
51
+ $stdout.puts "#{project.name}"
52
+ $stdout.puts "="*project.name.size
53
+ end
54
+ cumulative_time = 0
55
+ if sessions.any?
56
+ sessions_by_date = sessions.group_by(&:start_date)
57
+ sessions_by_date.keys.sort.each do |date|
58
+ next if report_date && date != report_date
59
+ sessions = sessions_by_date[date].sort
60
+ $stdout.puts " #{date.strftime("%Y-%m-%d")}" unless @config.brief && report_date
61
+ sessions.each do |session|
62
+ $stdout.puts " #{session.start_time.strftime("%I:%M %p")} - #{session.duration_in_english}" unless @config.brief
63
+ cumulative_time += session.duration
64
+ end
65
+ $stdout.print " Total:" unless @config.brief && report_date
66
+ $stdout.puts " #{Session.duration_in_english(sessions.inject(0){|sum,n| sum = sum+n.duration})}"
40
67
  end
41
- $stdout.puts " Total: #{Session.duration_in_english(sessions.inject(0){|sum,n| sum = sum+n.duration})}"
68
+ $stdout.puts "Grand Total: #{Session.duration_in_english(cumulative_time)}" unless @config.brief
69
+ else
70
+ $stdout.puts " No sessions for this project."
42
71
  end
43
- $stdout.puts "Grand Total: #{Session.duration_in_english(cumulative_time)}"
44
- else
45
- $stdout.puts " No sessions for this project."
46
72
  end
47
73
  end
48
74
  end
@@ -58,7 +58,7 @@ module BabyBro
58
58
  end
59
59
  time << "#{time_duration.to_i}s"
60
60
  breakdown = time.join(' ')
61
- output = "#{"%05.2f" % (duration/1.hour)} hours or #{breakdown}"
61
+ output = "#{(duration/1.hour).to_i < 10 ? " " : ""}#{"%.2f" % (duration/1.hour)} hours or #{breakdown}"
62
62
  end
63
63
 
64
64
  def <=> b
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baby-bro
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bill Doughty
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-07 00:00:00 -06:00
18
+ date: 2010-12-08 00:00:00 -06:00
19
19
  default_executable: bro
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency