devlog 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f476f2c6ab76e00904a225dde4bb72747bd5fc4
4
- data.tar.gz: ea182129ccc5398cec398a4019695d2b8f6c38a2
3
+ metadata.gz: 839f5c63004556d46fb81536bb83d211f35fba56
4
+ data.tar.gz: e24ff4540d187bec26a6f8879a329d2bb7266f47
5
5
  SHA512:
6
- metadata.gz: 2dd9c1464366e4739406f15c18338737710009f808af2fea868b697cc05b23bbbdac6e937e6887ad41a5d04e517ddd946df9d4a43c7188bebd933160b60ceb91
7
- data.tar.gz: ae709d70274481ab35dea6981313cfb35a2c9600588721f13331b0958d4ff27ffd12dc80c9197af35a129c2e01c6c2783f7a02df420185ea8a21326e26664962
6
+ metadata.gz: 420cc743b4dd152b7f3e57f77738e23d7b55b6aa6eb211a290a9d90bfa3fc54c9433d12cefc1739ca80630a59b3ed895e68e7a9013a03d434ffd5d135437e3ca
7
+ data.tar.gz: 851b1462545d70be06f06dfbe1fbca097ea24cb1c92452e1295a6f2cc6286c5469d31c8d59b715ad503bc418c9d1dbcf7386dbb412c252f70d139f2c89bf0f2f
data/.travis.yml CHANGED
@@ -2,5 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.3.0"
5
+ before_install:
6
+ - bundle update rdoc
5
7
  # uncomment this line if your project needs to run something other than `rake`:
6
8
  # script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
- gem "activesupport", ">= 4.1"
2
+ gem "activesupport", "~> 4.1"
3
3
 
4
4
  group :development, :test do
5
- gem "test-unit"
5
+ gem "test-unit", "~> 3.1"
6
6
  gem "jeweler", "~> 2.0"
7
7
  end
data/Gemfile.lock CHANGED
@@ -62,9 +62,9 @@ PLATFORMS
62
62
  ruby
63
63
 
64
64
  DEPENDENCIES
65
- activesupport (>= 4.1)
65
+ activesupport (~> 4.1)
66
66
  jeweler (~> 2.0)
67
- test-unit
67
+ test-unit (~> 3.1)
68
68
 
69
69
  BUNDLED WITH
70
70
  1.11.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/bin/devlog CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'benchmark'
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib devlog.rb]))
4
- USAGE= <<-EOF
4
+ USAGE = <<-EOF
5
5
  #{Devlog.display_version}
6
6
  This software is intended to parse and present information within devlog.markdown development logs. It also helps You to write the devlog.
7
7
 
@@ -13,7 +13,7 @@ Using with a file, for parsing and seeing the information summary:
13
13
 
14
14
  or in a folder with a 'devlog.markdown' file in it:
15
15
 
16
- #{'devlog'.green}
16
+ #{'devlog'.green}
17
17
 
18
18
  write commands for the current folder, the top three:
19
19
 
@@ -32,40 +32,54 @@ exporting devlog into a book, which can be read top down, like normal books:
32
32
  #{'devlog'.green} x ~ exports into devlog.txt
33
33
 
34
34
  EOF
35
- #arguments
35
+
36
+ # arguments
36
37
  $:.unshift File.join(File.dirname(__FILE__))
37
38
  @in_file_or_cmd = ARGV[0]
39
+
40
+ def print_backtrace(exception)
41
+ exception.backtrace.join("\n\t").to_s.blue
42
+ end
43
+
38
44
  def print_usage
39
45
  puts USAGE
40
46
  end
41
- def parse_now(devlog_file='devlog.markdown', msg='')
47
+
48
+ def parse_now(devlog_file = 'devlog.markdown', msg = '')
42
49
  puts msg
43
50
  t = parse_devlog_now(devlog_file)
44
51
  puts t.validation_string
45
52
  puts t.to_info_string
46
53
  puts is_session_open(devlog_file) ? "\nSession is open...".yellow : "\nNo open session.".green
47
54
  end
48
- def export_now(devlog_file='devlog.markdown', msg='')
55
+
56
+ def export_now(devlog_file = 'devlog.markdown', msg = '')
49
57
  puts msg
50
58
  exported_file = export_devlog_now(devlog_file)
51
59
  puts "\nExported to #{exported_file}.".yellow
52
60
  end
61
+
62
+ include Devlog
63
+
53
64
  def dodo
54
- include Devlog
65
+ load_settings('.devlog.yml')
66
+ default_devlog_file = devlog_file_setting
55
67
  time = Benchmark.realtime do
56
-
57
- if @in_file_or_cmd == 'help'
68
+ if @in_file_or_cmd =~ /.(markdown|md)$/ # devlog_file is passed directly via CLI
69
+ @settings = nil
70
+ parse_now(@in_file_or_cmd, "Parsing #{@in_file_or_cmd}!".red)
71
+ elsif @in_file_or_cmd == 'help'
58
72
  print_usage
59
73
  elsif @in_file_or_cmd == 'x'
60
- export_now('devlog.markdown',"Exporting devlog.markdown in current folder...".green)
74
+ export_now(default_devlog_file, "Exporting #{default_devlog_file}...".green)
61
75
  elsif @in_file_or_cmd == 'commit'
62
76
  `git commit -am 'devlog';git push`
63
77
  elsif @in_file_or_cmd == 'b'
64
78
  puts "CodingSession::BEGIN"
65
- start_coding_session("devlog.markdown")
79
+ start_coding_session(default_devlog_file)
66
80
  elsif @in_file_or_cmd == 'e'
67
81
  puts "CodingSession::END"
68
- stop_coding_session("devlog.markdown")
82
+ stop_coding_session(default_devlog_file)
69
83
  elsif @in_file_or_cmd == 'i'
70
84
  puts "Save info.markdown"
71
85
  save_info("devlog.markdown")
@@ -77,29 +91,27 @@ def dodo
77
91
  `git push`
78
92
  elsif @in_file_or_cmd == 'save'
79
93
  puts "Save info.markdown and Commit and push git"
80
- save_info("devlog.markdown")
94
+ save_info(default_devlog_file)
81
95
  `git commit -am "devlog" && git push`
82
96
  elsif @in_file_or_cmd == 'saver'
83
97
  puts "Save info.markdown, copy devlog to README.markdown and Commit and push git"
84
- save_info("devlog.markdown")
85
- save_to_readme("devlog.markdown")
98
+ save_info(default_devlog_file)
99
+ save_to_readme(default_devlog_file)
86
100
  `git commit -am "devlog" && git push`
87
101
  elsif @in_file_or_cmd == 's'
