sg_month_workdays_calculator 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47da4c211aa5fbfecabb440e1510cf37d6ac2122
4
+ data.tar.gz: f91ff456063b54dbd6e33c4c015d6c006911d458
5
+ SHA512:
6
+ metadata.gz: f83f013cf7b8e2813aca835897023b954b0ead6877a58bc95c4212ddb061651cd248dd361a2406f85ba38bc0d764f33aed0cd1802ccd1e1b6dfa21ae6713bd5c
7
+ data.tar.gz: bd0f921302ec23049e3cc3a39cfacd5c5a994aabb7683cea9a08796defc2343bc436901120a4a7d041ae9b617365d1bd3b66195b5134e6f26a29dcea447946eb
@@ -0,0 +1,85 @@
1
+ # This class calculates the number of working days for a date period according to MOM
2
+ # http://www.mom.gov.sg/employment-practices/salary/calculate-pay-for-incomplete-month
3
+ class SgMonthWorkdaysCalculator
4
+ def self.work_days(period:, weekly_workdays:)
5
+ new(period: period, weekly_workdays: weekly_workdays).work_days
6
+ end
7
+
8
+ # @param [DatePeriod] period
9
+ # @param [FixNum] weekly_workdays
10
+ def initialize(period:, weekly_workdays:)
11
+ @period = period
12
+ @weekly_workdays = weekly_workdays
13
+ end
14
+
15
+ # @return [FixNum] the number of working days
16
+ # This method smells of :reek:TooManyStatements, but we would like to keep this method very explicit.
17
+ # rubocop:disable Metrics/AbcSize
18
+ def work_days
19
+ case weekly_workdays
20
+ when 2.5
21
+ calendar_days - ((number_of_wednesdays / 2.0) + number_of_thursdays + number_of_fridays + number_of_weekends)
22
+ when 3
23
+ calendar_days - (number_of_thursdays + number_of_fridays + number_of_weekends)
24
+ when 3.5
25
+ calendar_days - ((number_of_thursdays / 2.0) + number_of_fridays + number_of_weekends)
26
+ when 4
27
+ calendar_days - (number_of_fridays + number_of_weekends)
28
+ when 4.5
29
+ calendar_days - ((number_of_fridays / 2.0) + number_of_weekends)
30
+ when 5
31
+ calendar_days - number_of_weekends
32
+ when 5.5
33
+ calendar_days - ((number_of_saturdays / 2.0) + number_of_sundays)
34
+ when 6
35
+ calendar_days - number_of_sundays
36
+ else
37
+ raise "Expected workdays between 2.5 and 6 by increments of .5 but got #{weekly_workdays}."
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :period, :weekly_workdays
44
+
45
+ # Sunday: 0
46
+ # Monday: 1
47
+ # Tuesday: 2
48
+ # Wednesday: 3
49
+ # Thursday: 4
50
+ # Friday: 5
51
+ # Saturday: 6
52
+
53
+ def number_of_days_for(weekday_number)
54
+ period.count { |day| day.wday == weekday_number }
55
+ end
56
+
57
+ def number_of_sundays
58
+ number_of_days_for(0)
59
+ end
60
+
61
+ def number_of_wednesdays
62
+ number_of_days_for(3)
63
+ end
64
+
65
+ def number_of_thursdays
66
+ number_of_days_for(4)
67
+ end
68
+
69
+ def number_of_fridays
70
+ number_of_days_for(5)
71
+ end
72
+
73
+ def number_of_saturdays
74
+ number_of_days_for(6)
75
+ end
76
+
77
+ # Saturdays and Sundays
78
+ def number_of_weekends
79
+ number_of_saturdays + number_of_sundays
80
+ end
81
+
82
+ def calendar_days
83
+ period.count
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sg_month_workdays_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mykola Kyryk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-26 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
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
+ - !ruby/object:Gem::Dependency
84
+ name: reek
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Implements month workdays calculation for calculating pay for an incomplete
98
+ month of work.
99
+ email:
100
+ - mkyryk@payrollhero.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - lib/sg_month_workdays_calculator.rb
106
+ homepage: https://github.com/payrollhero/sg_month_workdays_calculator
107
+ licenses:
108
+ - BSD-3-Clause
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Implements month workdays calculation for calculating pay for an incomplete
130
+ month of work.
131
+ test_files: []