Module: Devlog
- Defined in:
- lib/devlog.rb
Defined Under Namespace
Classes: Parsing, Tajm, Zezzion
Constant Summary collapse
- LIBPATH =
:stopdoc:
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- VERSION =
File.open(File.join(File.dirname(__FILE__), %w[.. VERSION]), 'r').read
- DATETIME_FORMAT =
parsing datetime
"%d.%m.%Y %H:%M:%S"
Class Method Summary collapse
- .display_version ⇒ Object
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
-
.log(txt) ⇒ Object
Write siple console log.
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
-
.version ⇒ Object
:startdoc: Returns the version string for the library.
Instance Method Summary collapse
-
#devlog_session_entry(session_type = 'Coding', begin_end = 'BEGIN') ⇒ Object
helper for the time entries.
-
#is_session_open(devlog_file = 'devlog.markdown') ⇒ Object
if the first non empty line is not and END entry then session is open (or malformed file).
- #parse_datetime(line) ⇒ Object
-
#parse_devlog(devlog = nil) ⇒ Object
this is just a historic event, not used.
- #parse_devlog_now(devlog = nil) ⇒ Object
-
#prepend_string(t = "\n", devlog_file = 'devlog.markdown') ⇒ Object
prepend a string to a text file.
-
#start_coding_session(devlog_file = 'devlog.markdown') ⇒ Object
insert a new session.
-
#stop_coding_session(devlog_file = 'devlog.markdown') ⇒ Object
close the current session, if any.
Class Method Details
.display_version ⇒ Object
52 53 54 |
# File 'lib/devlog.rb', line 52 def self.display_version "\n#{'Devlog'.green} v#{Devlog.version}\n" end |
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.
30 31 32 |
# File 'lib/devlog.rb', line 30 def self.libpath( *args ) args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) end |
.log(txt) ⇒ Object
Write siple console log
56 57 58 |
# File 'lib/devlog.rb', line 56 def self.log(txt) puts "#{txt}" end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.
37 38 39 |
# File 'lib/devlog.rb', line 37 def self.path( *args ) args.empty? ? PATH : ::File.join(PATH, args.flatten) end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
45 46 47 48 49 50 51 |
# File 'lib/devlog.rb', line 45 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.version ⇒ Object
:startdoc: Returns the version string for the library.
23 24 25 |
# File 'lib/devlog.rb', line 23 def self.version VERSION end |
Instance Method Details
#devlog_session_entry(session_type = 'Coding', begin_end = 'BEGIN') ⇒ Object
helper for the time entries
226 227 228 |
# File 'lib/devlog.rb', line 226 def devlog_session_entry(session_type='Coding', begin_end='BEGIN') "\n##{Time.now.strftime(DATETIME_FORMAT)} #{session_type}Session::#{begin_end}\n" end |
#is_session_open(devlog_file = 'devlog.markdown') ⇒ Object
if the first non empty line is not and END entry then session is open (or malformed file)
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/devlog.rb', line 246 def is_session_open(devlog_file='devlog.markdown') is_open = true File.open(devlog_file, 'r') do |f| loop do break if not line = f.gets #exit on end of file, read line if (line.strip.size>0) #non empty line if (line =~ /Session::END/) is_open = false break else break end end end end is_open end |
#parse_datetime(line) ⇒ Object
62 63 64 65 |
# File 'lib/devlog.rb', line 62 def parse_datetime(line) parts = line[1..-1].split DateTime.strptime("#{parts[0]} #{parts[1]}", DATETIME_FORMAT) end |
#parse_devlog(devlog = nil) ⇒ Object
this is just a historic event, not used
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/devlog.rb', line 180 def parse_devlog(devlog=nil) t = Tajm.new return t unless devlog timeEnd = nil timeBegin = nil in_session = false File.open(devlog, "r").each do |line| if line =~ /-NOCHARGE/ in_session = false #do not count nocharge sessions elsif line =~ /\A#/ && line =~ /CodingSession::END/ in_session = true timeEnd = parse_datetime(line) elsif line =~ /\A#/ && line =~ /CodingSession::BEGIN/ if in_session in_session = false timeBegin = parse_datetime(line) #cs_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds t.coding_session_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds end elsif line =~ /\A#/ && line =~ /ComSession::END/ in_session = true timeEnd = parse_datetime(line) elsif line =~ /\A#/ && line =~ /ComSession::BEGIN/ if in_session in_session = false timeBegin = parse_datetime(line) t.com_session_time += (timeEnd - timeBegin).to_f * 24 end elsif line =~ /\A\+[0-9]+[h]/ t.com_session_time += line.to_f elsif line =~ /\A\+[0-9]+[m]/ t.com_session_time += (line.to_f / 60) elsif line =~ /\A\-[0-9]+[h]/ t.payed_time += (line.to_f) end end #return the Tajm object t end |
#parse_devlog_now(devlog = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/devlog.rb', line 67 def parse_devlog_now(devlog=nil) t = Parsing.new t.devlog_file = devlog return t unless devlog return t unless File.exist?(devlog) timeEnd = nil timeBegin = nil timeEnd_line_number = nil timeBegin_line_number = nil in_session = false temp_zezzion = nil line_number = 0 File.open(devlog, "r").each do |line| line_number+=1 if line =~ /-NOCHARGE/ in_session = false #do not count nocharge sessions, this is a secret feature elsif line =~ /\A#/ && line =~ /CodingSession::END/ in_session = true timeEnd = parse_datetime(line) timeEnd_line_number = line_number #zezzion temp_zezzion = Zezzion.new temp_zezzion.zzend = timeEnd temp_zezzion.zzend_line_number = timeEnd_line_number elsif line =~ /\A#/ && line =~ /CodingSession::BEGIN/ if in_session in_session = false timeBegin = parse_datetime(line) timeBegin_line_number = line_number #cs_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds delta = (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds t.coding_session_time += delta #zezzion temp_zezzion.coding_session_time += delta temp_zezzion.zzbegin = timeBegin temp_zezzion.zzbegin_line_number = timeBegin_line_number t.add_zezzion temp_zezzion temp_zezzion = nil end elsif line =~ /\A#/ && line =~ /ComSession::END/ in_session = true timeEnd = parse_datetime(line) timeEnd_line_number = line_number #zezzion temp_zezzion = Zezzion.new(Zezzion::COM) temp_zezzion.zzend = timeEnd temp_zezzion.zzend_line_number = timeEnd_line_number elsif line =~ /\A#/ && line =~ /ComSession::BEGIN/ if in_session in_session = false timeBegin = parse_datetime(line) timeBegin_line_number = line_number delta = (timeEnd - timeBegin).to_f * 24 t.com_session_time += delta #zezzion temp_zezzion.coding_session_time += delta temp_zezzion.zzbegin = timeBegin temp_zezzion.zzbegin_line_number = timeBegin_line_number t.add_zezzion temp_zezzion temp_zezzion = nil end elsif line =~ /\A\+[0-9]+[h]/ delta = line.to_f t.com_session_time += delta #zezzion if temp_zezzion temp_zezzion.com_session_time += delta else puts "error adding temp_zezzion com_session_time at line: #{line}" end elsif line =~ /\A\+[0-9]+[m]/ delta = (line.to_f / 60) t.com_session_time += delta #zezzion if temp_zezzion temp_zezzion.com_session_time += delta else puts "error adding temp_zezzion com_session_time at line: #{line}" end elsif line =~ /\A\-[0-9]+[h]/ delta = (line.to_f) t.payed_time += delta #zezzion if temp_zezzion temp_zezzion.payed_time += delta else puts "error adding temp_zezzion delta time at line: #{line}" end end end #return the Parsing object t end |
#prepend_string(t = "\n", devlog_file = 'devlog.markdown') ⇒ Object
prepend a string to a text file
231 232 233 |
# File 'lib/devlog.rb', line 231 def prepend_string(t="\n", devlog_file='devlog.markdown') system "echo '#{t}' | cat - #{devlog_file} > #{devlog_file}.tmp && mv #{devlog_file}.tmp #{devlog_file}" end |
#start_coding_session(devlog_file = 'devlog.markdown') ⇒ Object
insert a new session
236 237 238 |
# File 'lib/devlog.rb', line 236 def start_coding_session(devlog_file='devlog.markdown') prepend_string(devlog_session_entry('Coding', 'BEGIN'), devlog_file) end |
#stop_coding_session(devlog_file = 'devlog.markdown') ⇒ Object
close the current session, if any
241 242 243 |
# File 'lib/devlog.rb', line 241 def stop_coding_session(devlog_file='devlog.markdown') prepend_string(devlog_session_entry('Coding', 'END'), devlog_file) end |