pet-states.
Keep the countrywide manual in one rater
Save the countrywide rater aspet-states/base.rsl, with its four tables:
Complete example: pet-states/base.rsl
Complete example: pet-states/base.rsl
pet-states/base.rsl
pet-states/tables/BaseRate.csv
pet-states/tables/BreedFactor.csv
pet-states/tables/SexFactor.csv
pet-states/tables/AgeFactor.csv
Name the base in a state file
Texas files the countrywide manual as it stands. Its memorandum reprints the claims fee, so the Texas rater cites the fee on that page. Savepet-states/tx.rsl:
pet-states/tx.rsl
rsl: "0.4.2"is the RSL version that reads state files. The base keeps its own version.- The
specblock of the state file is thespecof the Texas rater. extends "base.rsl"names the base: a file in the folder of the state file.Sourcesdeclares the Texas filing. A plain section declares names of the state’s own.replace Constantsgives the claims fee the base’s value and the Texas citation.
Replace what the state’s pages change
The California pages file four tables and the claims fee, and add a breed group. Savepet-states/ca.rsl and the California tables:
Complete example: pet-states/ca.rsl
Complete example: pet-states/ca.rsl
pet-states/ca.rsl
pet-states/tables/ca/BaseRate.csv
pet-states/tables/ca/BreedFactor.csv
pet-states/tables/ca/SexFactor.csv
pet-states/tables/ca/AgeFactor.csv
replace names a declaration of the base and states the state’s version of it.
Replace a type and the tables it keys
California adds the breed groupgiant.
A replaced enumeration holds every member of the base’s enumeration:
giant takes the next id.
BreedFactor is keyed by BreedGroup, so California files it again with a row for giant.
A table that California declares in its own Tables section is keyed by California’s BreedGroup already, so it stands as written.
A replaced table keeps the base’s keys in the same order, and each column of the base under its name and type:
Change one row of a table
California changes the factor of male pets, and keeps the factor of female pets. A table’s rows are the rows of one file. A state that changes one row declares the whole table inreplace Tables and names its own CSV:
tables/ca/SexFactor.csv holds both rows: male at 1.02, and female at the countrywide 1.00.
Each key compares by its declared type. A number key, such as the age band 2, compares by value, so 2 and 2.0 are one key.
California files its own anniversary factors and keeps the countrywide inception factors. Its file tables/ca/AgeFactor.csv holds both columns.
Replace a constant
Add to a record and its chain
amend Records adds inputs, calculations and rules to a record of the base.
California asks whether the pet carries a microchip, and charges a fee for a senior pet:
amend chain adds a named step to the arithmetic of a calculation:
- The chain of
Pet.monthlystarts frombase_rate. Its steps readbreed_factor,sex_factor,age_factor,claims_feeandinception_factor, in that order. - A step is named by the value it reads.
before inception_factorputs the new step between the claims fee and the inception factor. - The base’s
roundholds the whole chain, so it rounds the new total. - The new step is the calculation
Pet.senior. California’s monthly premium isround((base_rate × breed_factor × sex_factor × age_factor + claims_fee + senior_charge) × inception_factor, 2, half_up).
Drop a base rule
The countrywide manual enrolls a pet up to age 14. California enrolls a pet up to age 13, under the same code:drop check removes each base rule with the code. A rule of the state’s own amend Records keeps the code, so California refuses age 14 with its own message.
Check and rate each state
rslc show prints the merged program of a state file, with the file that supplies each declaration:
rslc diff prints the difference between two states. Texas adds its own source and cites the claims fee at the countrywide value:
microchipped, and its own tables give $70.15.
A California dog aged 12 pays the senior charge before the inception factor:
round((44.20 × 1.21 × 1.02 × 2.00 + 3.60 + 2.50) × 1.25, 2, half_up) = 144.00.
California refuses a pet aged 14 with its own message. The countrywide rater accepts 14 and refuses 15:
Rater.build compiles a state file as the bundle’s rater.rsl, so name the base base.rsl, or any name other than rater.rsl.
Export a state
rslc export packages the rater that a state file gives:
source_files with the kind enum_csv: it is data that a check reads, and the rater rates only on the California files.
rslc check, rslc export and the catalog all read the same California rater.
Related
- Language reference: state files states every form and its rules.
- Check messages: state files explains each message of a state file.
- Split a rater into files imports types and tables from a second file.
- Versions explains how a patch such as 0.4.2 relates to its line.