Giter Site home page Giter Site logo

kdonovan / rails_money Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jerrett/rails_money

1.0 2.0 1.0 89 KB

Rails Money Plugin - fork adds ability to create Money objects directly from other Money objects.

Home Page: http://www.nullcreations.net/

License: MIT License

Ruby 100.00%

rails_money's Introduction

= Rails Money

Note! This is NOT compatible with the 'money' gem!

A handler for storing money in ActiveRecord objects as integers (as cents), but dealing
with them as Money Objects.


Note: Dividing a money object will return an array of Money objects. This ensures cents 
do not go missing.

For example:

  >> money = Money.new(10.00)
  => #<Money:0xb76b3e14 @cents=1000> 
  >> money / 3
  => [#<Money:0xb76b3e14 @cents=433>, #<Money:0xb76b3f2c @cents=333>, #<Money:0xb76b3f04 @cents=333>]

All other operations (+, -, *, and Comparable stuff) will work without any surprises or magic. 

== Usage

Create your tables with fields named FIELDNAME_in_cents and you will be able to access them as
FIELDNAME. ActiveRecord will return Money objects instead of Fixnums.

  add_column :products, :price_in_cents, :integer
 
  product = Product.find_first
  product.price = 100.00
  product.price >> #<Money @cents=10000>


Creating a Money can be done from a Fixnum (dollars) or a Float (dollars.cents). To create a money
object from just cents, do Money.create_from_cents(100) 

== Feedback

Any suggestions, fixes, or improvements - lemme know, jerrett at gmail

rails_money's People

Contributors

also avatar jaggederest avatar kdonovan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.