tlog 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,165 +1,165 @@
1
1
 
2
2
  class Tlog::Entity::Log
3
3
 
4
- attr_accessor :name
5
- attr_accessor :goal
6
- attr_accessor :entries
7
- attr_accessor :path
8
-
9
- def initialize(log_path = nil)
10
- @entries = []
11
- if log_path
12
- @name = log_path.basename.to_s
13
- @path = log_path
14
- @goal = goal_length
15
- end
16
- end
17
-
18
- def create(options)
19
- unless Dir.exists?(@path)
20
- # Default time log attribute values
21
- state = 'open'
22
- points = 0
23
- owner = 'none'
24
-
25
- FileUtils.mkdir_p(@path)
26
- @goal = ChronicDuration.parse(options[:goal]) if options[:goal]
27
- state = options[:state] if options[:state]
28
- points = options[:points] if options[:point]
29
- owner = options[:owner] if options[:owner]
30
- write_log(state, points, owner)
31
- true
32
- end
33
- end
34
-
35
- def goal_length
36
- if File.exists?(goal_path)
37
- contents = File.read(goal_path)
38
- contents.strip
39
- contents.to_i
40
- end
41
- end
42
-
43
- def entries
44
- log_entries = []
45
- hex_value = head_hex_value
46
- return log_entries unless hex_value
47
- begin
48
- entry = Tlog::Entity::Entry.new(entry_path(hex_value), hex_value)
49
- hex_value = entry.parent_hex
50
- log_entries.push(entry)
51
- end until hex_value == "none"
52
- return log_entries
53
- end
54
-
55
- def duration
56
- dur = 0
57
- entries.each do |entry|
58
- dur += entry.length
59
- end
60
- dur
61
- end
62
-
63
- def owner
64
- read_file(owner_path) if File.exists?(owner_path)
65
- end
66
-
67
- def state
68
- read_file(state_path) if File.exists?(state_path)
69
- end
70
-
71
- def points
72
- read_file(points_path) if File.exists?(points_path)
73
- end
74
-
75
- def update_state(state)
76
- File.open(state_path, 'w'){|f| f.write(state)}
77
- end
78
-
79
- def update_points(points)
80
- File.open(points_path, 'w'){|f| f.write(points)}
81
- end
82
-
83
- def update_owner(owner)
84
- File.open(owner_path, 'w'){|f| f.write(owner)}
85
- end
86
-
87
- def add_entry(current)
88
- entry_hex = generate_random_hex
89
- new_entry = Tlog::Entity::Entry.new(entry_path(entry_hex), entry_hex)
90
- head_hex_value ? parent_hex = head_hex_value : parent_hex = "none"
91
-
92
- update_head(entry_hex)
93
- new_entry.create(parent_hex, current)
94
- update_goal(new_entry.length) if goal_length
95
- end
96
-
97
- def update_head(entry_hex)
98
- File.open(head_path, 'w'){|f| f.write(entry_hex)}
99
- end
100
-
101
- def update_goal(entry_length)
102
- new_length = goal_length - entry_length
103
- File.open(goal_path, 'w'){|f| f.write(new_length)}
104
- end
105
-
106
- def delete
107
- FileUtils.rm_rf(@path) if Dir.exists?(@path)
108
- end
109
-
110
- private
111
-
112
- def write_log(state, points, owner)
113
- File.open(points_path, 'w'){|f| f.write(points)}
114
- File.open(state_path, 'w'){|f| f.write(state)}
115
- File.open(owner_path, 'w'){|f| f.write(owner)}
116
- File.open(hold_path, 'w+'){|f| f.write('hold')}
117
- File.open(goal_path, 'w'){|f| f.write(@goal)} if @goal
118
- end
119
-
120
- def read_file(path)
121
- if File.exists?(path)
122
- contents = File.read(path)
123
- contents.strip
124
- end
125
- end
126
-
127
- def head_hex_value
128
- if File.exists?(head_path)
129
- head_content = File.read(head_path)
130
- head_content.strip if head_content
131
- end
132
- end
133
-
134
- def points_path
135
- File.join(@path, 'POINTS')
136
- end
137
-
138
- def state_path
139
- File.join(@path, 'STATE')
140
- end
141
-
142
- def owner_path
143
- File.join(@path, 'OWNER')
144
- end
145
-
146
- def goal_path
147
- File.join(@path, 'GOAL')
148
- end
149
-
150
- def hold_path
151
- File.join(@path, '.HOLD')
152
- end
153
-
154
- def head_path
155
- File.join(@path, 'HEAD')
156
- end
157
-
158
- def entry_path(hex)
159
- File.join(@path, hex)
160
- end
161
-
162
- def generate_random_hex
163
- SecureRandom.hex(13)
164
- end
4
+ attr_accessor :name
5
+ attr_accessor :goal
6
+ attr_accessor :entries
7
+ attr_accessor :path
8
+
9
+ def initialize(log_path = nil)
10
+ @entries = []
11
+ if log_path
12
+ @name = log_path.basename.to_s
13
+ @path = log_path
14
+ @goal = goal_length
15
+ end
16
+ end
17
+
18
+ def create(options)
19
+ unless Dir.exists?(@path)
20
+ # Default time log attribute values
21
+ state = 'open'
22
+ points = 0
23
+ owner = 'none'
24
+
25
+ FileUtils.mkdir_p(@path)
26
+ @goal = ChronicDuration.parse(options[:goal]) if options[:goal]
27
+ state = options[:state] if options[:state]
28
+ points = options[:points] if options[:points]
29
+ owner = options[:owner] if options[:owner]
30
+ write_log(state, points, owner)
31
+ true
32
+ end
33
+ end
34
+
35
+ def goal_length
36
+ if File.exists?(goal_path)
37
+ contents = File.read(goal_path)
38
+ contents.strip
39
+ contents.to_i
40
+ end
41
+ end
42
+
43
+ def entries
44
+ log_entries = []
45
+ hex_value = head_hex_value
46
+ return log_entries unless hex_value
47
+ begin
48
+ entry = Tlog::Entity::Entry.new(entry_path(hex_value), hex_value)
49
+ hex_value = entry.parent_hex
50
+ log_entries.push(entry)
51
+ end until hex_value == "none"
52
+ return log_entries
53
+ end
54
+
55
+ def duration
56
+ dur = 0
57
+ entries.each do |entry|
58
+ dur += entry.length
59
+ end
60
+ dur
61
+ end
62
+
63
+ def owner
64
+ read_file(owner_path) if File.exists?(owner_path)
65
+ end
66
+
67
+ def state
68
+ read_file(state_path) if File.exists?(state_path)
69
+ end
70
+
71
+ def points
72
+ read_file(points_path).to_i if File.exists?(points_path)
73
+ end
74
+
75
+ def update_state(state)
76
+ File.open(state_path, 'w'){|f| f.write(state)}
77
+ end
78
+
79
+ def update_points(points)
80
+ File.open(points_path, 'w'){|f| f.write(points)}
81
+ end
82
+
83
+ def update_owner(owner)
84
+ File.open(owner_path, 'w'){|f| f.write(owner)}
85
+ end
86
+
87
+ def add_entry(current)
88
+ entry_hex = generate_random_hex
89
+ new_entry = Tlog::Entity::Entry.new(entry_path(entry_hex), entry_hex)
90
+ head_hex_value ? parent_hex = head_hex_value : parent_hex = "none"
91
+
92
+ update_head(entry_hex)
93
+ new_entry.create(parent_hex, current)
94
+ update_goal(new_entry.length) if goal_length
95
+ end
96
+
97
+ def update_head(entry_hex)
98
+ File.open(head_path, 'w'){|f| f.write(entry_hex)}
99
+ end
100
+
101
+ def update_goal(entry_length)
102
+ new_length = goal_length - entry_length
103
+ File.open(goal_path, 'w'){|f| f.write(new_length)}
104
+ end
105
+
106
+ def delete
107
+ FileUtils.rm_rf(@path) if Dir.exists?(@path)
108
+ end
109
+
110
+ private
111
+
112
+ def write_log(state, points, owner)
113
+ File.open(points_path, 'w'){|f| f.write(points)}
114
+ File.open(state_path, 'w'){|f| f.write(state)}
115
+ File.open(owner_path, 'w'){|f| f.write(owner)}
116
+ File.open(hold_path, 'w+'){|f| f.write('hold')}
117
+ File.open(goal_path, 'w'){|f| f.write(@goal)} if @goal
118
+ end
119
+
120
+ def read_file(path)
121
+ if File.exists?(path)
122
+ contents = File.read(path)
123
+ contents.strip
124
+ end
125
+ end
126
+
127
+ def head_hex_value
128
+ if File.exists?(head_path)
129
+ head_content = File.read(head_path)
130
+ head_content.strip if head_content
131
+ end
132
+ end
133
+
134
+ def points_path
135
+ File.join(@path, 'POINTS')
136
+ end
137
+
138
+ def state_path
139
+ File.join(@path, 'STATE')
140
+ end
141
+
142
+ def owner_path
143
+ File.join(@path, 'OWNER')
144
+ end
145
+
146
+ def goal_path
147
+ File.join(@path, 'GOAL')
148
+ end
149
+
150
+ def hold_path
151
+ File.join(@path, '.HOLD')
152
+ end
153
+
154
+ def head_path
155
+ File.join(@path, 'HEAD')
156
+ end
157
+
158
+ def entry_path(hex)
159
+ File.join(@path, hex)
160
+ end
161
+
162
+ def generate_random_hex
163
+ SecureRandom.hex(13)
164
+ end
165
165
  end