88
- puts is_session_open("devlog.markdown") ? "Session is open..." : "No open session."
89
- elsif @in_file_or_cmd =~ /markdown/
90
- parse_now(@in_file_or_cmd, "Parsing #{@in_file_or_cmd}...".red)
102
+ puts is_session_open(default_devlog_file) ? "Session is open..." : "No open session."
91
103
  else
92
- parse_now('devlog.markdown', "Parsing devlog.markdown in current folder...".green)
104
+ parse_now(default_devlog_file, "Parsing #{default_devlog_file}...".green)
93
105
  end
94
-
95
- end
96
- puts "\n\n"
97
- #puts "\nRealtime: #{time}sec\n\n"
106
+ end
107
+ puts "\n\n"
108
+ puts "\nRealtime: #{time}sec\n\n"
98
109
  end
99
- #devlog run
110
+
111
+ # devlog run
100
112
  begin
101
113
  dodo
102
- rescue Exception => e
103
- puts "\nRuntime exception: #{e.message.to_s.blue}\n"
104
- print_usage
105
- end
114
+ rescue StandardError => e
115
+ puts "\nRuntime exception: #{e.message.to_s.blue}\nBacktrace:\n#{print_backtrace(e)}"
116
+ print_usage
117
+ end
data/devlog.gemspec CHANGED
@@ -2,19 +2,19 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: devlog 0.2.0 ruby lib
5
+ # stub: devlog 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "devlog"
9
- s.version = "0.2.0"
8
+ s.name = "devlog".freeze
9
+ s.version = "0.3.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["mihael"]
14
- s.date = "2016-01-24"
15
- s.description = "devlog.markdown time&space extractor"
16
- s.email = "kitschmaster@gmail.com"
17
- s.executables = ["devlog"]
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["mihael".freeze]
14
+ s.date = "2018-01-08"
15
+ s.description = "devlog.markdown time&space extractor".freeze
16
+ s.email = "kitschmaster@gmail.com".freeze
17
+ s.executables = ["devlog".freeze]
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE",
20
20
  "README.md"
@@ -32,9 +32,8 @@ Gem::Specification.new do |s|
32
32
  "bin/devlog",
33
33
  "devlog.gemspec",
34
34
  "devlog.markdown",
35
- "empty_devlog.markdown",
36
35
  "lib/devlog.rb",
37
- "sublime_text/.DS_Store",
36
+ "lib/devlog_settings.rb",
38
37
  "sublime_text/devlog.tmbundle/Snippets/begin.tmSnippet",
39
38
  "sublime_text/devlog.tmbundle/Snippets/combegin.tmSnippet",
40
39
  "sublime_text/devlog.tmbundle/Snippets/comend.tmSnippet",
@@ -45,36 +44,43 @@ Gem::Specification.new do |s|
45
44
  "sublime_text/devlog.tmbundle/Snippets/tu.tmSnippet",
46
45
  "sublime_text/devlog.tmbundle/info.plist",
47
46
  "sublime_text/tu.py",
47
+ "test/devlog_file_test.rb",
48
+ "test/devlog_settings_test.rb",
48
49
  "test/devlog_test.rb",
50
+ "test/test_devlogs/.devlog.yml",
51
+ "test/test_devlogs/empty_devlog.markdown",
52
+ "test/test_devlogs/test_devlog.markdown",
53
+ "test/test_devlogs/test_devlog_export.markdown",
54
+ "test/test_devlogs/test_invalid_date_devlog.markdown",
55
+ "test/test_devlogs/test_negative_devlog.markdown",
56
+ "test/test_devlogs/test_open_devlog.markdown",
57
+ "test/test_devlogs/test_settings.yml",
58
+ "test/test_devlogs/test_single_devlog.markdown",
59
+ "test/test_devlogs/test_stats_devlog.markdown",
49
60
  "test/test_helper.rb",
50
- "test_devlog.markdown",
51
- "test_devlog_export.markdown",
52
- "test_negative_devlog.markdown",
53
- "test_open_devlog.markdown",
54
- "test_single_devlog.markdown",
55
- "test_stats_devlog.markdown"
61
+ "tmp/.gitignore"
56
62
  ]
57
- s.homepage = "http://github.com/mihael/devlog"
58
- s.licenses = ["MIT"]
59
- s.rubygems_version = "2.5.1"
60
- s.summary = "takes devlog.markdown and gives info"
63
+ s.homepage = "http://github.com/mihael/devlog".freeze
64
+ s.licenses = ["MIT".freeze]
65
+ s.rubygems_version = "2.5.2".freeze
66
+ s.summary = "takes devlog.markdown and gives info".freeze
61
67
 
62
68
  if s.respond_to? :specification_version then
63
69
  s.specification_version = 4
64
70
 
65
71
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<activesupport>, [">= 4.1"])
67
- s.add_development_dependency(%q<test-unit>, [">= 0"])
68
- s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
72
+ s.add_runtime_dependency(%q<activesupport>.freeze, ["~> 4.1"])
73
+ s.add_development_dependency(%q<test-unit>.freeze, ["~> 3.1"])
74
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.0"])
69
75
  else
70
- s.add_dependency(%q<activesupport>, [">= 4.1"])
71
- s.add_dependency(%q<test-unit>, [">= 0"])
72
- s.add_dependency(%q<jeweler>, ["~> 2.0"])
76
+ s.add_dependency(%q<activesupport>.freeze, ["~> 4.1"])
77
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3.1"])
78
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
73
79
  end
74
80
  else
75
- s.add_dependency(%q<activesupport>, [">= 4.1"])
76
- s.add_dependency(%q<test-unit>, [">= 0"])
77
- s.add_dependency(%q<jeweler>, ["~> 2.0"])
81
+ s.add_dependency(%q<activesupport>.freeze, ["~> 4.1"])
82
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3.1"])
83
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
78
84
  end
79
85
  end
80
86
 
data/devlog.markdown CHANGED
@@ -1,3 +1,35 @@
1
+ #08.01.2018 21:56:04 CodingSession::END
2
+
3
+ doing some more work on settings.
4
+
5
+ the idea is to optionally have a file with the following name `.devlog.yml` in a folder where You want to work with devlog. this allows writing the devlog in an arbitrary folder relative to the settings file.
6
+
7
+ ii was also thinking about doing convention, simply always look for a `devlog.markdown` in the current folder, and then one up and so on... but ended up going with a setting. so by default `devlog.markdown` is expected to live in the folder where the CLI command is spawned: `devlog`. if there's a settings file instead, and it overrides `devlog_file` path, then that is used instead (but only if it exists).
8
+
9
+ done. this is already nice, now I can finally run `devlog` from the project folder and keep my devlog out of it.
10
+
11
+ now, it would be good to also publish this to the world.
12
+
13
+ so let's see... this time I can actually create a PR and reference an [issue](https://github.com/mihael/devlog/issues/7) for it.
14
+
15
+ the new version will be 0.3.0.
16
+
17
+ #08.01.2018 20:01:28 CodingSession::BEGIN
18
+
19
+ #14.06.2017 00:28:08 CodingSession::END
20
+
21
+ ah, well, still not done. cleaning up some more...
22
+
23
+ #14.06.2017 00:00:01 CodingSession::BEGIN
24
+
25
+ #13.06.2017 23:59:11 CodingSession::END
26
+
27
+ doing some cleanup... have a bunch of Issues that need to be implemented.
28
+
29
+ but starting with invalid date parsing problem, want to see the line that caused it. done.
30
+
31
+ #13.06.2017 22:30:56 CodingSession::BEGIN
32
+
1
33
  #24.01.2016 20:44:45 CodingSession::END
2
34
 
3
35
  ii can now export the devlog. the top session becomes the bottom one, and a human can read the devlog like a book: top down...
data/lib/devlog.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  #require "time"
2
2
  #require "date"
3
3
  require "active_support/all"
4
+ require_relative "./devlog_settings"
4
5
 
6
+ # Colors for devlog
5
7
  class String
6
8
  def red; colorize(self, "\e[1m\e[31m"); end
7
9
  def green; colorize(self, "\e[1m\e[32m"); end
@@ -12,59 +14,70 @@ class String
12
14
  def pur; colorize(self, "\e[1m\e[35m"); end
13
15
  def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
14
16
  end
17
+
18
+ # The devlog module with all the mumbo
15
19
  module Devlog
16
20
  # :stopdoc:
17
21
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
18
22
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
19
23
  VERSION = File.open(File.join(File.dirname(__FILE__), %w[.. VERSION]), 'r').read
24
+
20
25
  # :startdoc:
21
26
  # Returns the version string for the library.
22
27
  #
23
28
  def self.version
24
29
  VERSION
25
30
  end
31
+
26
32
  # Returns the library path for the module. If any arguments are given,
27
33
  # they will be joined to the end of the libray path using
28
34
  # <tt>File.join</tt>.
29
35
  #
30
- def self.libpath( *args )
36
+ def self.libpath(*args)
31
37
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
32
38
  end
39
+
33
40
  # Returns the lpath for the module. If any arguments are given,
34
41
  # they will be joined to the end of the path using
35
42
  # <tt>File.join</tt>.
36
43
  #
37
- def self.path( *args )
44
+ def self.path(*args)
38
45
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
39
46
  end
47
+
40
48
  # Utility method used to require all files ending in .rb that lie in the
41
49
  # directory below this file that has the same name as the filename passed
42
50
  # in. Optionally, a specific _directory_ name can be passed in such that
43
51
  # the _filename_ does not have to be equivalent to the directory.
44
52
  #
45
- def self.require_all_libs_relative_to( fname, dir = nil )
53
+ def self.require_all_libs_relative_to(fname, dir = nil)
46
54
  dir ||= ::File.basename(fname, '.*')
47
55
  search_me = ::File.expand_path(
48
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
56
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb')
57
+ )
49
58
 
50
- Dir.glob(search_me).sort.each {|rb| require rb}
59
+ Dir.glob(search_me).sort.each { |rb| require rb }
51
60
  end
61
+
52
62
  def self.display_version
53
63
  "\n#{'Devlog'.green} v#{Devlog.version}\n"
54
64
  end
55
- # Write siple console log
65
+
66
+ # Write simple console log
56
67
  def self.log(txt)
57
68
  puts "#{txt}"
58
69
  end
59
70
 
60
- #parsing datetime
61
- DATETIME_FORMAT = "%d.%m.%Y %H:%M:%S"
71
+ # Parsing datetime
72
+ DATETIME_FORMAT = '%d.%m.%Y %H:%M:%S'.freeze
62
73
  def parse_datetime(line)
63
74
  parts = line[1..-1].split
64
75
  DateTime.strptime("#{parts[0]} #{parts[1]}", DATETIME_FORMAT)
76
+ rescue StandardError
77
+ abort "\nError\nCan not parse line with invalid date:\n\n#{line}".to_s.blue
65
78
  end
66
79
 
67
- def parse_devlog_now(devlog=nil)
80
+ def parse_devlog_now(devlog = nil)
68
81
  t = Parsing.new
69
82
  t.devlog_file = devlog
70
83
 
@@ -79,17 +92,17 @@ module Devlog
79
92
  temp_zezzion = nil
80
93
 
81
94
  line_number = 0
82
- File.open(devlog, "r").each do |line|
83
- line_number+=1
95
+ File.open(devlog, 'r').each do |line|
96
+ line_number += 1
84
97
 
85
98
  if line =~ /-NOCHARGE/
86
- in_session = false #do not count nocharge sessions, this is a secret feature
99
+ in_session = false # do not count nocharge sessions, this is a secret feature
87
100
  elsif line =~ /\A#/ && line =~ /CodingSession::END/
88
101
  in_session = true
89
102
  timeEnd = parse_datetime(line)
90
103
  timeEnd_line_number = line_number
91
104
 
92
- #zezzion
105
+ # zezzion
93
106
  temp_zezzion = Zezzion.new
94
107
  temp_zezzion.zzend = timeEnd
95
108
  temp_zezzion.zzend_line_number = timeEnd_line_number
@@ -100,11 +113,11 @@ module Devlog
100
113
  timeBegin = parse_datetime(line)
101
114
  timeBegin_line_number = line_number
102
115
 
