overtimer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/config.example.yml +3 -0
- data/lib/overtimer.rb +5 -0
- data/lib/overtimer/version.rb +3 -0
- data/lib/overtimer/workbase.rb +51 -0
- data/lib/overtimer/workweek.rb +43 -0
- data/overtimer.gemspec +26 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/workweek_helpers.rb +23 -0
- data/spec/workweek_spec.rb +61 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTY5MzUyYTE2NzJjYWM4MDljMWU3M2QxZjc3OGQ4MDFmZmViMzFhZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGVjZDBjOWVhODkzMTgzMzQwNWU4YWUxYmY0NTljYTJiNzA0MTY4Mg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTYxNTNlZWM5MmNmOWZmNmE3Y2M2YmM4MGY3YzFlODkyYTI0OGVhNGE4YzM5
|
10
|
+
NDIxZWNiZmM0N2Y1N2Y0NDdiODY5OWZmYmZmZWJmZWVhNjlkMDZiZjNhYzQx
|
11
|
+
OGQ5NWQ2NjhiNzYzMTdkMjRiOTk5YjFjZDQ1OGY5ZWEyZTA3NGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OWE0MzJlMGQzNDhkMzJiYzMwODE0ZGRlMTI5ODBjNzQ1MDdmNjA5ZmFlOGU4
|
14
|
+
M2Q4YTcxMGI1YTg5MTQ2MzA1YWZlOTdlYmQ4NTAwY2Y5ZTllZDkxZmNlNTRk
|
15
|
+
MWYyZTE3NDFjODFjZTNkNGVmOWQ4MjZkNjg5MzI2YTY2ZjY4Zjk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
harvester
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keyvan Fatehi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# overtimer
|
2
|
+
|
3
|
+
Calculates employee payroll info based on California laws (overtime, doubletime, etc)
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Assuming you've installed the gem with `gem install overtimer`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'rubygems'
|
11
|
+
require 'overtimer'
|
12
|
+
|
13
|
+
# Create a workweek using an array of hours per day for 1 week
|
14
|
+
ww = Overtimer::Workweek.new [17,12,15,11,12,4,0]
|
15
|
+
|
16
|
+
# Do the deductions meet your expectation (pull requests welcome)
|
17
|
+
ww.total == 71
|
18
|
+
ww.regular == 40,
|
19
|
+
ww.overtime == 23
|
20
|
+
ww.doubletime == 8
|
21
|
+
|
22
|
+
# What about only one of the days in the workweek?
|
23
|
+
wd = ww[0]
|
24
|
+
|
25
|
+
# How about these? Are they correct? They are for me anyway.
|
26
|
+
wd.total == 17
|
27
|
+
wd.regular == 8
|
28
|
+
wd.overtime == 4
|
29
|
+
wd.doubletime == 5
|
30
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config.example.yml
ADDED
data/lib/overtimer.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Overtimer
|
2
|
+
class Workbase
|
3
|
+
attr_reader :total, :regular, :overtime
|
4
|
+
attr_accessor :doubletime
|
5
|
+
def max_regular
|
6
|
+
self.class.max_regular
|
7
|
+
end
|
8
|
+
|
9
|
+
def max_overtime
|
10
|
+
if self.class.respond_to? :max_overtime
|
11
|
+
self.class.max_overtime
|
12
|
+
else
|
13
|
+
999
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize *args
|
18
|
+
@total = 0
|
19
|
+
@regular = 0
|
20
|
+
@overtime = 0
|
21
|
+
@doubletime = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def regular=(val)
|
25
|
+
@regular = val
|
26
|
+
if @regular >= max_regular
|
27
|
+
overflow = @regular - max_regular
|
28
|
+
self.overtime += overflow
|
29
|
+
@regular -= overflow
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def overtime=(val)
|
34
|
+
@overtime = val
|
35
|
+
if @overtime >= max_overtime
|
36
|
+
overflow = @overtime - max_overtime
|
37
|
+
self.doubletime += overflow
|
38
|
+
@overtime -= overflow
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def account_for_hours hours
|
43
|
+
if @regular <= max_regular
|
44
|
+
self.regular += hours
|
45
|
+
else
|
46
|
+
self.overtime += hours
|
47
|
+
end
|
48
|
+
@total += hours
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'overtimer/workbase'
|
2
|
+
|
3
|
+
module Overtimer
|
4
|
+
class Workday < Workbase
|
5
|
+
def self.max_regular
|
6
|
+
8
|
7
|
+
end
|
8
|
+
def self.max_overtime
|
9
|
+
4
|
10
|
+
end
|
11
|
+
def initialize hours
|
12
|
+
super
|
13
|
+
account_for_hours hours
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Workweek < Workbase
|
18
|
+
def self.max_regular
|
19
|
+
40
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize days
|
23
|
+
super
|
24
|
+
@days = days.map!{|i| Workday.new(i) }
|
25
|
+
|
26
|
+
if defined? ALEX_DOUBLE_TIME
|
27
|
+
if days.reject{|i| i.total == 0}.size == 7
|
28
|
+
@total += @doubletime += days.pop.total
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
days.each do |day|
|
33
|
+
account_for_hours day.total
|
34
|
+
self.doubletime += day.doubletime
|
35
|
+
self.overtime -= day.doubletime
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def [] index
|
40
|
+
@days[index]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/overtimer.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'overtimer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "overtimer"
|
8
|
+
spec.version = Overtimer::VERSION
|
9
|
+
spec.authors = ["Keyvan Fatehi"]
|
10
|
+
spec.email = ["keyvan@digitalfilmtree.com"]
|
11
|
+
spec.description = %q{Calculates employee payroll info based on California laws (overtime, doubletime, etc)}
|
12
|
+
spec.summary = %q{calculates overtime based on California law}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module WorkweekHelpers
|
2
|
+
def expect_week hash
|
3
|
+
describe "week" do
|
4
|
+
hash.each do |meth,val|
|
5
|
+
describe "##{meth}" do
|
6
|
+
specify { subject.send(meth).should eq val }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def expect_day index, hash
|
13
|
+
describe "day #{index}" do
|
14
|
+
hash.each do |meth,val|
|
15
|
+
describe "##{meth}" do
|
16
|
+
specify do
|
17
|
+
subject[index].send(meth).should eq val
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Overtimer::Workweek do
|
4
|
+
context 'standard' do
|
5
|
+
subject { Overtimer::Workweek.new [8,8,8,8,8,0,0] }
|
6
|
+
expect_week({
|
7
|
+
total:40,
|
8
|
+
regular:40,
|
9
|
+
overtime:0,
|
10
|
+
doubletime:0
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'worked on Saturday' do
|
15
|
+
subject { Overtimer::Workweek.new [8,8,8,8,8,8,0] }
|
16
|
+
expect_week({
|
17
|
+
total:48,
|
18
|
+
regular:40,
|
19
|
+
overtime:8,
|
20
|
+
doubletime:0
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'worked on Saturday and Sunday' do
|
25
|
+
# Alex Says: The seventh consecutive day is considered doubletime
|
26
|
+
# Ruthy Says: Joann's rules make above untrue
|
27
|
+
subject { Overtimer::Workweek.new [8,8,8,8,8,8,8] }
|
28
|
+
expect_week({
|
29
|
+
total:56,
|
30
|
+
regular:40,
|
31
|
+
overtime:16,
|
32
|
+
doubletime:0
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'worked hard' do
|
37
|
+
subject { Overtimer::Workweek.new [17,12,15,11,12,4,0] }
|
38
|
+
expect_day(0, {
|
39
|
+
total:17,
|
40
|
+
regular:8,
|
41
|
+
overtime:4,
|
42
|
+
doubletime:5
|
43
|
+
})
|
44
|
+
expect_week({
|
45
|
+
total:71,
|
46
|
+
regular:40,
|
47
|
+
overtime:23,
|
48
|
+
doubletime:8
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'worked soft' do
|
53
|
+
subject { Overtimer::Workweek.new [7,5,3,4,0,0,0] }
|
54
|
+
expect_week({
|
55
|
+
total:19,
|
56
|
+
regular:19,
|
57
|
+
overtime:0,
|
58
|
+
doubletime:0
|
59
|
+
})
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: overtimer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keyvan Fatehi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Calculates employee payroll info based on California laws (overtime,
|
84
|
+
doubletime, etc)
|
85
|
+
email:
|
86
|
+
- keyvan@digitalfilmtree.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- .ruby-gemset
|
94
|
+
- .ruby-version
|
95
|
+
- Gemfile
|
96
|
+
- Guardfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- config.example.yml
|
101
|
+
- lib/overtimer.rb
|
102
|
+
- lib/overtimer/version.rb
|
103
|
+
- lib/overtimer/workbase.rb
|
104
|
+
- lib/overtimer/workweek.rb
|
105
|
+
- overtimer.gemspec
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/support/workweek_helpers.rb
|
108
|
+
- spec/workweek_spec.rb
|
109
|
+
homepage: ''
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.0.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: calculates overtime based on California law
|
133
|
+
test_files:
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- spec/support/workweek_helpers.rb
|
136
|
+
- spec/workweek_spec.rb
|