# `Rating`

A rating on its own scale (schema.org): its value, from its `worst` to its `best`, the best above the worst. Shown `4.5/5`.

[Commerce and logistics](types.md#commerce-and-logistics); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `Rating { value: ...  best: ...  worst: ... }`.

Its parts keep these rules; a value that breaks one fails with the rule's name:

- `best_above_worst`: `best > worst`
- `value_on_scale`: `worst <= value and value <= best`

## Fields

| Field | Type |
|---|---|
| `value` | `Decimal` |
| `best` | `Decimal` |
| `worst` | `Decimal` |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

| JSON |
|---|
| `{"value":"4.5","best":"5","worst":"1"}` |
| `{"value":"8","best":"10","worst":"0"}` |
| `{"value":"92","best":"100","worst":"0"}` |
| `{"value":"1","best":"5","worst":"1"}` |

It is stored in 3 columns, each named for the field, `_` and its suffix. This is `{"value":"92","best":"100","worst":"0"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_value` | `numeric` | `92` |
| `<field>_best` | `numeric` | `100` |
| `<field>_worst` | `numeric` | `0` |

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"value":"4.5","best":"5","worst":"1"}` | `4.5/5` |
| `{"value":"8","best":"10","worst":"0"}` | `8/10` |
| `{"value":"92","best":"100","worst":"0"}` | `92/100` |
| `{"value":"1","best":"5","worst":"1"}` | `1/5` |

## Operations

It has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
