Skip to main content

Module money

Module money 

Source
Expand description

Money: exact amounts, and the amounts written in mail.

Amounts are kept in cents so sums never drift. Mail writes them in every national style (“1 234,56 €”, “€1,234.56”, “$20.00 USD”, “-8,49 €”).

Two readers: find_amount, the first amount after a word like “total” or “you received”; and payment_amount, for receipts, which also knows that the amount paid is stated in a sentence, on the total’s line, or last, and that a company’s share capital in the legal footer is never it.

Structs§

Amount
An amount found in a message, with its currency (ISO 4217).
Found
An amount found in a message, where it was, and what follows it.
Money
An amount in cents. Written in euros in configuration files: -250, 68.5.
Placed 🔒
An amount written next to a currency mark, and where it starts and ends.

Constants§

CURRENCIES 🔒
Currency marks, longest first so “EUR” is not read as something shorter.

Functions§

all_amounts 🔒
Every amount written next to a currency mark, in order. A minus sign right before the number makes it negative (“-8,49 €”, a discount).
currency_at 🔒
A currency mark starting at i: a symbol, or a code that is a whole word.
find_amount
The amount a message is about: the first after a word after which it usually comes (MoneyWords::keywords: “total”, “you received”), else the first.
grouped_digits 🔒
The digits of a whole part whose thousands are grouped by threes: “1 234” → “1234”. When the groups are not threes (“3 25”, a reference then a price), only the last group is the number.
in_number 🔒
Characters that can be inside a written number: digits, separators, spaces.
is_legal 🔒
last 🔒
line_amounts 🔒
The amounts of one line, each with the rest of the line after it.
line_amounts_after 🔒
The amounts of a line starting at character from (as fold counts them: folding keeps one character per character).
number_after 🔒
The number that starts just after position start (one space allowed), and where it ends.
number_before 🔒
The number that ends just before position end (one space allowed).
parse_number 🔒
“1 234,56”, “1,234.56”, “25,00”, “12,5”, “1250”, “20.00” → cents.
payment_amount
The amount a payment message is about, in this order of trust:
stated 🔒
stated_amount
The amount stated by a sentence (“Vous avez payé 387,00 € à…”), with what follows it.
total 🔒
without_code 🔒
“EUR à Exemple” → “à Exemple”: a currency code repeated after the symbol is not what follows.