Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
lib
rails
samples/dinheiro
test
CHANGELOG
MIT-LICENSE
README
Rakefile

README

 == Como usar o Dinheiro em seu ActiveRecord?

 * Arquivo 001_create_lancamentos.rb:

     class CreateLancamentos < ActiveRecord::Migration
       def self.up
         create_table :lancamentos do |t|
           t.column :descricao,   :string,    :null => false
           t.column :valor,       :decimal,   :precision => 14, :scale => 2
           t.column :mensalidade, :decimal,   :precision => 14, :scale => 2
         end
       end

       def self.down
         drop_table :lancamentos
       end
     end

 * Arquivo lancamento.rb:

     class Lancamento < ActiveRecord::Base
       usar_como_dinheiro :valor, :mensalidade
     end

 * No console (script/console):

     Loading development environment.
     >> lancamento = Lancamento.new
     => #<Lancamento:0x9652cd8 @attributes={"descricao"=>nil,
                                            "valor"=>#<BigDecimal:9657008,'0.0',4(4)>,
                                            "mensalidade"=>#<BigDecimal:9656e8c,'0.0',4(4)>},
                               @new_record=true>
     >> lancamento.valor = 100
     => 100
     >> lancamento.valor
     => #<Dinheiro:0x9650f3c @quantia=10000>
     >> lancamento.valor.real
     => "R$ 100,00"
     >> lancamento.valor = 100.50
     => 100.5
     >> lancamento.valor.real
     => "R$ 100,50"
     >> lancamento.valor = "250.50"
     => "250.50"
     >> lancamento.valor.real
     => "R$ 250,50"
     >> lancamento.valor = 354.58.reais
     => #<Dinheiro:0x9646384 @quantia=35458>
     >> lancamento.valor.real
     => "R$ 354,58"
     >> exit

Something went wrong with that request. Please try again.