jg_piawe 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.simplecov +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/piawe_report +11 -0
- data/lib/piawe/file_parser.rb +67 -0
- data/lib/piawe/rule_set.rb +179 -0
- data/lib/piawe/version.rb +3 -0
- data/lib/piawe.rb +143 -0
- data/piawe.gemspec +28 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7381321f2b5b45971f4b9d13140872b395ae31d
|
4
|
+
data.tar.gz: aff58d71e43d64d21ba381535a9c5f4f76531f07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f46d0e44fe3db1ca1d43f1b2086f923b387635489047b76a3daf7231a66f5e321311467020680186575ac9d80e969e7f0349d6f350a4e9b6c710b91af737debf
|
7
|
+
data.tar.gz: 09c31fdd61202a81202baa68166d454ee14085519b4b89c3eebe744d3c5273c24c90280b562aa0a5d8539baa4e936cac61fe529cf25e4f70f4c4d83bc96f914a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Piawe
|
2
|
+
|
3
|
+
This gem implements a PIAWE report generator
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jg_piawe'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jg_piawe
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Once the gem has been installed, PIAWE reports can be produced using the piawe_report command line utility. The syntax for this utility is:
|
24
|
+
|
25
|
+
```
|
26
|
+
piawe_report peopleFile rulesFile [reportDate]
|
27
|
+
```
|
28
|
+
e.g.:
|
29
|
+
```
|
30
|
+
piawe_report ~/workspace/piawe/spec/files/people.json ~/workspace/piawe/spec/files/rules_fixed.json '2017/02/01'
|
31
|
+
```
|
32
|
+
|
33
|
+
The date parameter is optional - it will default to the current date if omitted.
|
34
|
+
|
35
|
+
The report will be output to stdout.
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/piawe/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "piawe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/piawe_report
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'piawe'
|
4
|
+
|
5
|
+
#tosimpletotest
|
6
|
+
if [2,3].include? ARGV.size
|
7
|
+
puts Piawe::FileParser.new( ARGV[0], ARGV[1], ARGV.size > 2 ? ARGV[2] : Date.today.strftime('%Y/%m/%d') ).report
|
8
|
+
else
|
9
|
+
puts "Usage:"
|
10
|
+
puts "piawe_report peopleFile rulesFile [reportDate]"
|
11
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Class to read people and rules files and convert them into a PIAWE report
|
2
|
+
class Piawe::FileParser
|
3
|
+
|
4
|
+
# Create a new FileParser to generate a PIAWE report from files
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
#
|
9
|
+
# * +people_file_name+ - Fully qualified path of the people file
|
10
|
+
# * +rules_file_name+ - Fully qualified path of the rules file
|
11
|
+
# * +report_date_string+ - Report date to use, in YYYY/MM/DD format
|
12
|
+
#
|
13
|
+
def initialize( people_file_name, rules_file_name, report_date_string )
|
14
|
+
@people_file_name = people_file_name
|
15
|
+
@rules_file_name = rules_file_name
|
16
|
+
@report_date_string = report_date_string
|
17
|
+
end
|
18
|
+
|
19
|
+
# Generate a JSON hash containing the PIAWE report
|
20
|
+
def report
|
21
|
+
JSON.pretty_generate( { piawe_report: Piawe.new( people_array, rules_array ).report( report_date ) } )
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def people_array
|
27
|
+
people_hash["people"] || (raise ArgumentError, "people hash did not contain a people key!")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def people_hash
|
32
|
+
JSON.parse people_file.read
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def people_file
|
37
|
+
File.exist?(@people_file_name) ? File.new(@people_file_name) : (raise ArgumentError, "Could not find file #{@people_file_name}")
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def rules_array
|
42
|
+
rules_hash["rules"] || (raise ArgumentError, "rules hash did not contain a rules key")
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def rules_hash
|
47
|
+
JSON.parse rules_file.read
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def rules_file
|
52
|
+
File.exist?(@rules_file_name) ? File.new(@rules_file_name) : (raise ArgumentError, "Could not find file #{@rules_file_name}")
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def report_date
|
57
|
+
/^(?<yyyy>\d{4})\/(?<mm>\d{2})\/(?<dd>\d{2})$/ =~ @report_date_string || (raise ArgumentError, "report_date_string was not in YYYY/MM/DD format")
|
58
|
+
result = nil
|
59
|
+
begin
|
60
|
+
result = Date.new(yyyy.to_i, mm.to_i, dd.to_i)
|
61
|
+
rescue ArgumentError => ex
|
62
|
+
raise ArgumentError, "report_date_string does not represent a valid date: #{@report_date_string}"
|
63
|
+
end
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'role_playing'
|
3
|
+
|
4
|
+
# Class to encapsulate a set of PIAWE payment rules
|
5
|
+
class Piawe::RuleSet
|
6
|
+
|
7
|
+
include RolePlaying::Context
|
8
|
+
|
9
|
+
|
10
|
+
# Create a new RuleSet to represent the rules contained in a rules array
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# ==== Parameters
|
14
|
+
#
|
15
|
+
# * +rules_array+ - An array of rule hashes
|
16
|
+
#
|
17
|
+
# ==== Rule Hash
|
18
|
+
#
|
19
|
+
# A rule hash it a Ruby hash that has has the following format:
|
20
|
+
#
|
21
|
+
# {"rules":[
|
22
|
+
# {"applicableWeeks": "1-26", "percentagePayable": 90, "overtimeIncluded": true},
|
23
|
+
# {"applicableWeeks": "27-52", "percentagePayable": 80, "overtimeIncluded": true},
|
24
|
+
# {"applicableWeeks": "53-79", "percentagePayable": 70, "overtimeIncluded": true},
|
25
|
+
# {"applicableWeeks": "80-104", "percentagePayable": 60, "overtimeIncluded": false},
|
26
|
+
# {"applicableWeeks": "105+", "percentagePayable": 10, "overtimeIncluded": false}
|
27
|
+
# ]}
|
28
|
+
#
|
29
|
+
# * applicableWeeks - A String that indicates the range of injury weeks during which the rule applies - Week 1 starts at the day of the injury, and Week 2 starts on the 7th day after the injury, and so on. It can have two formats: either a start week and end week joined by a dash, or a start week followed by a plus sign, which indicates the rule should apply to all later weeks as well. The first rule must have a start week of 1, the last rule must use the plus sign syntax, and all intervening rules must have a start week that is one greater than the end week of the preceeding rule.
|
30
|
+
#
|
31
|
+
# * percentagePayable - A Numeric that indicates the percentage of Average Weekly Earnings that are paid when this rule applies.
|
32
|
+
#
|
33
|
+
# * overtimeIncluded - A TrueClass or FalseClass that indicates whether overtime earnings should be considered part of Average Weekly Earnings when this rule applies.
|
34
|
+
def initialize(rules_array)
|
35
|
+
rules_array && rules_array.is_a?(Array) || (raise ArgumentError, "rules array is required - got #{rules_array.inspect}")
|
36
|
+
rules_array.size > 0 || (raise ArgumentError, "rules array must contain at least one entry")
|
37
|
+
rules_array.each do |rule_hash|
|
38
|
+
add(Rule.played_by rule_hash)
|
39
|
+
end
|
40
|
+
rules[-1].end_week.nil? || (raise ArgumentError, "last rule must have a terminating + sign")
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Based on the included Rules, generate a report line for a given person at a given report date
|
45
|
+
# This is included in the RuleSet class for expedience - a cleaner separation of concerns could be
|
46
|
+
# achieved by factoring this method into a report generator class, that calls a RuleSet.get_rule(person, report_date) method.
|
47
|
+
#
|
48
|
+
#
|
49
|
+
# ==== Parameters
|
50
|
+
#
|
51
|
+
# * +person+ - The Piawe::Person for whom the report line should be generated
|
52
|
+
#
|
53
|
+
# * +report_date+ - The Date for which the report line should be generated
|
54
|
+
#
|
55
|
+
def report_line(person, report_date)
|
56
|
+
rules.each do |rule|
|
57
|
+
return rule.report_line( person, report_date ) if rule.matches?( person.weeks_since_injury( report_date ) )
|
58
|
+
end # each rule
|
59
|
+
# this should not be possible - but putting this here defensively...
|
60
|
+
raise "APPLICATION BUG - A RuleSet EXISTS THAT DOES NOT COVER ALL POSSIBLE DATES!! (Date was #{report_date.strftime('%Y/%m/%d')}, person was #{person.inspect})"
|
61
|
+
end # method payment_report
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
|
70
|
+
def add(rule)
|
71
|
+
# check consistency of rule dates
|
72
|
+
(rule.end_week.nil? || rule.end_week > rule.start_week) || (raise ArgumentError, "rule #{rules.size + 1} has an end week of #{rule.end_week} that is not later than it's start week of #{rule.start_week}")
|
73
|
+
if rules[-1] # we have existing rules, check we are consistent
|
74
|
+
rules[-1].end_week || (raise ArgumentError, "rule #{rules.size} has a terminating + sign, and should have been the last rule, however there was a subsequent rule: #{rule.inspect}")
|
75
|
+
rule.start_week == rules[-1].end_week + 1 || (raise ArgumentError, "rule #{rules.size} ends at week #{rules[-1].end_week} but rule #{rules.size + 1} starts at week #{rule.start_week} - each rule should start one week after the prior rule ends")
|
76
|
+
else # this should be the first rule - check it's start date
|
77
|
+
1 == rule.start_week || (raise ArgumentError, "rule 1 should start at week 1, but starts at week #{rule.start_week}")
|
78
|
+
end # if we have existing rules
|
79
|
+
rules << rule
|
80
|
+
end # method add
|
81
|
+
|
82
|
+
|
83
|
+
def rules
|
84
|
+
@rules ||= []
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
# role to be added to a rule hash
|
91
|
+
role :Rule do
|
92
|
+
|
93
|
+
def start_week
|
94
|
+
@start_week ||= (
|
95
|
+
/(?<starting_week>\d+)[+-]/ =~ applicable_weeks
|
96
|
+
starting_week.to_i
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def end_week
|
102
|
+
@end_week ||= if /\+$/ =~ applicable_weeks
|
103
|
+
nil
|
104
|
+
else
|
105
|
+
( /\d*\-(?<ending_week>\d+)$/ =~ applicable_weeks ) || (raise ArgumentError, "invalid applicableWeeks value: #{applicable_weeks}")
|
106
|
+
ending_week.to_i
|
107
|
+
end # if trailing + sign
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def applicable_weeks
|
112
|
+
@applicable_weeks ||= (
|
113
|
+
self.has_key?("applicableWeeks") || (raise ArgumentError, "rule hash did not have an applicableWeeks key: #{self.inspect}")
|
114
|
+
/(^\d+\-\d+$)|(^\d+\+$)/ =~ self["applicableWeeks"] || (raise ArgumentError, "applicableWeeks key is not in valid format")
|
115
|
+
self["applicableWeeks"]
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def percentage_payable
|
121
|
+
self.has_key?("percentagePayable") || (raise ArgumentError, "rule_hash does not have a percentagePayable key: #{self.inspect}")
|
122
|
+
self["percentagePayable"].is_a?(Numeric) || (raise ArgumentError, "rule_hash has a non-numeric value for percentagePayable key: #{self['percentagePayable']}")
|
123
|
+
BigDecimal.new self["percentagePayable"]
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def overtime_included
|
128
|
+
self.has_key?("overtimeIncluded") || (raise ArgumentError, "rule_hash does not have an overtimeIncluded key: #{self.inspect}")
|
129
|
+
( self["overtimeIncluded"].is_a?(TrueClass) || self["overtimeIncluded"].is_a?(FalseClass) ) || (raise ArgumentError, "overtimeIncluded value was not a boolean true or false - value was #{ self['overtimeIncluded'] }" )
|
130
|
+
self["overtimeIncluded"]
|
131
|
+
end
|
132
|
+
|
133
|
+
# The weeks_since_injury value is interpreted as a statement of which injury week we
|
134
|
+
# are currently in - the first week commencing at the date of the injury, the second week
|
135
|
+
# commencing 7 days after that date etc.
|
136
|
+
def matches?(weeks_since_injury)
|
137
|
+
weeks_since_injury >= (start_week - 1).to_f && # it's after the prior week, i.e. when injured, you are immediately in the first
|
138
|
+
# week of injury
|
139
|
+
(
|
140
|
+
end_week.nil? ||
|
141
|
+
weeks_since_injury < end_week.to_f # it's before the end_week number - i.e. exactly 1 week after an injury,
|
142
|
+
# you are now into the second week of injury
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def pay_for_this_week( person )
|
148
|
+
(
|
149
|
+
(
|
150
|
+
person.normal_hours * person.hourly_rate + (
|
151
|
+
overtime_included ? person.overtime_hours * person.overtime_rate : 0
|
152
|
+
)
|
153
|
+
) * ( percentage_payable / 100 )
|
154
|
+
).round(2)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def report_line(person, report_date)
|
159
|
+
{
|
160
|
+
name: person.name,
|
161
|
+
pay_for_this_week: sprintf( "%.2f", pay_for_this_week( person ) ),
|
162
|
+
weeks_since_injury: sprintf( "%.2f", person.weeks_since_injury( report_date ) ),
|
163
|
+
hourly_rate: sprintf( "%.6f", person.hourly_rate ),
|
164
|
+
overtime_rate: sprintf( "%.6f", person.overtime_rate ),
|
165
|
+
normal_hours: sprintf( "%.2f", person.normal_hours ),
|
166
|
+
overtime_hours: sprintf( "%.2f", person.overtime_hours ),
|
167
|
+
percentage_payable: sprintf( "%.2f", percentage_payable ),
|
168
|
+
overtime_included: overtime_included.to_s
|
169
|
+
}
|
170
|
+
end # method report_line
|
171
|
+
|
172
|
+
end # role Rule
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
end # class Piawe::RuleSet
|
177
|
+
|
178
|
+
|
179
|
+
|
data/lib/piawe.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'piawe/version'
|
2
|
+
require 'piawe/rule_set'
|
3
|
+
require 'piawe/file_parser'
|
4
|
+
require 'role_playing'
|
5
|
+
require 'date'
|
6
|
+
require 'bigdecimal'
|
7
|
+
|
8
|
+
# Class to encapsulate PIAWE report generation
|
9
|
+
class Piawe
|
10
|
+
|
11
|
+
include RolePlaying::Context
|
12
|
+
|
13
|
+
# Create a new Piawe instance to generate reports for a particular set of people and rules
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# ==== Parameters
|
17
|
+
#
|
18
|
+
# * +people_array+ - An array of people hashes
|
19
|
+
#
|
20
|
+
# * +rules_array+ - An array of rule hashes
|
21
|
+
#
|
22
|
+
# ==== People Hash
|
23
|
+
#
|
24
|
+
# A people hash it a Ruby hash that has has the following format:
|
25
|
+
#
|
26
|
+
# {"people": [
|
27
|
+
# {"name": "Ebony Boycott", "hourlyRate": 75.0030, "overtimeRate": 150.0000, "normalHours": 35.0, "overtimeHours": 7.3, "injuryDate": "2016/05/01" },
|
28
|
+
# {"name": "Geoff Rainford-Brent", "hourlyRate": 30.1234, "overtimeRate": 60.3456, "normalHours": 25.0, "overtimeHours": 10.7, "injuryDate": "2016/08/04" },
|
29
|
+
# {"name": "Meg Gillespie", "hourlyRate": 50.0000, "overtimeRate": 100.0000, "normalHours": 37.5, "overtimeHours": 0.0, "injuryDate": "2015/12/31" },
|
30
|
+
# {"name": "Jason Lanning", "hourlyRate": 40.0055, "overtimeRate": 90.9876, "normalHours": 40.0, "overtimeHours": 12.4, "injuryDate": "2013/01/01" }
|
31
|
+
# ]}
|
32
|
+
#
|
33
|
+
# * name - The person's name.
|
34
|
+
#
|
35
|
+
# * hourlyRate - The person's hourly rate of pay, calculated according to PIAWE rules.
|
36
|
+
#
|
37
|
+
# * overtimeRate - The person's overtime rate of pay, calculated according to PIAWE rules.
|
38
|
+
#
|
39
|
+
# * normalHours - The person's normal weekly hours, calculated according to PIAWE rules.
|
40
|
+
#
|
41
|
+
# * overtimeHours - The person's normal weekly overtime hours, calculated according to PIAWE rules.
|
42
|
+
#
|
43
|
+
# * injuryDate - The date of the injury that caused the person to cease work.
|
44
|
+
#
|
45
|
+
# ==== Rule Hash
|
46
|
+
#
|
47
|
+
# A rule hash it a Ruby hash that has has the following format:
|
48
|
+
#
|
49
|
+
# {"rules":[
|
50
|
+
# {"applicableWeeks": "1-26", "percentagePayable": 90, "overtimeIncluded": true},
|
51
|
+
# {"applicableWeeks": "27-52", "percentagePayable": 80, "overtimeIncluded": true},
|
52
|
+
# {"applicableWeeks": "53-79", "percentagePayable": 70, "overtimeIncluded": true},
|
53
|
+
# {"applicableWeeks": "80-104", "percentagePayable": 60, "overtimeIncluded": false},
|
54
|
+
# {"applicableWeeks": "105+", "percentagePayable": 10, "overtimeIncluded": false}
|
55
|
+
# ]}
|
56
|
+
#
|
57
|
+
# * applicableWeeks - A String that indicates the range of injury weeks during which the rule applies - Week 1 starts at the day of the injury, and Week 2 starts on the 7th day after the injury, and so on. It can have two formats: either a start week and end week joined by a dash, or a start week followed by a plus sign, which indicates the rule should apply to all later weeks as well. The first rule must have a start week of 1, the last rule must use the plus sign syntax, and all intervening rules must have a start week that is one greater than the end week of the preceeding rule.
|
58
|
+
#
|
59
|
+
# * percentagePayable - A Numeric that indicates the percentage of Average Weekly Earnings that are paid when this rule applies.
|
60
|
+
#
|
61
|
+
# * overtimeIncluded - A TrueClass or FalseClass that indicates whether overtime earnings should be considered part of Average Weekly Earnings when this rule applies.
|
62
|
+
def initialize( people_array, rules_array )
|
63
|
+
@rules = Piawe::RuleSet.new rules_array
|
64
|
+
@people = people_array.map { |person_hash| Person.played_by(person_hash) }
|
65
|
+
end # initialize
|
66
|
+
|
67
|
+
|
68
|
+
# Generate a PIAWE report (Ruby Hash format) for the people and rules this Piawe instance encapsulates, as at the specified report date.
|
69
|
+
#
|
70
|
+
# ==== Parameters
|
71
|
+
#
|
72
|
+
# * +report_date+ - The date for which the report should be generated. Defaults to the current date
|
73
|
+
#
|
74
|
+
def report( report_date=Date.today )
|
75
|
+
{
|
76
|
+
report_date: report_date.strftime("%Y/%m/%d"),
|
77
|
+
report_lines: @people.map { |person| @rules.report_line(person, report_date) }
|
78
|
+
}
|
79
|
+
end # method report
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
role :Person do
|
84
|
+
|
85
|
+
def weeks_since_injury(report_date) # :nodoc:
|
86
|
+
@weeks_since_injury ||= ( report_date - injury_date) / 7
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def injury_date # :nodoc:
|
91
|
+
@injury_date ||= (
|
92
|
+
self.has_key?("injuryDate") || (raise ArgumentError, "person_hash does not have a key of injuryDate: #{self.inspect}")
|
93
|
+
/^\d{4}\/\d{2}\/\d{2}$/ =~ self["injuryDate"] || (raise ArgumentError, "injury date of #{self["injuryDate"]} is not in yyyy/mm/dd format: #{self.inspect}")
|
94
|
+
result = nil
|
95
|
+
begin
|
96
|
+
result = Date.parse self["injuryDate"]
|
97
|
+
rescue ArgumentError => ex
|
98
|
+
raise ArgumentError, "person_hash has an invalidly formatted injuryDate key: #{self.inspect} }"
|
99
|
+
end
|
100
|
+
result <= Date.today || (raise ArgumentError, "person_hash has an injuryDate value that is in the future: #{self.inspect}")
|
101
|
+
result
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def name # :nodoc:
|
107
|
+
self.has_key?("name") || (raise ArgumentError, "person_hash does not have a key of name: #{self.inspect}")
|
108
|
+
self["name"] || (raise ArgumentError, "person_hash has a nil value for name key: #{self.inspect}")
|
109
|
+
self["name"]
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def hourly_rate # :nodoc:
|
114
|
+
get_decimal "hourlyRate"
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def overtime_rate # :nodoc:
|
119
|
+
get_decimal "overtimeRate"
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def normal_hours # :nodoc:
|
124
|
+
get_decimal "normalHours"
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def overtime_hours # :nodoc:
|
129
|
+
get_decimal "overtimeHours"
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def get_decimal(key) # :nodoc:
|
134
|
+
self.has_key?(key) || (raise ArgumentError, "person_hash does not have a key of #{key}: #{self.inspect}")
|
135
|
+
self[key].is_a?(Numeric) || (raise ArgumentError, "person_hash has a non-numeric value for #{key} key: #{self.inspect}")
|
136
|
+
BigDecimal.new self[key], 15
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
end # class Piawe
|
data/piawe.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'piawe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'jg_piawe'
|
8
|
+
spec.version = Piawe::VERSION
|
9
|
+
spec.authors = ["John Gray"]
|
10
|
+
spec.email = 'foo@bar.com'
|
11
|
+
spec.date = '2017-03-08'
|
12
|
+
|
13
|
+
spec.summary = "PIAWE calculator"
|
14
|
+
spec.description = "A simple calculator for PIAWE based payments"
|
15
|
+
spec.homepage = 'http://rubygems.org/gems/jg_piawe'
|
16
|
+
spec.license = 'GPL-3.0'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
|
+
spec.add_runtime_dependency "role_playing", ["= 0.1.5"]
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jg_piawe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Gray
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-08 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
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: role_playing
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.5
|
83
|
+
description: A simple calculator for PIAWE based payments
|
84
|
+
email: foo@bar.com
|
85
|
+
executables:
|
86
|
+
- piawe_report
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".simplecov"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- exe/piawe_report
|
100
|
+
- lib/piawe.rb
|
101
|
+
- lib/piawe/file_parser.rb
|
102
|
+
- lib/piawe/rule_set.rb
|
103
|
+
- lib/piawe/version.rb
|
104
|
+
- piawe.gemspec
|
105
|
+
homepage: http://rubygems.org/gems/jg_piawe
|
106
|
+
licenses:
|
107
|
+
- GPL-3.0
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: PIAWE calculator
|
129
|
+
test_files: []
|