bd_money 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
data/bd_money.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bd_money}
8
- s.version = "0.0.10"
8
+ s.version = "0.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adrian Madrid"]
12
- s.date = %q{2012-03-22}
12
+ s.date = %q{2012-03-26}
13
13
  s.description = %q{This library makes it easier to deal with Money values, storing them as BigDecimal to avoid floating-point math errors.}
14
14
  s.email = %q{aemadrid@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -178,8 +178,9 @@ class Money
178
178
 
179
179
  def to_s(this_precision = precision, this_round_mode = round_mode)
180
180
  amount_str = round_amount(this_precision, this_round_mode).to_s('F')
181
+ return amount_str if amount_str == "NaN"
181
182
  dollars, cents = amount_str.split('.')
182
- return dollars if this_precision == 0
183
+ return dollars if this_precision == 0 || cents.nil?
183
184
  if cents.size >= this_precision
184
185
  "#{dollars}.#{cents[0, this_precision]}"
185
186
  else
@@ -203,6 +204,7 @@ class Money
203
204
  last = options[:last] || defaults[:last]
204
205
 
205
206
  number = to_s precision
207
+ return number if number == 'NaN'
206
208
  begin
207
209
  parts = number.to_s.split('.')
208
210
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
@@ -7,6 +7,7 @@ describe Money do
7
7
  let(:other_amt) { 1.01 }
8
8
  subject { Money.new amt, 2, :half_down }
9
9
  let(:neg_subject) { Money.new neg_amt, 2, :half_down }
10
+ let(:nan_subject) { Money.new(0) / 0 }
10
11
 
11
12
  describe "class precision" do
12
13
  it { Money.precision.should == 2 }
@@ -295,6 +296,9 @@ describe Money do
295
296
  it { subject.to_s(5).should == amt[0, 7] }
296
297
  it { subject.to_s(6).should == amt }
297
298
  end
299
+ describe "not a number" do
300
+ it { nan_subject.to_s.should == "NaN" }
301
+ end
298
302
  end
299
303
 
300
304
  describe "to_big_decimal" do
@@ -309,6 +313,7 @@ describe Money do
309
313
  describe "format" do
310
314
  let(:amt) { '1234567.12' }
311
315
  let(:neg_amt) { '-1234567.12' }
316
+ let(:nan) { Money.new(0) / 0 }
312
317
  it { subject.formatted().should == '$ 1,234,567.12' }
313
318
  it { subject.formatted(:no_cents).should == '$ 1,234,567' }
314
319
  it { subject.formatted(:no_commas).should == '$ 1234567.12' }
@@ -323,6 +328,9 @@ describe Money do
323
328
  it { neg_subject.formatted(:no_commas, :precision => 1).should == '$ -1234567.1' }
324
329
  it { neg_subject.formatted(:general, :last => '%').should == '-1234567.12%' }
325
330
  it { neg_subject.formatted(:general, :spacer => " ", :last => '%').should == '-1234567.12%' }
331
+ it { nan_subject.formatted().should == 'NaN' }
332
+ it { nan_subject.formatted(:no_cents).should == 'NaN' }
333
+ it { nan_subject.formatted(:no_commas, :precision => 1).should == 'NaN' }
326
334
  end
327
335
 
328
336
  describe "forwarded" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bd_money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adrian Madrid
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-22 00:00:00 -06:00
18
+ date: 2012-03-26 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency