Sha256: a51e417398e17bb9635836c09a90aef7b7ace70b0ca772e9c4c46c0b9e41634e

Contents?: true

Size: 561 Bytes

Versions: 1

Compression:

Stored size: 561 Bytes

Contents

module Prezzo
  module Explainable
    def self.included(base)
      base.class_eval do
        base.extend(ClassMethods)
      end
    end

    module ClassMethods
      def explain_with(*methods)
        define_method(:explain) do
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prezzo-0.4.0 lib/prezzo/explainable.rb