nofxx-money 2.3.5 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.5
1
+ 2.3.6
data/lib/money/money.rb CHANGED
@@ -88,7 +88,7 @@ class Money
88
88
  # Money.ca_dollar and Money.us_dollar
89
89
  def initialize(cents, currency = nil, bank = nil)
90
90
  @cents = cents.to_i
91
- @currency = currency || Money.default_currency
91
+ @currency = (currency || Money.default_currency).upcase
92
92
  @bank = bank || Money.default_bank
93
93
  end
94
94
 
@@ -256,17 +256,20 @@ class Money
256
256
  symbol = ""
257
257
  end
258
258
  else
259
- symbol = CURRENCIES[currency][:symbol]
259
+ symbol = (CURRENCIES[currency] ? CURRENCIES[currency][:symbol] : "$")
260
260
  end
261
261
  self.currency
262
262
 
263
+ delimiter = (CURRENCIES[currency] ? CURRENCIES[currency][:delimiter] : "," )
264
+ separator = (CURRENCIES[currency] ? CURRENCIES[currency][:separator] : "." )
265
+
263
266
  if rules[:no_cents]
264
267
  formatted = sprintf("#{symbol}%d", cents.to_f / 100)
265
- formatted.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{CURRENCIES[currency][:delimiter]}")
268
+ formatted.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
266
269
  else
267
270
  formatted = sprintf("#{symbol}%.2f", cents.to_f / 100).split('.')
268
- formatted[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{CURRENCIES[currency][:delimiter]}")
269
- formatted = formatted.join(CURRENCIES[currency][:separator])
271
+ formatted[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
272
+ formatted = formatted.join(separator)
270
273
  end
271
274
 
272
275
  # Commify ("10000" => "10,000")
@@ -278,7 +281,7 @@ class Money
278
281
  formatted << currency
279
282
  formatted << '</span>' if rules[:html]
280
283
  end
281
- formatted.gsub!(CURRENCIES[currency][:symbol],CURRENCIES[currency][:html]) if rules[:html]
284
+ formatted.gsub!(symbol,CURRENCIES[currency][:html]) if rules[:html]
282
285
  formatted
283
286
  end
284
287
 
data/money.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{money}
5
- s.version = "2.3.5"
5
+ s.version = "2.3.6"
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"]
@@ -100,7 +100,7 @@ describe Money::ExchangeBank do
100
100
  end
101
101
 
102
102
  it "should fetch data" do
103
- Money.default_currency = "EUR"
103
+ Money.stub!(:default_currency).and_return("EUR")
104
104
  @bank.fetch_rates
105
105
  @bank.get_rate("DKK").should be_close(7.4453, 0.0001)
106
106
  @bank.get_rate("BRL").should be_close(2.832, 0.001)
@@ -108,7 +108,7 @@ describe Money::ExchangeBank do
108
108
  end
109
109
 
110
110
  it "should fetch diff than eur" do
111
- Money.default_currency = "BRL"
111
+ Money.stub!(:default_currency).and_return("BRL")
112
112
  @bank.fetch_rates
113
113
  @bank.get_rate("DKK").should be_close(2.6289, 0.0001)
114
114
  @bank.get_rate("EEK").should be_close(5.5249, 0.0001)
@@ -116,13 +116,12 @@ describe Money::ExchangeBank do
116
116
  end
117
117
 
118
118
  it "should fetch for an unknown one" do
119
- Money.default_currency = "XXX"
119
+ Money.stub!(:default_currency).and_return("XXX")
120
120
  @bank.fetch_rates
121
121
  @bank.get_rate("DKK").should be_nil
122
122
  @bank.get_rate("EUR", "USD").should be_close(1.4098, 0.001)
123
- Money.default_currency = "USD"
124
-
125
123
  end
124
+
126
125
  end
127
126
 
128
127
  describe "Live Fetching" do
@@ -158,9 +158,8 @@ describe Money do
158
158
  end
159
159
 
160
160
  it "Money.add_rate works" do
161
- Money.add_rate("USD", 1.0)
162
- Money.add_rate("EUR", 10)
163
- Money.new(10_00, "EUR").exchange_to("USD").should == Money.new(1_00, "USD")
161
+ Money.add_rate("BGL", 10)
162
+ Money.new(10_00, "USD").exchange_to("BGL").should == Money.new(100_00, "BGL")
164
163
  end
165
164
 
166
165
  it "Money method missing exchange" do
@@ -217,6 +216,7 @@ describe Money do
217
216
  it { Money.new(800000).format.should eql("$8,000.00") }
218
217
  it { Money.new(-8000000, "JPY").format(:no_cents => true).should eql("¥-80.000") }
219
218
  it { Money.new(87654321, "BRL").format.should eql("R$876.543,21") }
219
+ it { Money.new(87654321, "brl").format.should eql("R$876.543,21") }
220
220
  it { Money.new(800000000, "BRL").format.should eql("R$8.000.000,00") }
221
221
  it { Money.new(8000000000, "BRL").format.should eql("R$80.000.000,00") }
222
222
  it { Money.new(80000000000, "CAD").format.should eql("$800,000,000.00") }
@@ -224,9 +224,8 @@ describe Money do
224
224
  it { Money.new(8800000000088, "EUR").format.should eql("€88,000,000,000.88") }
225
225
 
226
226
  it "should fail nicely if symbol can`t be found" do
227
- Money.default_currency = "XXX"
227
+ Money.stub!(:default_currency).and_return("XXX")
228
228
  Money.new(800).format.should eql("$8.00")
229
- Money.default_currency = "USD"
230
229
  end
231
230
 
232
231
  describe "Actions involving two Money objects" 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.5
4
+ version: 2.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Money Team