Sha256: 97489545a5c23544d01e819533be9522cadad59f493f64548b694b892ffaf39f

Contents?: true

Size: 573 Bytes

Versions: 3

Compression:

Stored size: 573 Bytes

Contents

module Customize
	class Formular < ActiveRecord::Base
		belongs_to :related, :polymorphic=>true
		serialize :calculator_attributes

		def calculator
			return unless calculator_name
			cal = calculator_name.constantize
			cal_ins = cal.new
			calculator_attributes.try :symbolize_keys! if calculator_attributes.respond_to? :symbolize_keys!
			names = (calculator_attributes.keys.map!(&:to_sym) & cal.inputs) if calculator_attributes
			names.each do |name|
				cal_ins.instance_variable_set "@#{name}", calculator_attributes[name]
			end if names
			cal_ins
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
customize-0.0.8 app/models/customize/formular.rb
customize-0.0.7 app/models/customize/formular.rb
customize-0.0.6 app/models/customize/formular.rb