lib/prezzo/explainable.rb in prezzo-0.3.1 vs lib/prezzo/explainable.rb in prezzo-0.4.0

- old
+ new

@@ -5,14 +5,22 @@ base.extend(ClassMethods) end end module ClassMethods - def explain_with(*options) + def explain_with(*methods) define_method(:explain) do - options.each_with_object({}) do |method, explanation| - explanation[method] = send(method) + explanation = { + total: calculate, + } + + components = methods.each_with_object({}) do |method, acc| + acc[method] = send(method) end + + explanation[:components] = components unless components.empty? + + explanation end end end end end