timeclock 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -0,0 +1,6 @@
1
+ TODO:
2
+
3
+ - Style the email
4
+ - Allow smtp information to be set.. probably save to a deet's to a file like we are doing with ~/.timeclock
5
+ - Move the .timeclock file and email file to a folder ~/.timeclock/
6
+ - layer in an automation system.
data/bin/clock CHANGED
@@ -1,121 +1,12 @@
1
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
2
+ require 'timeclock'
112
3
 
113
4
  def help
114
5
  puts "Usage:"
115
6
  puts ""
116
7
  puts "clock in"
117
8
  puts "clock out"
118
- puts "clock send"
9
+ puts "clock submit"
119
10
  puts "clock clear"
120
11
  end
121
12
 
@@ -123,20 +14,24 @@ if ARGV.first == nil
123
14
  puts "Error: incorrect syntax"
124
15
  puts "try clock --help"
125
16
  else
126
- check_file
17
+ Timeclock::Clock.check_file
18
+ Timeclock::Clock.check_email
127
19
  case ARGV.first
128
20
  when "in"
129
- clock_in
21
+ Timeclock::Clock.clock_in
130
22
  when "out"
131
- clock_out
23
+ Timeclock::Clock.clock_out
132
24
  when "submit"
133
- send
25
+ Timeclock::Clock.send
134
26
  when "send"
135
- send
27
+ Timeclock::Clock.send
136
28
  when "clear"
137
- clear
138
- when "--help"
139
- help
29
+ Timeclock::Clock.clear
30
+ when "total"
31
+ puts Timeclock::Clock.total
32
+ when "daily"
33
+ require 'pp'
34
+ pp Timeclock::Clock.daily_log
140
35
  else
141
36
  help
142
37
  end
@@ -0,0 +1,18 @@
1
+ # Use this file to easily define all of your cron jobs.
2
+ #
3
+ # It's helpful, but not entirely necessary to understand cron before proceeding.
4
+ # http://en.wikipedia.org/wiki/Cron
5
+
6
+ # Example:
7
+ #
8
+ # set :output, "~/.timeclock.log"
9
+
10
+ # every 1.minute do
11
+ # command "clock automate"
12
+ # end
13
+
14
+ # every 4.days do
15
+ # runner "AnotherModel.prune_old_records"
16
+ # end
17
+
18
+ # Learn more: http://github.com/javan/whenever
@@ -0,0 +1,176 @@
1
+ require 'time'
2
+
3
+ module Timeclock
4
+ class Clock
5
+ class << self
6
+ def home_directory
7
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
8
+ end
9
+
10
+ def put_log_string(contents)
11
+ File.open(log_file, "w").write(contents)
12
+ end
13
+
14
+
15
+ def get_log_string
16
+ File.open(log_file, 'r') { |f| f.read }
17
+ end
18
+
19
+ def put_email_string(contents)
20
+ File.open(email_file, "w").write(contents)
21
+ end
22
+
23
+ def get_email_string
24
+ File.open(email_file, 'r') { |f| f.read }
25
+ end
26
+
27
+ def email_file
28
+ "#{home_directory}/.email"
29
+ end
30
+
31
+
32
+ def log_file
33
+ "#{home_directory}/.timeclock"
34
+ end
35
+
36
+ def running_on_windows?
37
+ RUBY_PLATFORM =~ /mswin32|mingw32/
38
+ end
39
+
40
+ def clock_in
41
+ string = get_log_string
42
+ array = string.split("\n")
43
+ if !array.empty?
44
+ if array.last.include? "in"
45
+ puts "You are already clocked in"
46
+ exit(1)
47
+ end
48
+ end
49
+ print "what are you working on: "
50
+ job = STDIN.gets.strip
51
+ array << "in #{job} #{Time.now}"
52
+ put_log_string array.join("\n")
53
+ puts "clocking in at #{Time.now}"
54
+ end
55
+
56
+ def clock_out
57
+ string = get_log_string
58
+ array = string.split("\n")
59
+ if array.last.include? "out"
60
+ puts "You are already clocked out"
61
+ exit(1)
62
+ end
63
+ array << "out #{Time.now}"
64
+ put_log_string array.join("\n")
65
+ puts "clocking out at #{Time.now.to_s}"
66
+ end
67
+
68
+ def total
69
+ total = 0.0
70
+ collect.each {|value|total += value[:hours]}
71
+ total
72
+ end
73
+
74
+ def daily_log
75
+ collection = collect
76
+ new_hash = {}
77
+ time_array = []
78
+ collection.each do |element|
79
+ day = Time.parse(element[:clock_in]).day
80
+ if new_hash[day]
81
+ new_hash[day][:total] += element[:hours]
82
+ new_hash[day][:log] << {:in => element[:clock_in], :out => element[:clock_out]}
83
+ else
84
+ new_hash[day] = {}
85
+ new_hash[day][:total] = element[:hours]
86
+ new_hash[day][:log] = [{:in => element[:clock_in], :out => element[:clock_out]}]
87
+ end
88
+ end
89
+ new_hash[:total] = total
90
+ new_hash
91
+ end
92
+
93
+ def collect
94
+ string = get_log_string
95
+ array = string.split("\n")
96
+ rtn = []
97
+ if array.size.even?
98
+ until array.empty?
99
+ clock_in = array.shift
100
+ clock_out = array.shift
101
+ in_array = clock_in.split(" ")
102
+ out_array = clock_out.split(" ")
103
+ in_time = Time.parse("#{in_array[2]} #{in_array[3]} #{in_array[4]}")
104
+ out_time = Time.parse("#{out_array[1]} #{out_array[2]} #{out_array[3]}")
105
+ hash = {}
106
+ hash[:hours] = (out_time - in_time) / 3600 #convert to hours
107
+ hash[:clock_in] = in_time.ctime
108
+ hash[:clock_out] = out_time.ctime
109
+ hash[:project] = in_array[1]
110
+ rtn << hash
111
+ end
112
+ else
113
+ puts "You do not have an even number of clock in's and out's"
114
+ exit(1)
115
+ end
116
+ rtn
117
+ end
118
+
119
+ def send
120
+ puts collect
121
+ print "who should I send this to: "
122
+ to = STDIN.gets.strip
123
+ begin
124
+ require 'pony'
125
+ require 'erb'
126
+
127
+ Pony.mail(
128
+ :to => to,
129
+ :from => "Lyon <lyon@delorum.com>",
130
+ :subject => "Time card",
131
+ :content_type => 'text/html',
132
+ :html_body => ERB.new(File.new("templates/email.html.erb").read).result(binding),
133
+ :body => "You are reading this because your email client sux and cant interperate html... fix it." #,
134
+ # :via => :smtp, :via_options => {
135
+ # :address => 'smtp.gmail.com',
136
+ # :port => '587',
137
+ # :enable_starttls_auto => true,
138
+ # :user_name => 'user',
139
+ # :password => 'password',
140
+ # :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
141
+ # :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
142
+ # }
143
+ )
144
+ puts "Time card has been sent to #{to}."
145
+ rescue Exception => e
146
+ puts "Time card not sent because pony is dumb."
147
+ end
148
+
149
+ end
150
+
151
+ def email
152
+ string = get_email_string
153
+ array = string.split("\n")
154
+ end
155
+
156
+ def check_email
157
+ `touch #{email_file}` unless File.exist? email_file
158
+ end
159
+
160
+ def check_file
161
+ `touch #{log_file}` unless File.exist? log_file
162
+ end
163
+
164
+ def clear
165
+ print "Are you sure you want delete your existing log? (yes/no): "
166
+ if STDIN.gets.strip == 'yes'
167
+ `rm #{log_file}`
168
+ check_file
169
+ end
170
+ end
171
+
172
+
173
+ end
174
+ end
175
+ end
176
+
@@ -1,3 +1,3 @@
1
1
  module Timeclock
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/timeclock.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "timeclock/version"
2
+ require "timeclock/clock"
2
3
 
