110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/fantastic_currency.rb', line 110
def currency(field_name)
define_method "#{field_name.to_s}" do |*args|
if self[field_name]
format_currency(self[field_name], { :currency => self[:currency] }.merge(args.first || {}))
end
end
alias_method "#{field_name.to_s}_before_type_cast", "#{field_name}"
define_method "#{field_name.to_s}=" do |value|
raise "Money doesn't float!" if value.class.name == "Float"
currency = FantasticCurrency::Config.get_currency(self[:currency])
self[field_name] = (BigDecimal.new(value.to_s) * (10**currency[:precision])).to_i
end
end
|