nofxx-money 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/money/money.rb CHANGED
@@ -28,6 +28,9 @@ class Money
28
28
  attr_accessor :default_currency
29
29
  end
30
30
 
31
+ self.default_bank = VariableExchangeBank.instance
32
+ self.default_currency = "USD"
33
+
31
34
  CURRENCIES = {
32
35
  "USD" => { :delimiter => ",", :separator => ".", :symbol => "$" },
33
36
  "CAD" => { :delimiter => ",", :separator => ".", :symbol => "$" },
@@ -38,9 +41,6 @@ class Money
38
41
  "GBP" => { :delimiter => ",", :separator => ".", :symbol => '£', :html => '£' },
39
42
  "JPY" => { :delimiter => ".", :separator => ".", :symbol => '¥', :html => '¥' },
40
43
  }
41
- self.default_bank = VariableExchangeBank.instance
42
- self.default_currency = "USD"
43
-
44
44
 
45
45
  # Create a new money object with value 0.
46
46
  def self.empty(currency = default_currency)
@@ -76,10 +76,10 @@ class Money
76
76
  #
77
77
  # Alternativly you can use the convinience methods like
78
78
  # Money.ca_dollar and Money.us_dollar
79
- def initialize(cents, currency = Money.default_currency, bank = Money.default_bank)
79
+ def initialize(cents, currency = nil, bank = nil)
80
80
  @cents = cents.to_i
81
- @currency = currency || default_currency
82
- @bank = bank
81
+ @currency = currency || Money.default_currency
82
+ @bank = bank || Money.default_bank
83
83
  end
84
84
 
85
85
  # Do two money objects equal? Only works if both objects are of the same currency
@@ -96,6 +96,7 @@ class Money
96
96
  end
97
97
 
98
98
  def +(other_money)
99
+ other_money = Money.new(other_money) unless other_money.is_a? Money
99
100
  if currency == other_money.currency
100
101
  Money.new(cents + other_money.cents, other_money.currency)
101
102
  else
@@ -104,6 +105,7 @@ class Money
104
105
  end
105
106
 
106
107
  def -(other_money)
108
+ other_money = Money.new(other_money) unless other_money.is_a? Money
107
109
  if currency == other_money.currency
108
110
  Money.new(cents - other_money.cents, other_money.currency)
109
111
  else
@@ -138,13 +140,13 @@ class Money
138
140
 
139
141
  # Calculates compound interest
140
142
  # Returns a money object with the sum of self + it
141
- def compound_interest(rate,count=1)
142
- Money.new(cents * ((1 + rate / 100.0 / 12) ** count - 1))
143
+ def compound_interest(rate, count = 1, period = 12)
144
+ Money.new(cents * ((1 + rate / 100.0 / period) ** count - 1))
143
145
  end
144
146
 
145
147
  # Calculate self + simple interest
146
- def simple_interest(rate,count=1)
147
- Money.new(rate/100/12*cents*count)
148
+ def simple_interest(rate, count = 1, period = 12)
149
+ Money.new(rate / 100 / period * cents * count)
148
150
  end
149
151
 
150
152
  # Split money in number of installments
@@ -152,10 +154,11 @@ class Money
152
154
  # Money.new(10_00).split_in_installments(3)
153
155
  # => [ 3.34, 3.33, 3.33 ] (All Money instances)
154
156
  #
155
- def split_in_installments(fixnum,extra=nil,*opts)
157
+ def split_in_installments(fixnum, order=false)
156
158
  wallet = Wallet.new(fixnum, Money.new(cents/fixnum,currency))
157
159
  to_add = cents % fixnum
158
160
  to_add.times { |m| wallet[m] += Money.new(1) }
161
+ wallet.reverse! if order
159
162
  wallet
160
163
  end
161
164
 
@@ -164,8 +167,8 @@ class Money
164
167
  # Money.new(1000_00).split_in_installments(Money.new(300_00))
165
168
  # => [ 334_00, 333_00, 333_00 ] (All Money instances)
166
169
  #
167
- def in_installments_of(other_money,first=false)
168
- split_in_installments(cents/other_money.cents,first)
170
+ def in_installments_of(other_money, order=false)
171
+ split_in_installments(cents/other_money.cents, order)
169
172
  end
170
173
 
171
174
  # Just a helper if you got tax inputs in percentage.