103
- #cs_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds
116
+ # cs_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds
104
117
  delta = (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds
105
118
  t.coding_session_time += delta
106
119
 
107
- #zezzion
120
+ # zezzion
108
121
  temp_zezzion.coding_session_time += delta
109
122
  temp_zezzion.zzbegin = timeBegin
110
123
  temp_zezzion.zzbegin_line_number = timeBegin_line_number
@@ -117,7 +130,7 @@ module Devlog
117
130
  timeEnd = parse_datetime(line)
118
131
  timeEnd_line_number = line_number
119
132
 
120
- #zezzion
133
+ # zezzion
121
134
  temp_zezzion = Zezzion.new(Zezzion::COM)
122
135
  temp_zezzion.zzend = timeEnd
123
136
  temp_zezzion.zzend_line_number = timeEnd_line_number
@@ -131,7 +144,7 @@ module Devlog
131
144
  delta = (timeEnd - timeBegin).to_f * 24
132
145
  t.com_session_time += delta
133
146
 
134
- #zezzion
147
+ # zezzion
135
148
  temp_zezzion.coding_session_time += delta
136
149
  temp_zezzion.zzbegin = timeBegin
137
150
  temp_zezzion.zzbegin_line_number = timeBegin_line_number
@@ -143,7 +156,7 @@ module Devlog
143
156
  delta = line.to_f
144
157
  t.com_session_time += delta
145
158
 
146
- #zezzion
159
+ # zezzion
147
160
  if temp_zezzion
148
161
  temp_zezzion.com_session_time += delta
149
162
  else
@@ -153,7 +166,7 @@ module Devlog
153
166
  delta = (line.to_f / 60)
154
167
  t.com_session_time += delta
155
168
 
156
- #zezzion
169
+ # zezzion
157
170
  if temp_zezzion
158
171
  temp_zezzion.com_session_time += delta
159
172
  else
@@ -163,77 +176,32 @@ module Devlog
163
176
  delta = (line.to_f)
164
177
  t.payed_time += delta
165
178
 
166
- #zezzion
179
+ # zezzion
167
180
  if temp_zezzion
168
181
  temp_zezzion.payed_time += delta
169
182
  else
170
183
  puts "error adding temp_zezzion delta time at line: #{line}"
171
184
  end
172
185
  end
173
-
174
186
  end
175
- #return the Parsing object
187
+ # return the Parsing object
176
188
  t
177
189
  end
178
190
 
179
- #this is just a historic event, not used
180
- def parse_devlog(devlog=nil)
181
- t = Tajm.new
182
- return t unless devlog
183
-
184
- timeEnd = nil
185
- timeBegin = nil
186
- in_session = false
191
+ # Workflow methods
187
192
 
188
- File.open(devlog, "r").each do |line|
189
- if line =~ /-NOCHARGE/
190
- in_session = false #do not count nocharge sessions
191
- elsif line =~ /\A#/ && line =~ /CodingSession::END/
192
- in_session = true
193
- timeEnd = parse_datetime(line)
194
- elsif line =~ /\A#/ && line =~ /CodingSession::BEGIN/
195
- if in_session
196
- in_session = false
197
- timeBegin = parse_datetime(line)
198
- #cs_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds
199
- t.coding_session_time += (timeEnd - timeBegin).to_f * 24 #hours *60 #minutes *60 #seconds
200
- end
201
- elsif line =~ /\A#/ && line =~ /ComSession::END/
202
- in_session = true
203
- timeEnd = parse_datetime(line)
204
- elsif line =~ /\A#/ && line =~ /ComSession::BEGIN/
205
- if in_session
206
- in_session = false
207
- timeBegin = parse_datetime(line)
208
- t.com_session_time += (timeEnd - timeBegin).to_f * 24
209
- end
210
- elsif line =~ /\A\+[0-9]+[h]/
211
- t.com_session_time += line.to_f
212
- elsif line =~ /\A\+[0-9]+[m]/
213
- t.com_session_time += (line.to_f / 60)
214
- elsif line =~ /\A\-[0-9]+[h]/
215
- t.payed_time += (line.to_f)
216
- end
217
-
218
- end
219
- #return the Tajm object
220
- t
221
- end
222
-
223
- #workflow methods
224
-
225
- #helper for the time entries
226
- def devlog_session_entry(session_type='Coding', begin_end='BEGIN')
193
+ # Helper for the time entries
194
+ def devlog_session_entry(session_type = 'Coding', begin_end = 'BEGIN')
227
195
  "\n##{Time.now.strftime(DATETIME_FORMAT)} #{session_type}Session::#{begin_end}\n"
228
196
  end
229
197
 
230
- #prepend a string to a text file
231
- #def prepend_string(t="\n", devlog_file='devlog.markdown')
232
- # system "echo '#{t}' | cat - #{devlog_file} > #{devlog_file}.tmp && mv #{devlog_file}.tmp #{devlog_file}"
233
- #end
198
+ # Prepend a string to a text file
199
+ # def prepend_string(t="\n", devlog_file='devlog.markdown')
200
+ # system "echo '#{t}' | cat - #{devlog_file} > #{devlog_file}.tmp && mv #{devlog_file}.tmp #{devlog_file}"
201
+ # end
234
202
 
235
203
  require 'tempfile'
236
- def prepend_string(string="\n", path)
204
+ def prepend_string(path, string = "\n")
237
205
  Tempfile.open File.basename(path) do |tempfile|
238
206
  tempfile << string
239
207
  File.open(path, 'r+') do |file|
@@ -245,17 +213,17 @@ module Devlog
245
213
  end
246
214
 
247
215
  #insert a new session
248
- def start_coding_session(devlog_file='devlog.markdown')
249
- prepend_string(devlog_session_entry('Coding', 'BEGIN'), devlog_file)
216
+ def start_coding_session(devlog_file = 'devlog.markdown')
217
+ prepend_string(devlog_file, devlog_session_entry('Coding', 'BEGIN'))
250
218
  end
251
219
 
252
220
  #close the current session, if any
253
- def stop_coding_session(devlog_file='devlog.markdown')
254
- prepend_string(devlog_session_entry('Coding', 'END'), devlog_file)
221
+ def stop_coding_session(devlog_file = 'devlog.markdown')
222
+ prepend_string(devlog_file, devlog_session_entry('Coding', 'END'))
255
223
  save_info(devlog_file)
256
224
  end
257
225
 
258
- def save_info(devlog_file='devlog.markdown', info_file='info.markdown')
226
+ def save_info(devlog_file = 'devlog.markdown', info_file = 'info.markdown')
259
227
  info = parse_devlog_now(devlog_file)
260
228
  if info.has_info?
261
229
  File.open(File.join(File.dirname(devlog_file), info_file), 'w') {|f| f.write(info.to_info_string(short=true)) }
@@ -264,17 +232,17 @@ module Devlog
264
232
  end
265
233
  end
266
234
 
267
- def save_to_readme(devlog_file='devlog.markdown')
235
+ def save_to_readme(devlog_file = 'devlog.markdown')
268
236
  `cp #{devlog_file} #{File.join(File.dirname(devlog_file), 'README.markdown')}`
269
237
  end
270
238
 
271
- #if the first non empty line is not and END entry then session is open (or malformed file)
272
- def is_session_open(devlog_file='devlog.markdown')
239
+ # If the first non empty line is not and END entry then session is open (or malformed file)
240
+ def is_session_open(devlog_file = 'devlog.markdown')
273
241
  is_open = true
274
242
  File.open(devlog_file, 'r') do |f|
275
243
  loop do
276
- break if not line = f.gets #exit on end of file, read line
277
- if (line.strip.size>0) #non empty line
244
+ break if not line = f.gets # exit on end of file, read line
245
+ if (line.strip.size>0) # non empty line
278
246
  if (line =~ /Session::END/)
279
247
  is_open = false
280
248
  break
@@ -287,21 +255,21 @@ module Devlog
287
255
  is_open
288
256
  end
289
257
 
290
- def export_devlog_now(devlog_file='devlog.markdown')
258
+ def export_devlog_now(devlog_file = 'devlog.markdown')
291
259
  devlog_export_file = File.join(File.dirname(devlog_file), 'devlog_book.markdown')
292
- #`sed -n '1!G;h;$p' #{devlog_file} > #{devlog_export_file}` #not what we want! , we want just the sessions upside down, but text intact
293
- #so need to parse all sessions and print them out in reverse!
260
+ # `sed -n '1!G;h;$p' #{devlog_file} > #{devlog_export_file}` #not what we want! , we want just the sessions upside down, but text intact
261
+ # so need to parse all sessions and print them out in reverse!
294
262
 
295
263
  sessionEnd = ''
296
264
  sessionMidd = ''
297
265
  sessionBegin = ''
298
266
  in_session = false
299
267
 
300
- #the ends are the begins, the begins are the ends
268
+ # The ends are the begins, the begins are the ends
301
269
 
302
270
  File.new(devlog_export_file, 'wb')
303
271
 
304
- File.open(devlog_file, "r").each do |line|
272
+ File.open(devlog_file, 'r').each do |line|
305
273
  if line =~ /-NOCHARGE/
306
274
  in_session = false #do not export nocharge sessions
307
275
  elsif line =~ /\A#/ && (line =~ /CodingSession::END/ || line =~ /ComSession::END/ )
@@ -312,8 +280,8 @@ module Devlog
312
280
  in_session = false
313
281
  sessionBegin = line
314
282
  s = sessionBegin + sessionMidd + sessionEnd
315
- #system "echo '#{s}' | cat - #{devlog_export_file} > #{devlog_export_file}.tmp && mv #{devlog_export_file}.tmp #{devlog_export_file}"
316
- prepend_string(s, devlog_export_file)
283
+ # system "echo '#{s}' | cat - #{devlog_export_file} > #{devlog_export_file}.tmp && mv #{devlog_export_file}.tmp #{devlog_export_file}"
284
+ prepend_string(devlog_export_file, s)
317
285
  sessionEnd = ''
318
286
  sessionMidd = ''
319
287
  sessionBegin = ''
@@ -326,23 +294,23 @@ module Devlog
326
294
  devlog_export_file
327
295
  end
328
296
 
329
- #the parsing object
297
+ # The parsing object
330
298
  class Parsing
331
- #this is the total time, but each session has these same params
299
+ # this is the total time, but each session has these same params
332
300
  attr_accessor :coding_session_time, :com_session_time, :payed_time #backward compatible object with Tajm, from devlog 0.0.0
333
301
 
334
302
  attr_accessor :zezzions, :devlog_file
335
303
 
336
- def initialize(viewing_time_current_date=DateTime.now)
304
+ def initialize(viewing_time_current_date = DateTime.now)
337
305
  @viewing_time_current_date = viewing_time_current_date
338
306
  @zezzions = []
339
307
 
340
- #backward compatible object with Tajm, from devlog 0.0.0
308
+ # backward compatible object with Tajm, from devlog 0.0.0
341
309
  @coding_session_time = 0.0
342
310
  @com_session_time = 0.0
343
311
  @payed_time = 0.0
344
312
 
345
- @devlog_file = ""
313
+ @devlog_file = ''
346
314
  end
347
315
 
348
316
  def has_info?
@@ -353,68 +321,70 @@ module Devlog
353
321
  @zezzions << zezzion
354
322
  end
355
323
 
356
- #global devlog start, first entry
324
+ # global devlog start, first entry
357
325
  def devlog_begin
358
326
  @zezzions.last.zzbegin
359
327
  end
360
328
 
361
- #global devlog end, last entry
329
+ # global devlog end, last entry
362
330
  def devlog_end
363
331
  @zezzions.first.zzend
364
332
  end
365
333
 
366
- #how much time between first session begin and last session end
367
- #in seconds
368
- #def devlog_time
369
- # (self.devlog_end.to_time - self.devlog_begin.to_time)/60.0/60.0
370
- #end
334
+ # how much time between first session begin and last session end
335
+ # in seconds
336
+ # def devlog_time
337
+ # (self.devlog_end.to_time - self.devlog_begin.to_time)/60.0/60.0
338
+ # end
371
339
 
372
340
  def session_time
373
- @zezzions.inject(time=0){|time, zezzion| time+zezzion.session_time}.round(2)
341
+ @zezzions.inject(0) { |time, zezzion| time + zezzion.session_time }.round(2)
374
342
  end
375
343
 
376
- #how many days devlog spans
344
+ # how many days devlog spans
377
345
  def devlog_days
378
- count_time(:days=>1)
379
- #(self.devlog_end - self.devlog_begin).to_i + 1 #counting days like this, would not account for daylight saving changes
346
+ count_time( :days => 1)
347
+ # (self.devlog_end - self.devlog_begin).to_i + 1 #counting days like this, would not account for daylight saving changes
380
348
  end
381
349
 
382
- #how many weeks devlog spans
350
+ # how many weeks devlog spans
383
351
  def devlog_weeks
384
352
  (devlog_days/7.0).round(2)
385
353
  end
386
354
 
387
355
  def devlog_months
388
- count_time(:months=>1)
356
+ count_time( :months => 1)
389
357
  end
390
358
 
391
- #hours per day
359
+ # hours per day
392
360
  def per_day
393
361
  (self.session_time/self.devlog_days).round(2)
394
362
  end
363
+
395
364
  def per_week
396
365
  (self.session_time/self.devlog_weeks).round(2)
397
366
  end
367
+
398
368
  def per_month
399
369
  (self.session_time/self.devlog_months).round(2)
400
370
  end
401
371
 
402
- #total charge time in hours, coding plus communication sessions
372
+ # total charge time in hours, coding plus communication sessions
403
373
  def charge_time
404
374
  (coding_session_time + com_session_time).round(2)
405
375
  end
406
376
 
407
- #total charge time in hours, coding plus communication sessions - payed hours
377
+ # total charge time in hours, coding plus communication sessions - payed hours
408
378
  def unpayed_time
409
379
  (coding_session_time + com_session_time + payed_time).round(2)
410
380
  end
411
381
 
412
- #return hours worked for the last X days, from beginTime
413
- def hours_for_last(days, beginTime=DateTime.now)
382
+ # return hours worked for the last X days, from beginTime
383
+ def hours_for_last(days, beginTime = DateTime.now)
414
384
  endTime = beginTime.to_time - days.days
415
- selected_zezzions = @zezzions.select{|z| z.zzbegin.to_time<beginTime && z.zzend>=endTime}
416
- #puts("Selected sessons from #{beginTime} to #{endTime}: #{selected_zezzions.size}")
417
- selected_zezzions.inject(time=0){|time, z| time+z.session_time}.round(2)
385
+ selected_zezzions = @zezzions.select { |z| z.zzbegin.to_time < beginTime && z.zzend >= endTime }
386
+ # puts("Selected sessons from #{beginTime} to #{endTime}: #{selected_zezzions.size}")
387
+ selected_zezzions.inject(0) { |time, z| time + z.session_time }.round(2)
418
388
  end
419
389
 
420
390
  def longest_session
@@ -442,26 +412,26 @@ module Devlog
442
412
  end
443
413
 
444
414
  def last_session
445
- @zezzions.first #devlog_begin
415
+ @zezzions.first # devlog_begin
446
416
  end
447
417
 
448
418
  def first_session
449
- @zezzions.last #devlog_end
419
+ @zezzions.last # devlog_end
450
420
  end
451
421
 
452
- #return all sessions
422
+ # return all sessions
453
423
  def devlog_sessions
454
424
  @zezzions
455
425
  end
456
426
 
457
427
  def validation_string
458
- vs = ""
428
+ vs = ''
459
429
  vs << (@zezzions.any? ? '' : "No sessions recorded, add some first...\n".red)
460
- vs << (File.exist?(self.devlog_file) ? '' : "No such file #{self.devlog_file}...\n".red)
430
+ vs << (File.exist?(devlog_file) ? '' : "No such file #{devlog_file}...\n".red)
461
431
  end
462
432
 
463
433
  def to_info_string(short=false)
464
- s = ""
434
+ s = ''
465
435
  s << "\nSession::Time: = #{self.session_time} [h]\n"
466
436
  s << ("\nCodingSession::Time = %.1f [h]\n" % self.coding_session_time)
467
437
  s << ("\nComSession::Time = %.1f [h]\n" % self.com_session_time)
@@ -498,11 +468,12 @@ module Devlog
498
468
  end
499
469
 
500
470
  private
471
+
501
472
  def sessions_to_s(sessions)
502
473
  "\n" + sessions.collect{|session| " " + session.to_s}.join("\n")
503
474
  end
504
475
 
505
- #count :weeks=>1, or :days=>1, or :years=>1
476
+ # count :weeks=>1, or :days=>1, or :years=>1
506
477
  def count_time(options)
507
478
  num = 0
508
479
  cur = self.devlog_begin
@@ -510,20 +481,18 @@ module Devlog
510
481
  num += 1
511
482
  cur = cur.advance(options)
512
483
  end
513
- return num
484
+ num
514
485
  end
515
-
516
486
  end
517
487
 
518
-
519
488
  class Zezzion
520
- COM = 1 #communication session
521
- COD = 0 #coding session
489
+ COM = 1 # communication session
490
+ COD = 0 # coding session
522
491
  attr_accessor :zzbegin, :zzend, :zzbegin_title, :zzend_title, :zztype
523
492
  attr_accessor :coding_session_time, :com_session_time, :payed_time
524
493
  attr_accessor :zzend_line_number, :zzbegin_line_number
525
494
 
526
- def initialize(zztype=COD)
495
+ def initialize(zztype = COD)
527
496
  @zztype = zztype
528
497
  @zzbegin = nil
529
498
  @zzend = nil
@@ -537,33 +506,33 @@ module Devlog
537
506
  @zzend_line_number = 0
538
507
  end
539
508
 
540
- #in seconds
509
+ # in seconds
541
510
  def time
542
511
  @zzend.to_time - @zzbegin.to_time
543
512
  end
544
513
 
545
- #zezzion_time in days
514
+ # zezzion_time in days
546
515
  def days
547
516
  min = self.time / 60
548
517
  hours = min / 60
549
518
  days = hours / 24
550
519
  end
551
520
 
552
- #the whole coding session time
521
+ # the whole coding session time
553
522
  def session_time
554
523
  @coding_session_time + @com_session_time #in seconds
555
524
  end
556
525
 
557
- #hours per day
526
+ # hours per day
558
527
  def per_day
559
- #whole time over number of days the parsing covers
528
+ # whole time over number of days the parsing covers
560
529
  session_time/days
561
530
  end
562
531
  def per_week
563
- #todo
532
+ # todo
564
533
  end
565
534
  def per_month
566
- #todo
535
+ # todo
567
536
  end
568
537
 
569
538
  def type
@@ -583,9 +552,7 @@ module Devlog
583
552
  @com_session_time = 0.0
584
553
  @payed_time = 0.0
585
554
  end
586
-
587
555
  end
588
-
589
556
  end
590
557
 
591
558
  module DateTimeAgoInWords
@@ -616,6 +583,7 @@ module DateTimeAgoInWords
616
583
  pair.compact
617
584
  end
618
585
  end
586
+
619
587
  class DateTime
620
588
  include DateTimeAgoInWords
621
- end
589
+ end
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ # require 'pry'
4
+
5
+ #
6
+ module Devlog
7
+ # Settings - keeping it simple.
8
+ # Allow settings.key besides settings[:key]
9
+ # If the method name exists as a key within this Hash, fetch it.
10
+ class Settings < Hash
11
+ def method_missing(m, *args, &block)
12
+ if key?(m)
13
+ fetch m
14
+ elsif key?(m.to_s)
15
+ fetch m.to_s
16
+ else
17
+ super
18
+ end
19
+ end
20
+ end
21
+
22
+ def load_settings(file)
23
+ yaml = YAML.load_file(file)
24
+ @settings = yaml ? Settings[yaml] : Settings.new
25
+ end
26
+
27
+ def settings
28
+ @settings
29
+ end
30
+
31
+ # The default is the current folder with devlog.markdown in it.
32
+ DEVLOG_FILE = 'devlog.markdown'.freeze
33
+
34
+ # Calculate a devlog_file path.
35
+ def devlog_file_setting
36
+ return DEVLOG_FILE unless @settings
37
+ devlog_file_setting = @settings['devlog_file']
38
+ if devlog_file_setting && File.exists?(File.join(Dir.pwd, devlog_file_setting))
39
+ devlog_file_setting
40
+ else
41
+ DEVLOG_FILE
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ # Test the devlog_file_setting override
4
+ class DevlogFileTest < Test::Unit::TestCase
5
+ def setup
6
+ load_settings(File.join(File.dirname(__FILE__),
7
+ TEST_FILES_PATH, '.devlog.yml'))
8
+ end
9
+
10
+ def test_devlog_file_returns_the_overriden_devlog_file
11
+ x = "overridden setting should be returned, but was #{devlog_file_setting}"
12
+ assert(devlog_file_setting == 'test/test_devlogs/test_devlog.markdown', x)
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ # Test the settings
4
+ class DevlogSettingsTest < Test::Unit::TestCase
5
+ def setup
6
+ load_settings(File.join(File.dirname(__FILE__),
7
+ TEST_FILES_PATH, 'test_settings.yml'))
8
+ end
9
+
10
+ def test_settings
11
+ assert(settings.is_a?(Settings) == true, 'settings is a Hash')
12
+ end
13
+
14
+ def test_adding_setting
15
+ settings[:new_setting] = 'added'
16
+ assert(settings.new_setting == 'added', 'new_setting should be defined')
17
+ end
18
+
19
+ def test_changing_setting_on_the_fly
20
+ settings[:new_setting] = 'added'
21
+ assert(settings.new_setting == 'added', 'new_setting should be defined')
22
+ settings[:new_setting] = 'mod'
23
+ assert(settings.new_setting == 'mod', 'new_setting should be modified')
24
+ end
25
+
26
+ def test_loading_from_yaml
27
+ assert(settings.devlog_file == 'development_log.markdown',
28
+ 'example setting should be loaded')
29
+ end
30
+
31
+ def test_devlog_file_setting_returns_default_when_overriden_devlog_file_does_not_exist
32
+ assert(devlog_file_setting == 'devlog.markdown',
33
+ 'default setting should be returned, since the example setting does not exist')
34
+ end
35
+
36
+ def test_nested_settings_are_possible_but_not_encouraged
37
+ assert_raise(NoMethodError) { settings.nested.setting == 'xyz' }
38
+ assert(settings.nested['setting'] == 'xyz', 'xyz should be defined')
39
+ end
40
+ end
data/test/devlog_test.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class DevlogTest < Test::Unit::TestCase
4
-
5
4
  def test_empty_devlog
6
- @tajm = parse_devlog(File.join(File.dirname(__FILE__), '..', 'empty_devlog.markdown'))
5
+ @tajm = parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'empty_devlog.markdown'))
7
6
  puts "#{@tajm.coding_session_time} #{@tajm.com_session_time} #{@tajm.payed_time}"
