diff options
-rwxr-xr-x | dump.lua | 7 | ||||
-rw-r--r-- | fuel.lua | 30 |
2 files changed, 37 insertions, 0 deletions
diff --git a/dump.lua b/dump.lua new file mode 100755 index 0000000..4fb3d77 --- /dev/null +++ b/dump.lua @@ -0,0 +1,7 @@ +#!/usr/bin/env -S lua -l fuel +local f = fuel.fill +local r = fuel.relative +f("O", "2023-12-28", "17:55", 202230.0, "95", 100.21, 15.37) +f("O", "2024-02-23", "12:05", r(119.2), "lpg", 74.14, 23.61) +f("O", "2024-02-23", "12:18", 202350.9, "95", 100.02, 14.95) +f("O", "2024-04-05", "12:27", r(279.2), "95", 100.16, 14.86) diff --git a/fuel.lua b/fuel.lua new file mode 100644 index 0000000..c10b205 --- /dev/null +++ b/fuel.lua @@ -0,0 +1,30 @@ +local fmts = { + ["zł"] = "%.2f %s", + l = "%.2f %s", + km = "%.1f %s", +} + + +local function fmt (value, unit) + return (fmts[unit] or "%.1f"):format(value, unit) +end + + +local last_milage = 0 + + +local function relative (kilometres) + return last_milage + kilometres +end + + +local function fill (id, date, time, milage, fuel, cost, volume) + if last_milage > milage then + error "new milage may not be less than the previous" + end + last_milage = milage + print(id, date, time, fmt(last_milage, "km"), fuel, fmt(cost, "zł"), fmt(volume, "l")) +end + + +return {fill=fill, relative=relative} |