3
4
  module Timeclock
4
5
  # Your code goes here...
@@ -0,0 +1,4 @@
1
+ Hay dude. this will be my email someday
2
+ <%= collect.to_s %>
3
+ <%= total %>
4
+ <%= daily_log %>
data/timeclock.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Lyon"]
9
9
  s.email = ["lyon@delorum.com"]
10
10
  s.homepage = ""
11
- s.summary = %q{Time clock because I dont like filling out those cards}
12
- s.description = %q{DUH}
11
+ s.summary = %q{Timeclock is a small but useful timeclock system that allows users to push clock in and clock out. additionally you can see your daily time totals and you can also send your clock invoice to an email}
12
+ s.description = %q{A simple console based clock in/clock out system.}
13
13
 
14
14
  s.rubyforge_project = "timeclock"
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeclock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-20 00:00:00.000000000 -06:00
12
+ date: 2011-06-24 00:00:00.000000000 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
- description: DUH
15
+ description: A simple console based clock in/clock out system.
16
16
  email:
17
17
  - lyon@delorum.com
18
18
  executables:
@@ -25,8 +25,11 @@ files:
25
25
  - README
26
26
  - Rakefile
27
27
  - bin/clock
28
+ - config/schedule.rb
28
29
  - lib/timeclock.rb
30
+ - lib/timeclock/clock.rb
29
31
  - lib/timeclock/version.rb
32
+ - templates/email.html.erb
30
33
  - timeclock.gemspec
31
34
  has_rdoc: true
32
35
  homepage: ''
@@ -52,5 +55,7 @@ rubyforge_project: timeclock
52
55
  rubygems_version: 1.5.3
53
56
  signing_key:
54
57
  specification_version: 3
55
- summary: Time clock because I dont like filling out those cards
58
+ summary: Timeclock is a small but useful timeclock system that allows users to push
59
+ clock in and clock out. additionally you can see your daily time totals and you
60
+ can also send your clock invoice to an email
56
61
  test_files: []