Method: Exchange::Typecasting#attribute

Defined in:
lib/exchange/typecasting.rb,
lib/exchange/typecasting.rb

#attribute(data) ⇒ Object

Installs a money setter



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/exchange/typecasting.rb', line 54

def install_money_getter attribute, options={}
  
  define_method :"#{attribute}_with_exchange_typecasting" do
    currency = evaluate_money_option(options[:currency]) if options[:currency]
    
    test_for_currency_error(currency, attribute)
    
    time     = evaluate_money_option(options[:at]) if options[:at]
    
    if value = send(:"#{attribute}_without_exchange_typecasting")
      Exchange::Money.new(value) do |c|
        c.currency = currency
        c.time     = time if time
      end
    end
  end
  exchange_typecasting_alias_method_chain attribute
  
end