Method: Amountable::ClassMethod#amount

Defined in:
lib/amountable.rb

#amount(name, options = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/amountable.rb', line 94

def amount(name, options = {})
  (self.amount_names ||= Set.new) << name

  define_method name do
    (find_amount(name) || Amountable::NilAmount.new).value
  end

  define_method "#{name}=" do |value|
    set_amount(name, value)
  end

  Array(options[:summable] || options[:summables] || options[:set] || options[:sets] || options[:amount_set] || options[:amount_sets]).each do |set|
    amount_set(set, name)
  end
end