8
7
  assert(@tajm.coding_session_time==0, "time is money is love")
9
8
  assert(@tajm.com_session_time==0, "selftalk")
@@ -35,6 +34,12 @@ class DevlogTest < Test::Unit::TestCase
35
34
  assert(@tajm_test.charge_time==5.5, "wrong charge wrong")
36
35
  end
37
36
 
37
+ def test_devlog_invalid_date
38
+ assert_raise(SystemExit) do
39
+ parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_invalid_date_devlog.markdown'))
40
+ end
41
+ end
42
+
38
43
  def test_p_session_time
39
44
  p = Parsing.new
40
45
  zezzion = Zezzion.new
@@ -111,7 +116,6 @@ class DevlogTest < Test::Unit::TestCase
111
116
  load_devlog_stat
112
117
  hours = @tajm_stat.hours_for_last(1, parse_datetime("#09.03.2014 11:00:00"))
113
118
  assert(hours==1, "should be 1, but is #{hours}")
114
-
115
119
  end
116
120
 
117
121
  def test_session_count
@@ -136,7 +140,7 @@ class DevlogTest < Test::Unit::TestCase
136
140
  end
137
141
 
138
142
  def test_start_coding_session
139
- @empty_devlog = File.join(File.dirname(__FILE__), '..', 'tmp1_devlog.markdown')
143
+ @empty_devlog = File.join(File.dirname(__FILE__), TEMP_PATH, 'tmp1_devlog.markdown')
140
144
  File.open(@empty_devlog, 'w') {|f| f.puts('empty')}
