class Piawe::RuleSet
Class to encapsulate a set of PIAWE payment rules
Public Class Methods
Create a new RuleSet to represent the rules contained in a rules array The primary responsibiltiy of this class is to delegate rendering of a report line to the appropriate Rule
Parameters¶ ↑
-
rules_array
- An array of rule hashes
Rule Hash¶ ↑
A rule hash it a Ruby hash that has has the following format:
{"rules":[ {"applicableWeeks": "1-26", "percentagePayable": 90, "overtimeIncluded": true}, {"applicableWeeks": "27-52", "percentagePayable": 80, "overtimeIncluded": true}, {"applicableWeeks": "53-79", "percentagePayable": 70, "overtimeIncluded": true}, {"applicableWeeks": "80-104", "percentagePayable": 60, "overtimeIncluded": false}, {"applicableWeeks": "105+", "percentagePayable": 10, "overtimeIncluded": false} ]}
-
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.
-
percentagePayable - A Numeric that indicates the percentage of Average Weekly Earnings that are paid when this rule applies.
-
overtimeIncluded - A TrueClass or FalseClass that indicates whether overtime earnings should be considered part of Average Weekly Earnings when this rule applies.
# File lib/piawe/rule_set.rb, line 35 def initialize(rules_array) rules_array && rules_array.is_a?(Array) || (raise ArgumentError, "rules array is required - got #{rules_array.inspect}") rules_array.size > 0 || (raise ArgumentError, "rules array must contain at least one entry") rules_array.each do |rule_hash| add(Rule.played_by rule_hash) end rules[-1].end_week.nil? || (raise ArgumentError, "last rule must have a terminating + sign") end
Public Instance Methods
Based on the included Rules, generate a report line for a given person at a given report date by delegating to matching Rule objects
Parameters¶ ↑
-
person
- The Piawe::Person for whom the report line should be generated -
report_date
- The Date for which the report line should be generated
# File lib/piawe/rule_set.rb, line 55 def report_line(person, report_date) rules.each do |rule| return rule.report_line( person, report_date ) if rule.matches?( person.weeks_since_injury( report_date ) ) end # each rule # this should not be possible - but putting this here defensively... 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})" end