summaryrefslogtreecommitdiff
path: root/fuel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'fuel.lua')
-rw-r--r--fuel.lua30
1 files changed, 30 insertions, 0 deletions
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}