141
145
  start_coding_session(@empty_devlog)
142
146
  assert(File.readlines(@empty_devlog).grep(/CodingSession::BEGIN/).size>0, "should insert CodingSession::BEGIN at top of file")
@@ -145,7 +149,7 @@ class DevlogTest < Test::Unit::TestCase
145
149
  end
146
150
 
147
151
  def test_stop_coding_session
148
- @empty_devlog = File.join(File.dirname(__FILE__), '..', 'tmp2_devlog.markdown')
152
+ @empty_devlog = File.join(File.dirname(__FILE__), TEMP_PATH, 'tmp2_devlog.markdown')
149
153
  File.delete(@empty_devlog) if File.exist?(@empty_devlog)
150
154
  File.open(@empty_devlog, 'w') {|f| f.puts('empty')}
151
155
  stop_coding_session(@empty_devlog)
@@ -155,14 +159,14 @@ class DevlogTest < Test::Unit::TestCase
155
159
  end
156
160
 
157
161
  def test_save_info_after_stop_coding_session
158
- @devlog_info = File.join(File.dirname(__FILE__), '..', 'info.markdown')
159
- @empty_devlog = File.join(File.dirname(__FILE__), '..', 'tmp3_devlog.markdown')
162
+ @devlog_info = File.join(File.dirname(__FILE__), TEMP_PATH, 'info.markdown')
163
+ @empty_devlog = File.join(File.dirname(__FILE__), TEMP_PATH, 'tmp3_devlog.markdown')
160
164
  #File.delete(@empty_devlog) if File.exist?(@empty_devlog)