data/lib/tlog/error.rb CHANGED
@@ -9,4 +9,7 @@ class Tlog::Error::TimeLogNotFound < StandardError
9
9
  end
10
10
 
11
11
  class Tlog::Error::CheckoutInvalid < StandardError
12
+ end
13
+
14
+ class Tlog::Error::NotImplementedError < StandardError
12
15
  end
@@ -1,7 +1,8 @@
1
+
1
2
  class Tlog::Format::DateTime
2
3
 
3
- def self.timestamp(gmt_time)
4
- gmt_time.strftime("%B %d, %I:%M%p")
5
- end
4
+ def self.timestamp(gmt_time)
5
+ gmt_time.strftime("%B %d, %I:%M%p")
6
+ end
6
7
 
7
8
  end
@@ -1,13 +1,14 @@
1
+
1
2
  class Tlog::Format::Seconds
2
3
 
3
- def self.duration(total_seconds)
4
- output = ""
5
- total_seconds ||= 0
6
- total_seconds = total_seconds.to_i
7
- mm, ss = total_seconds.divmod(60)
8
- hh, mm = mm.divmod(60)
9
- output = "%2s:%02d:%02d" % [hh, mm, ss]
10
- return output
11
- end
4
+ def self.duration(total_seconds)
5
+ output = ""
6
+ total_seconds ||= 0
7
+ total_seconds = total_seconds.to_i
8
+ mm, ss = total_seconds.divmod(60)
9
+ hh, mm = mm.divmod(60)
10
+ output = "%2s:%02d:%02d" % [hh, mm, ss]
11
+ return output
12
+ end
12
13
 
