work_log 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ nbproject/
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in work_log.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,82 @@
1
+ = work_log
2
+
3
+ == Description
4
+
5
+ A simple time tracker that logs your work times to a file using a command line interface.
6
+
7
+ == Installation
8
+
9
+ sudo gem install work_log
10
+
11
+ The +work_log+ command should now be available in your command line interface.
12
+
13
+ == Usage
14
+
15
+ Currently +work_log+ supports the following arguments:
16
+
17
+ work_log start # Log that you started working.
18
+ # You can pass a starting time in human readable words, e.g.
19
+ # work_log start two hours ago
20
+ # Default time is DateTime.now
21
+ # Shorthand: work_log s
22
+
23
+ work_log end # Log that you finished working.
24
+ # You can also pass a time (see start)
25
+ # Shorthand: work_log e
26
+
27
+ work_log all # List all entries
28
+ # Shorthand: work_log a
29
+
30
+ work_log week # List the entries of the current week
31
+ # Shorthand: work_log w
32
+
33
+ work_log last # Show the last logged entry
34
+
35
+ work_log since # Show all entries since a given time, examples:
36
+ # work_log since yesterday
37
+ # work_log since 2 weeks ago
38
+
39
+ work_log undo # Removes the last entry from the log
40
+
41
+ === Hint: Changing the location of the saved file
42
+
43
+ Especially interesting in combination with *Dropbox* to add backup/multiple device sync capabilities to work_log. ;)
44
+
45
+ Per default, the entries are saved in your home directory:
46
+
47
+ ~/work_log.yml
48
+
49
+ But you can change location of the saved file by creating a file called <tt>.work_log_gem</tt> in your home directory.
50
+
51
+ touch ~/.work_log_gem
52
+
53
+ And enter the following valid YAML (watch the indentation):
54
+
55
+ logfile: "/Users/yourUserName/some/other/path/work_log.yml"
56
+
57
+ Note that this must be the absolute path to the file.
58
+
59
+ == LICENSE:
60
+
61
+ (The MIT License)
62
+
63
+ Copyright (c) 2010 Christian Bäuerlein
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining
66
+ a copy of this software and associated documentation files (the
67
+ 'Software'), to deal in the Software without restriction, including
68
+ without limitation the rights to use, copy, modify, merge, publish,
69
+ distribute, sublicense, and/or sell copies of the Software, and to
70
+ permit persons to whom the Software is furnished to do so, subject to
71
+ the following conditions:
72
+
73
+ The above copyright notice and this permission notice shall be
74
+ included in all copies or substantial portions of the Software.
75
+
76
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
77
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
78
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
79
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
80
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
81
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
82
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/work_log ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'work_log'
5
+
6
+ WorkLog::Logger.new(ARGV)
data/config/config.yml ADDED
@@ -0,0 +1 @@
1
+ logfile: "/Users/fabrik42/Dropbox/flinc/work_log.yml"
@@ -0,0 +1,95 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ require 'date'
4
+ require 'chronic'
5
+
6
+ module WorkLog
7
+
8
+ class Logger
9
+
10
+ attr_accessor :logfile
11
+ attr_accessor :entries
12
+
13
+ HOME_PATH = ENV['HOME']
14
+ CONFIGURATION_FILE = HOME_PATH + "/.work_log_gem"
15
+ DEFAULT_LOGFILE = HOME_PATH + "/work_log.yml"
16
+
17
+ def initialize(args)
18
+ action = args.shift
19
+ load_config
20
+
21
+ begin
22
+ load
23
+ rescue
24
+ save
25
+ load
26
+ end
27
+
28
+ time = args.empty? ? DateTime.now : DateTime.parse((Chronic.parse(args.join(' ')) || DateTime.now).to_s)
29
+
30
+ puts '', ''
31
+
32
+ if action == 'start' || action == 's'
33
+ add "Work started", time
34
+ print entries.last
35
+ elsif action == 'end' || action == 'e'
36
+ add "Work ended", time
37
+ print entries.last
38
+ elsif action == 'all' || action == 'a'
39
+ entries.each {|e| print e }
40
+ elsif action == 'week' || action == 'w'
41
+ puts "Entries for this week:"
42
+ entries.select{|entry| entry['time'].cwyear == Date.today.cwyear && entry['time'].cweek == Date.today.cweek }.each {|e| print e }
43
+ elsif action == 'since'
44
+ puts "Entries since #{args.join(' ')}"
45
+ entries.select{|entry| entry['time'] > time }.each {|e| print e }
46
+ elsif action == 'last'
47
+ print entries.last
48
+ elsif action == 'undo'
49
+ removed_entry = entries.pop
50
+ save
51
+ puts "Removed the following entry:"
52
+ print removed_entry
53
+ else
54
+ puts "Unknown arguments."
55
+ end
56
+
57
+ puts '', ''
58
+
59
+ end
60
+
61
+ def load_config
62
+ return @logfile = DEFAULT_LOGFILE unless File.exist?(CONFIGURATION_FILE)
63
+
64
+ config = YAML::load_file(CONFIGURATION_FILE)
65
+ @logfile = config['logfile'] ? config['logfile'] : DEFAULT_LOGFILE
66
+ end
67
+
68
+ def print(entry)
69
+ puts "#{entry['time'].strftime("%a, %b %d %Y at %H:%M")} -> #{entry['message']}"
70
+ end
71
+
72
+ def add(message, time = DateTime.now)
73
+ @entries << {
74
+ 'time' => time,
75
+ 'message' => message
76
+ }
77
+ save
78
+ end
79
+
80
+ def load
81
+ file_content = YAML.load_file(logfile)
82
+ @entries = file_content && file_content['entries'] ? file_content['entries']: []
83
+ @entries.each {|entry| entry['time'] = DateTime.parse entry['time'].to_s }
84
+ @entries
85
+ end
86
+
87
+ def save
88
+ File.open(logfile, 'w') do |file|
89
+ file.write YAML.dump({'entries' => entries})
90
+ end
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,3 @@
1
+ module WorkLog
2
+ VERSION = "0.0.2"
3
+ end
data/lib/work_log.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'work_log/version'
2
+ require 'work_log/logger'
3
+
4
+ module WorkLog
5
+
6
+ end
data/work_log.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "work_log/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "work_log"
7
+ s.version = WorkLog::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Christian Bäuerlein"]
10
+ s.email = ["fabrik42@gmail.com"]
11
+ s.homepage = "https://github.com/fabrik42/work_log"
12
+ s.summary = %q{A simple time tracker}
13
+ s.description = %q{Log your work times to a file using a simple command line interface}
14
+
15
+ s.add_dependency('chronic','>= 0.3.0')
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_log
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - "Christian B\xC3\xA4uerlein"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-29 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: chronic
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 3
33
+ - 0
34
+ version: 0.3.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Log your work times to a file using a simple command line interface
38
+ email:
39
+ - fabrik42@gmail.com
40
+ executables:
41
+ - work_log
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - README.rdoc
50
+ - Rakefile
51
+ - bin/work_log
52
+ - config/config.yml
53
+ - lib/work_log.rb
54
+ - lib/work_log/logger.rb
55
+ - lib/work_log/version.rb
56
+ - work_log.gemspec
57
+ has_rdoc: true
58
+ homepage: https://github.com/fabrik42/work_log
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A simple time tracker
91
+ test_files: []
92
+