161
165
  File.new(@empty_devlog, 'w').puts('\n')
162
166
  start_coding_session(@empty_devlog)
163
167
  assert(File.readlines(@empty_devlog).grep(/CodingSession::BEGIN/).size>0, "should insert CodingSession::BEGIN at top of file")
164
168
  assert(is_session_open(@empty_devlog)==true, "should be true, session should be open after starting")
165
- prepend_string('+1h', @empty_devlog)
169
+ prepend_string(@empty_devlog, '+1h')
166
170
  sleep(1)
167
171
  stop_coding_session(@empty_devlog)
168
172
  assert(File.readlines(@empty_devlog).grep(/CodingSession::END/).size>0, "should insert CodingSession::END at top of file")
@@ -177,14 +181,14 @@ class DevlogTest < Test::Unit::TestCase
177
181
  end
178
182
 
179
183
  def test_is_session_open
180
- @closed_devlog = File.join(File.dirname(__FILE__), '..', 'test_devlog.markdown')
184
+ @closed_devlog = File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_devlog.markdown')
181
185
  assert(is_session_open(@closed_devlog)==false, "should be false, session should be closed")
182
- @open_devlog = File.join(File.dirname(__FILE__), '..', 'test_open_devlog.markdown')
186
+ @open_devlog = File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_open_devlog.markdown')
183
187
  assert(is_session_open(@open_devlog)==true, "should be true, session should be open")
184
188
  end
185
189
 
186
190
  def test_devlog_export
187
- @exported_devlog = export_devlog_now(File.join(File.dirname(__FILE__), '..', 'test_devlog_export.markdown'))
191
+ @exported_devlog = export_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_devlog_export.markdown'))
188
192
  assert(File.exists?(@exported_devlog))
189
193
  assert(File.size(@exported_devlog)>0, "file should not be empty")
190
194
  File.open(@exported_devlog, "r") do |f|
@@ -200,4 +204,7 @@ class DevlogTest < Test::Unit::TestCase
200
204
  File.delete(@exported_devlog) if File.exist?(@exported_devlog)