13
14
  end
data/lib/tlog/input.rb CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
2
  class Tlog::Input
3
- attr_accessor :args
4
- attr_accessor :options
3
+ attr_accessor :args
4
+ attr_accessor :options
5
5
 
6
- def initialize(args=[])
7
- @args = args
8
- @options = {}
9
- end
6
+ def initialize(args=[])
7
+ @args = args
8
+ @options = {}
9
+ end
10
10
  end
data/lib/tlog/output.rb CHANGED
@@ -1,33 +1,33 @@
1
1
 
2
2
  class Tlog::Output
3
3
 
4
- attr_accessor :stdout
5
- attr_accessor :stderr
6
-
7
- def initialize(stdout,stderr)
8
- @stdout = stdout
9
- @stderr = stderr
10
- end
11
-
12
- def error(err)
13
- @stderr.puts err
14
- end
15
-
16
- def line(out)
17
- @stdout.puts out
18
- true
19
- end
20
-
21
- def line_yellow(out)
22
- @stdout.puts out.yellow
23
- end
24
-
25
- def line_red(out)
26
- @stdout.puts out.red
27
- end
28
-
29
- def line_blue(out)
30
- @stdout.puts out.blue
31
- end
4
+ attr_accessor :stdout
5
+ attr_accessor :stderr
6
+
7
+ def initialize(stdout,stderr)
8
+ @stdout = stdout
9
+ @stderr = stderr
10
+ end
11
+
12
+ def error(err)
13
+ @stderr.puts err
14
+ end
15
+
16
+ def line(out)
17
+ @stdout.puts out
18
+ true
19
+ end
20
+
21
+ def line_yellow(out)
22
+ @stdout.puts out.yellow
23
+ end
24
+
25
+ def line_red(out)
26
+ @stdout.puts out.red
27
+ end
28
+
29
+ def line_blue(out)
30
+ @stdout.puts out.blue
31
+ end
32
32
 
33
33
  end