mod_factor

How to Use

Add factor model:

rails g model financial_factor key:string amount:decimal owner:references owner_type:string

Change factor model:

belongs_to :owner, :polymorphic => true

Include ModFactor::Owner to owner:

class SomeModel < ActiveRecord::Base
    include ModFactor::Owner
    factors :financial_factors do
        factor :prop_one
        factor :prop_formula, :generate => true, 
            :formula => proc {|owner|1 + 1}
        factor :prop_one_times_ten, :generate=>true, 
            :formula => proc {|owner| (owner.prop_one||0) * 10}
    end
end

Some sample usage:

some_model = SomeModel.new
some_model.prop_one             # nil
some_model.prop_one = 10    # 10
some_model.calculate
some_model.prop_one_times_ten # 100

Include some math helper

class SomeModel < ActiveRecord::Base
    include ModFactor::Math
end

Provides following:

some_model.sigma_geometric # http://en.wikipedia.org/wiki/Geometric_progression

Contributing to mod_factor

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright (c) 2012 Ryan Wong. See LICENSE.txt for further details.