201
205
  end
202
206
 
207
+ def test_default_devlog_file_setting
208
+ assert(devlog_file_setting == 'devlog.markdown', 'should return default')
209
+ end
203
210
  end
@@ -0,0 +1 @@
1
+ devlog_file: "test/test_devlogs/test_devlog.markdown"
@@ -0,0 +1,11 @@
1
+ #01.06.2017 18:20:50 CodingSession::END
2
+
3
+ let's see how it goes today.
4
+
5
+ #01.06.2017 09:38:35 CodingSession::BEGIN
6
+
7
+ #31.06.2017 18:20:50 CodingSession::END
8
+
9
+ nevermind, just do it...
10
+
11
+ #31.05.2017 09:38:35 CodingSession::BEGIN
@@ -0,0 +1,5 @@
1
+ # Override the default location of the_project_folder_path/../info/devlog.markdown
2
+ devlog_file: development_log.markdown
3
+
4
+ nested:
5
+ setting: xyz
data/test/test_helper.rb CHANGED
@@ -9,38 +9,41 @@ class Test::Unit::TestCase
9
9
  include Devlog
10
10
  end
11
11
 
12
+ TEST_FILES_PATH = 'test_devlogs'.freeze
13
+ TEMP_PATH = '../tmp'.freeze
14
+
12
15
  def load_devlog
13
- @tajm = parse_devlog(File.join(File.dirname(__FILE__), '..', 'devlog.markdown'))
16
+ @tajm = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'devlog.markdown'))
14
17
  puts "#{@tajm.coding_session_time} #{@tajm.com_session_time} #{@tajm.payed_time}"
15
- assert(@tajm.coding_session_time>0, "no time no money no love")
16
- assert(@tajm.com_session_time>0, "no selftalk")
17
- assert(@tajm.payed_time<0, "no selfpay")
18
+ assert(@tajm.coding_session_time>0, "truth love simplicity")
19
+ assert(@tajm.com_session_time>0, "selftalk")
20
+ assert(@tajm.payed_time<0, "selfpay")
18
21
  end
19
22
 
20
23
  def load_devlog_now
21
24
  @tajm_now = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'devlog.markdown'))
22
25
  puts "#{@tajm_now.coding_session_time} #{@tajm_now.com_session_time} #{@tajm_now.payed_time}"
23
- assert(@tajm_now.coding_session_time>0, "no time no money no love")
24
- assert(@tajm_now.com_session_time>0, "no selftalk")
25
- assert(@tajm_now.payed_time<0, "no selfpay")
26
+ assert(@tajm_now.coding_session_time>0, "truth love simplicity")
27
+ assert(@tajm_now.com_session_time>0, "selftalk")
28
+ assert(@tajm_now.payed_time<0, "selfpay")
26
29
  end
27
30
 
28
31
  def load_devlog_test
29
- @tajm_test = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'test_devlog.markdown'))
32
+ @tajm_test = parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_devlog.markdown'))
30
33
  puts "#{@tajm_test.coding_session_time} #{@tajm_test.com_session_time} #{@tajm_test.payed_time}"
31
- assert(@tajm_test.coding_session_time>0, "no time no money no love")
32
- assert(@tajm_test.com_session_time>0, "no selftalk")
33
- assert(@tajm_test.payed_time<0, "no selfpay")
34
+ assert(@tajm_test.coding_session_time>0, "truth love simplicity")
35
+ assert(@tajm_test.com_session_time>0, "selftalk")
36
+ assert(@tajm_test.payed_time<0, "selfpay")
34
37
  end
35
38
 
36
39
  def load_devlog_stat
37
- @tajm_stat = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'test_stats_devlog.markdown'))
40
+ @tajm_stat = parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_stats_devlog.markdown'))
38
41
  end
39
42
 
40
43
  def load_devlog_single
41
- @tajm_single = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'test_single_devlog.markdown'))
44
+ @tajm_single = parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_single_devlog.markdown'))
42
45
  end
43
46
 
44
47
  def load_devlog_negative
45
- @tajm_negative = parse_devlog_now(File.join(File.dirname(__FILE__), '..', 'test_negative_devlog.markdown'))
48
+ @tajm_negative = parse_devlog_now(File.join(File.dirname(__FILE__), TEST_FILES_PATH, 'test_negative_devlog.markdown'))
46
49
  end
data/tmp/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # Ignore everything in this directory
2
+ *
3
+ # Except this file
4
+ !.gitignore
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mihael
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jeweler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -73,9 +73,8 @@ files:
73
73
  - bin/devlog
74
74
  - devlog.gemspec
75
75
  - devlog.markdown
76
- - empty_devlog.markdown
77
76
  - lib/devlog.rb
78
- - sublime_text/.DS_Store
77
+ - lib/devlog_settings.rb
79
78
  - sublime_text/devlog.tmbundle/Snippets/begin.tmSnippet
80
79
  - sublime_text/devlog.tmbundle/Snippets/combegin.tmSnippet
81
80
  - sublime_text/devlog.tmbundle/Snippets/comend.tmSnippet
@@ -86,14 +85,21 @@ files:
86
85
  - sublime_text/devlog.tmbundle/Snippets/tu.tmSnippet
87
86
  - sublime_text/devlog.tmbundle/info.plist
88
87
  - sublime_text/tu.py
88
+ - test/devlog_file_test.rb
89
+ - test/devlog_settings_test.rb
89
90
  - test/devlog_test.rb
91
+ - test/test_devlogs/.devlog.yml
92
+ - test/test_devlogs/empty_devlog.markdown
93
+ - test/test_devlogs/test_devlog.markdown
94
+ - test/test_devlogs/test_devlog_export.markdown
95
+ - test/test_devlogs/test_invalid_date_devlog.markdown
96
+ - test/test_devlogs/test_negative_devlog.markdown
97
+ - test/test_devlogs/test_open_devlog.markdown
98
+ - test/test_devlogs/test_settings.yml
99
+ - test/test_devlogs/test_single_devlog.markdown
100
+ - test/test_devlogs/test_stats_devlog.markdown
90
101
  - test/test_helper.rb
91
- - test_devlog.markdown
92
- - test_devlog_export.markdown
93
- - test_negative_devlog.markdown
94
- - test_open_devlog.markdown
95
- - test_single_devlog.markdown
96
- - test_stats_devlog.markdown
102
+ - tmp/.gitignore
97
103
  homepage: http://github.com/mihael/devlog
98
104
  licenses:
99
105
  - MIT
@@ -114,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
120
  version: '0'
115
121
  requirements: []
116
122
  rubyforge_project:
117
- rubygems_version: 2.5.1
123
+ rubygems_version: 2.5.2
118
124
  signing_key:
119
125
  specification_version: 4
120
126
  summary: takes devlog.markdown and gives info
Binary file