A Rails plugin to access prices stored as cents in dollars
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
MIT-LICENSE
README.markdown
Rakefile
init.rb

README.markdown

InDollars

An ActiveRecord plugin to use price fields stored in cents as dollars.

Requires Money gem. (Tested with version 2.1.5)

Installation

script/plugin install git://github.com/sdbase/in_dollars.git

Example

Given there is an 'awesomes' table with 'price' and 'cost' integer columns:

class Awesome < ActiveRecord::Base
  in_dollars :price, :cost
end

awesome = Awesome.new

awesome.price = 10000
awesome.price_in_dollars # => 100.00

awesome.price_in_dollars = 50.00
awesome.price # => 5000

awesome.cost = 5000
awesome.cost_in_dollars # => 50.00

awesome.cost_in_dollars = 25.00
awesome.cost # => 2500

You can pass any arguments to *_in_dollars that you would to Money#format:

awesome.price_in_dollars(:symbol => true) # => $50.00

Copyright (c) 2009 sdbase, released under the MIT license