module D12n::ModelSupport
Public Class Methods
included(base)
click to toggle source
# File lib/d12n/model_support.rb, line 28 def self.included(base) base.extend ClassMethods end
Private Instance Methods
read_d12n_attribute(name, options = {})
click to toggle source
# File lib/d12n/model_support.rb, line 34 def read_d12n_attribute(name, options = {}) localized = instance_variable_get "@#{options[:prefix]}_#{name}" return localized if localized number = send(name) return unless number # If a factor is defined, internal presentation is an integer multiple of the local value number /= options[:factor].to_f if options[:factor] D12n.strategy.bigdecimal_to_formatted(number) end
write_d12n_attribute(name, val, options = {})
click to toggle source
# File lib/d12n/model_support.rb, line 46 def write_d12n_attribute(name, val, options = {}) instance_variable_set "@#{options[:prefix]}_#{name}", val number = D12n.strategy.formatted_to_bigdecimal(val) # If a factor is defined, internal presentation is an integer multiple of the local value number = (number * options[:factor].to_f).to_i if options[:factor] send "#{name}=", number val rescue ArgumentError val end