timeclock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in timeclock.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/clock ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'time'
5
+
6
+ def home_directory
7
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
8
+ end
9
+
10
+ def put_log_string(contents)
11
+ file = File.open(log_file, "w")
12
+ file.write(contents)
13
+ end
14
+
15
+ def get_log_string
16
+ contents = File.open(log_file, 'r') { |f| f.read }
17
+ contents
18
+ end
19
+
20
+ def log_file
21
+ "#{home_directory}/.timeclock"
22
+ end
23
+
24
+ def running_on_windows?
25
+ RUBY_PLATFORM =~ /mswin32|mingw32/
26
+ end
27
+
28
+ def clock_in
29
+ string = get_log_string
30
+ array = string.split("\n")
31
+ if !array.empty?
32
+ if array.last.include? "in"
33
+ puts "You are already clocked in"
34
+ exit(1)
35
+ end
36
+ end
37
+ print "what are you working on: "
38
+ job = STDIN.gets.strip
39
+ array << "in #{job} #{Time.now}"
40
+ put_log_string array.join("\n")
41
+ puts "clocking in at #{Time.now}"
42
+ end
43
+
44
+ def clock_out
45
+ string = get_log_string
46
+ array = string.split("\n")
47
+ if array.last.include? "out"
48
+ puts "You are already clocked out"
49
+ exit(1)
50
+ end
51
+ array << "out #{Time.now}"
52
+ put_log_string array.join("\n")
53
+ puts "clocking out at #{Time.now.to_s}"
54
+ end
55
+
56
+ def collect
57
+ string = get_log_string
58
+ array = string.split("\n")
59
+ rtn = []
60
+ until array.empty?
61
+ clock_in = array.shift
62
+ clock_out = array.shift
63
+ if clock_in && clock_out
64
+ in_array = clock_in.split(" ")
65
+ out_array = clock_out.split(" ")
66
+ in_time = Time.parse("#{in_array[2]} #{in_array[3]} #{in_array[4]}")
67
+ out_time = Time.parse("#{out_array[2]} #{out_array[3]} #{out_array[4]}")
68
+ hash = {}
69
+ hash[:hours] = (out_time - in_time) / 3600 #convert to hours
70
+ hash[:clock_in] = in_time.to_s
71
+ hash[:clock_out] = out_time.to_s
72
+ hash[:project] = in_array[1]
73
+ rtn << hash
74
+ else
75
+ puts "You do not have an even number of clock in's and out's"
76
+ end
77
+ end
78
+ rtn
79
+ end
80
+
81
+ def send
82
+ puts collect
83
+ print "who should I send this to: "
84
+ to = STDIN.gets.strip
85
+ begin
86
+ require 'pony'
87
+ require 'erb'
88
+
89
+ Pony.mail(
90
+ :to => to,
91
+ :from => "Lyon <lyon@delorum.com>",
92
+ :subject => "Time card",
93
+ :content_type => 'text/html',
94
+ :html_body => ERB.new(File.new("template.html.erb").read).result(),
95
+ :body => "Make it read html so you can see the awesomeness that is my timecard"
96
+ )
97
+ puts "Time card has been sent to #{to}."
98
+ rescue Exception => e
99
+ puts "Time card not sent because pony is dumb."
100
+ end
101
+
102
+ end
103
+
104
+ def check_file
105
+ `touch #{log_file}` unless File.exist? log_file
106
+ end
107
+
108
+ def clear
109
+ `rm #{log_file}`
110
+ check_file
111
+ end
112
+
113
+ def help
114
+ puts "Usage:"
115
+ puts ""
116
+ puts "clock in"
117
+ puts "clock out"
118
+ puts "clock send"
119
+ puts "clock clear"
120
+ end
121
+
122
+ if ARGV.first == nil
123
+ puts "Error: incorrect syntax"
124
+ puts "try clock --help"
125
+ else
126
+ check_file
127
+ case ARGV.first
128
+ when "in"
129
+ clock_in
130
+ when "out"
131
+ clock_out
132
+ when "submit"
133
+ send
134
+ when "send"
135
+ send
136
+ when "clear"
137
+ clear
138
+ when "--help"
139
+ help
140
+ else
141
+ help
142
+ end
143
+
144
+ end
145
+
@@ -0,0 +1,3 @@
1
+ module Timeclock
2
+ VERSION = "0.0.1"
3
+ end
data/lib/timeclock.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "timeclock/version"
2
+
3
+ module Timeclock
4
+ # Your code goes here...
5
+ end
data/timeclock.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "timeclock/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "timeclock"
7
+ s.version = Timeclock::VERSION
8
+ s.authors = ["Lyon"]
9
+ s.email = ["lyon@delorum.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Time clock because I dont like filling out those cards}
12
+ s.description = %q{DUH}
13
+
14
+ s.rubyforge_project = "timeclock"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timeclock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lyon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-20 00:00:00.000000000 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: DUH
16
+ email:
17
+ - lyon@delorum.com
18
+ executables:
19
+ - clock
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - README
26
+ - Rakefile
27
+ - bin/clock
28
+ - lib/timeclock.rb
29
+ - lib/timeclock/version.rb
30
+ - timeclock.gemspec
31
+ has_rdoc: true
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: timeclock
52
+ rubygems_version: 1.5.3
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Time clock because I dont like filling out those cards
56
+ test_files: []