This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
brazilian-rails / brdinheiro
| name | age | message | |
|---|---|---|---|
| .. | |||
| |
CHANGELOG | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
| |
MIT-LICENSE | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
| |
README | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
| |
Rakefile | Sun Aug 31 18:45:55 -0700 2008 | [tapajos] |
| |
lib/ | Wed Sep 24 04:33:37 -0700 2008 | [tapajos] |
| |
rails/ | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
| |
samples/ | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
| |
test/ | Sun Aug 31 16:23:41 -0700 2008 | [tapajos] |
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





