← All labs
Calc Kit
Define a calculator once in a small Ruby DSL — typed inputs, outputs, and a calculate method — and Calc Kit gives you validation and a working calculator. Here's the definition on the left and the live calculator on the right.
The definition
class BuildEstimateCalculator < ApplicationCalculator
input :weeks, :integer, min: 1, default: 6
input :weekly_rate, :decimal, min: 0, default: 6000
input :complexity, :select,
options: %w[simple standard complex]
input :rush, :boolean, default: false
output :base, :currency
output :total, :currency
def calculate
base = weeks * weekly_rate
total = base * MULTIPLIERS.fetch(complexity)
total *= 1.2 if rush
{ base:, total: }
end
end