data/lib/money.rb CHANGED
@@ -25,5 +25,5 @@ require 'money/money'
25
25
  require 'money/core_extensions'
26
26
 
27
27
  class Money
28
- VERSION = "2.3.2"
28
+ VERSION = "2.3.3"
29
29
  end
data/money.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{money}
5
- s.version = "2.3.2"
5
+ s.version = "2.3.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Money Team"]
9
- s.date = %q{2009-03-22}
9
+ s.date = %q{2009-03-24}
10
10
  s.description = %q{This library aids one in handling money and different currencies.}
11
11
  s.email = ["see@readme"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
@@ -42,21 +42,29 @@ describe Money do
42
42
  money.exchange_to("EUR")
43
43
  end
44
44
 
45
- it "#exchange_to exchanges the amount properly" do
45
+ it "should exchange_to exchanges the amount properly" do
46
46
  money = Money.new(100_00, "USD")
47
47
  money.bank.should_receive(:exchange).with(100_00, "USD", "EUR").and_return(200_00)
48
48
  money.exchange_to("EUR").should == Money.new(200_00, "EUR")
49
49
  end
50
50
 
51
- it "#== returns true if and only if their amount and currency are equal" do
51
+ it "should returns true if and only if their amount and currency are equal" do
52
52
  Money.new(1_00, "USD").should == Money.new(1_00, "USD")
53
53
  end
54
54
 
55
- it "#* multiplies the money's amount by the multiplier while retaining the currency" do
55
+ it "should add retaining the currency" do
56
+ (Money.new(1_00, "USD") + 10).should == Money.new(1_10, "USD")
57
+ end
58
+
59
+ it "should substract retaining the currency" do
60
+ (Money.new(1_00, "USD") - 10).should == Money.new(90, "USD")
61
+ end
62
+
63
+ it "should multiply while retaining the currency" do
56
64
  (Money.new(1_00, "USD") * 10).should == Money.new(10_00, "USD")
57
65
  end
58
66
 
59
- it "#* divides the money's amount by the divisor while retaining the currency" do
67
+ it "should divides while retaining the currency" do
60
68
  (Money.new(10_00, "USD") / 10).should == Money.new(1_00, "USD")
61
69
  end
62
70
 
@@ -80,19 +88,18 @@ describe Money do
80
88
  Money.real(50).should == Money.new(50, "BRL")
81
89
  end
82
90
 
83
-
84
91
  describe "Installments" do
85
92
 
86
- it "# divides the money ammout in installments add last" do
93
+ it "# divides the money ammout in installments add first" do
87
94
  @money = Money.new(10_00).split_in_installments(3)
88
95
  @money[0].cents.should eql(334)
89
96
  @money[1].cents.should eql(333)
90
97
  @money[2].cents.should eql(333)
91
98
  end
92
99
 
93
- it "# divides the money ammout in installments add first" do
100
+ it "# divides the money ammout in installments add last" do
94
101
  @money = Money.new(10_00).split_in_installments(3,true)
95
- @money.to_s.should eql(["3.34", "3.33", "3.33"])
102
+ @money.to_s.should eql(["3.33", "3.33", "3.34"])
96
103
  end
97
104
 
98
105
  it "# divides the money ammout in installments base on payment" do
@@ -111,6 +118,11 @@ describe Money do
111
118
  Money.new(100).add_tax(-20).cents.should eql(80)
112
119
  end
113
120
 
121
+ it "shuld to_s wallet" do
122
+ @money = Money.new(10_00)
123
+ @money.split_in_installments(3).to_s.should eql(["3.34", "3.33", "3.33"])
124
+ end
125
+
114
126
  it "shuld sum array" do
115
127
  @money = Money.new(10_00).add_tax(10)
116
128
  @money.split_in_installments(3).sum.cents.should eql(1100)
@@ -145,6 +157,11 @@ describe Money do
145
157
  m.compound_interest(12.99,3).to_s.should eql("82.06")
146
158
  end
147
159
 
160
+ it "should calculate compound interest" do
161
+ m = Money.new(2500_00)
162
+ m.compound_interest(12.99,3,6).to_s.should eql("165.91")
163
+ end
164
+
148
165
  end
149
166
 
150
167
  describe "Format out " do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nofxx-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Money Team
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -07:00
12
+ date: 2009-03-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency