timestream 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/timestream CHANGED
@@ -1,42 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'spreadsheet'
4
+ require 'timestream/employee_activity_report'
5
5
 
6
- # TODO Add selector for spreadsheets
7
- spreadsheet = Spreadsheet.open ARGV[0]
8
- worksheet = spreadsheet.worksheet "EAR - Current Week"
6
+ employee_activity_report = Timestream::EmployeeActivityReport.new ARGV[0]
9
7
 
10
- DATE_ROW = 2
11
- DATE_COLUMN = 1
12
-
13
- saturday_date = worksheet.row(DATE_ROW)[DATE_COLUMN]
14
- project_totals_by_day = Hash.new { |hash, day|
15
- hash[day] = Hash.new(0)
16
- }
17
-
18
- DAY_COLUMN_SPAN = 3
19
- PROJECT_NUMBER_COLUMN = 0
20
-
21
- # 0-indexed - rows are for this week's time
22
- (12 .. 36).each do |row_index|
23
- row = worksheet.row(row_index)
24
- project_number = row[PROJECT_NUMBER_COLUMN]
25
-
26
- # TODO handle Vacation / Holiday / Sick time
27
- # no project number assigned
28
- next if project_number.nil?
29
-
30
- # 0 - Weekend
31
- # 1 - Monday
32
- # 2 - Tuesday...
33
- (0 .. 5).each do |day_index|
34
- day_column = 9 + DAY_COLUMN_SPAN * day_index
35
- hours = row[day_column] || 0
36
-
37
- total_by_project = project_totals_by_day[day_index]
38
- total_by_project[project_number] += hours
39
- end
40
- end
41
-
42
- puts project_totals_by_day.inspect
8
+ puts employee_activity_report.to_text_table
@@ -0,0 +1,136 @@
1
+ require 'rubygems'
2
+ require 'spreadsheet'
3
+ require 'terminal-table/import'
4
+
5
+ module Timestream
6
+ class EmployeeActivityReport
7
+ class Cell
8
+ attr_reader :column
9
+
10
+ def initialize(row, column)
11
+ @column = column
12
+ @row = row
13
+ end
14
+
15
+ attr_reader :row
16
+ end
17
+
18
+ def cell(location)
19
+ worksheet.row(location.row)[location.column]
20
+ end
21
+
22
+ DATE_CELL = Cell.new(2, 1)
23
+
24
+ DAY_COLUMN_SPAN = 3
25
+
26
+ def initialize(path)
27
+ @path = path
28
+ end
29
+
30
+ attr_reader :path
31
+
32
+ def row(index)
33
+ worksheet.row(index)
34
+ end
35
+
36
+ def spreadsheet
37
+ @spreadsheet ||= Spreadsheet.open path
38
+ end
39
+
40
+ class Timestream
41
+ include Enumerable
42
+
43
+ SLOT_NAMES = [:weekend, :monday, :tuesday, :wednesday, :thursday, :friday]
44
+
45
+ def each(&block)
46
+ @totals.each(&block)
47
+ end
48
+
49
+ def initialize
50
+ @totals = Array.new(SLOT_NAMES.length, 0)
51
+ end
52
+
53
+ def [](day)
54
+ if day.is_a? Symbol
55
+ day = SLOT_NAMES.index(day)
56
+ end
57
+
58
+ @totals[day]
59
+ end
60
+
61
+ def []=(day, total)
62
+ if day.is_a? Symbol
63
+ day = SLOT_NAMES.index(day)
64
+ end
65
+
66
+ @totals[day] = total
67
+ end
68
+
69
+ def to_a
70
+ @totals.dup
71
+ end
72
+ end
73
+
74
+ def timestream_by_project_number
75
+ if @timestream_by_project_number.nil?
76
+ parse
77
+ end
78
+
79
+ @timestream_by_project_number
80
+ end
81
+
82
+ def to_text_table
83
+ employee_activity_report = self
84
+ table {
85
+ self.headings = ['Project Number']
86
+ self.headings.concat Timestream::SLOT_NAMES.collect { |name|
87
+ name.to_s.capitalize
88
+ }
89
+
90
+ employee_activity_report.timestream_by_project_number.each do |project_number, timestream|
91
+ row = [project_number]
92
+ timestream.each do |daily_total|
93
+ row << "%02.02f" % daily_total
94
+ end
95
+
96
+ add_row row
97
+ end
98
+ }
99
+ end
100
+
101
+ def worksheet
102
+ @worksheet ||= spreadsheet.worksheet "EAR - Current Week"
103
+ end
104
+
105
+ private
106
+
107
+ def parse
108
+ @timestream_by_project_number = Hash.new { |hash, project_number|
109
+ hash[project_number] = Timestream.new
110
+ }
111
+
112
+ (12 .. 36).each do |row_index|
113
+ row = self.row(row_index)
114
+ project_number = row[PROJECT_NUMBER_COLUMN]
115
+
116
+ # TODO handle Vacation / Holiday / Sick time
117
+ # no project number assigned
118
+ next if project_number.nil?
119
+
120
+ # 0 - Weekend
121
+ # 1 - Monday
122
+ # 2 - Tuesday...
123
+ (0 .. 5).each do |day_index|
124
+ timestream = @timestream_by_project_number[project_number]
125
+
126
+ day_column = 9 + DAY_COLUMN_SPAN * day_index
127
+ hours = row[day_column] || 0
128
+
129
+ timestream[day_index] += hours
130
+ end
131
+ end
132
+ end
133
+
134
+ PROJECT_NUMBER_COLUMN = 0
135
+ end
136
+ end
@@ -1,3 +1,3 @@
1
1
  module Timestream
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/timestream.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "timestream"
16
16
 
17
17
  s.add_dependency("spreadsheet")
18
+ s.add_dependency("terminal-table")
18
19
 
19
20
  s.files = `git ls-files`.split("\n")
20
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timestream
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Imhoff
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-11 00:00:00 -05:00
18
+ date: 2011-05-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,20 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: terminal-table
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
35
49
  description: Converts Hamster report to EAR to JDE Timecard
36
50
  email:
37
51
  - luke@cray.com
@@ -47,6 +61,7 @@ files:
47
61
  - Rakefile
48
62
  - bin/timestream
49
63
  - lib/timestream.rb
64
+ - lib/timestream/employee_activity_report.rb
50
65
  - lib/timestream/version.rb
51
66
  - timestream.gemspec
52
67
  has_rdoc: true