nofxx-money 2.3.10 → 2.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -81,6 +81,11 @@ www.xe.com for the current rates or just returns <tt>rand(2)</tt>:
81
81
 
82
82
  Money.default_bank = ExchangeBankWhichScrapesXeDotCom.new
83
83
 
84
+ === `new` or `to_money` ?
85
+
86
+ If you already have a value in integer/float or a string which ruby can parse
87
+ with `to_i`, use new. It'll avoid the string parser, which is resource intensive.
88
+
84
89
 
85
90
  === Default Currency
86
91
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.9
1
+ 2.3.11
data/lib/money/money.rb CHANGED
@@ -41,6 +41,7 @@ class Money
41
41
  self.default_bank = ExchangeBank.instance
42
42
  self.default_currency = "USD"
43
43
 
44
+ # http://www.xe.com/symbols.php
44
45
  CURRENCIES = {
45
46
  "USD" => { :delimiter => ",", :separator => ".", :symbol => "$" },
46
47
  "CAD" => { :delimiter => ",", :separator => ".", :symbol => "$" },
@@ -126,6 +127,10 @@ class Money
126
127
  end
127
128
  end
128
129
 
130
+ def -@
131
+ Money.new(-cents)
132
+ end
133
+
129
134
  # multiply money by fixnum
130
135
  def *(fixnum)
131
136
  Money.new(cents * fixnum, currency)
@@ -215,31 +220,36 @@ class Money
215
220
  end
216
221
 
217
222
  # Format the price according to several rules
218
- # Currently supported are :with_currency, :no_cents, :symbol and :html
223
+ # Currently supported are :with_currency, :no_cents, :symbol and :html.
219
224
  #
220
- # with_currency:
225
+ # === +:with_currency+
221
226
  #
222
- # Money.ca_dollar(0).format => "free"
223
227
  # Money.ca_dollar(100).format => "$1.00"
224
228
  # Money.ca_dollar(100).format(:with_currency => true) => "$1.00 CAD"
225
229
  # Money.us_dollar(85).format(:with_currency => true) => "$0.85 USD"
226
230
  #
227
- # no_cents:
231
+ # === +:no_cents+
228
232
  #
229
233
  # Money.ca_dollar(100).format(:no_cents) => "$1"
230
234
  # Money.ca_dollar(599).format(:no_cents) => "$5"
231
- #
232
235
  # Money.ca_dollar(570).format(:no_cents, :with_currency) => "$5 CAD"
233
236
  # Money.ca_dollar(39000).format(:no_cents) => "$390"
234
237
  #
235
- # symbol:
238
+ # === +:symbol+
236
239
  #
237
240
  # Money.new(100, :currency => "GBP").format(:symbol => "£") => "£1.00"
241
+ # Money.new(100, :currency => "GBP").format(:symbol => "UU") => "UU1.00"
242
+ #
243
+ # === +:display_free+
244
+ #
245
+ # Money.ca_dollar(0).format => "free"
246
+ # Money.real(0).format(:display_free => "Gratis") => "Gratis"
238
247
  #
239
- # html:
248
+ # === +:html+
240
249
  #
241
250
  # Money.ca_dollar(570).format(:html => true, :with_currency => true) => "$5.70 <span class=\"currency\">CAD</span>"
242
- def format(*rules)
251
+ #
252
+ def format(*rules)
243
253
  # support for old format parameters
244
254
  rules = normalize_formatting_rules(rules)
245
255
 
@@ -251,19 +261,10 @@ class Money
251
261
  end
252
262
  end
253
263
 
254
- if rules.has_key?(:symbol)
255
- if rules[:symbol]
256
- symbol = rules[:symbol]
257
- else
258
- symbol = "$"
259
- end
260
- else
261
- symbol = (CURRENCIES[currency] ? CURRENCIES[currency][:symbol] : "$")
262
- end
263
- self.currency
264
-
265
- delimiter = (CURRENCIES[currency] ? CURRENCIES[currency][:delimiter] : "," )
266
- separator = (CURRENCIES[currency] ? CURRENCIES[currency][:separator] : "." )
264
+ curr = CURRENCIES[currency]
265
+ symbol = rules.has_key?(:symbol) ? (rules[:symbol] || "") : (curr ? curr[:symbol] : "$")
266
+ delimiter = (curr ? curr[:delimiter] : "," )
267
+ separator = (curr ? curr[:separator] : "." )
267
268
 
268
269
  if rules[:no_cents]
269
270
  formatted = sprintf("#{symbol}%d", cents.to_f / 100)
@@ -283,11 +284,11 @@ class Money
283
284
  formatted << currency
284
285
  formatted << '</span>' if rules[:html]
285
286
  end
286
- formatted.gsub!(symbol,CURRENCIES[currency][:html]) if rules[:html]
287
+ formatted.gsub!(symbol,curr[:html]) if rules[:html]
287
288
  formatted
288
- end
289
+ end
289
290
 
290
- def normalize_formatting_rules(rules)
291
+ def normalize_formatting_rules(rules)
291
292
  if rules.size == 1
292
293
  rules = rules.pop
293
294
  rules = { rules => true } if rules.is_a?(Symbol)
data/money.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{money}
5
- s.version = "2.3.10"
8
+ s.version = "2.3.11"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Money Team"]
9
- s.date = %q{2009-06-20}
12
+ s.date = %q{2009-08-18}
10
13
  s.description = %q{This library aids one in handling money and different currencies.}
11
14
  s.email = %q{see@reame}
12
15
  s.extra_rdoc_files = [
@@ -41,7 +44,7 @@ Gem::Specification.new do |s|
41
44
  s.homepage = %q{http://github.com/nofxx/money}
42
45
  s.rdoc_options = ["--charset=UTF-8"]
43
46
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.4}
47
+ s.rubygems_version = %q{1.3.5}
45
48
  s.summary = %q{This library aids one in handling money and different currencies.}
46
49
  s.test_files = [
47
50
  "spec/db/schema.rb",
@@ -214,6 +214,9 @@ describe Money do
214
214
  it { @cash.format(:symbol => "R$ ").should eql("R$ 2.00") }
215
215
  it { @cash.format(:no_cents => true).should eql("¥2") }
216
216
  it { @cash.format(:no_cents => true, :symbol => "R$ ").should eql("R$ 2") }
217
+ it { @cash.format(:symbol => false).should eql("2.00") }
218
+ it { @cash.format(:symbol => nil).should eql("2.00") }
219
+ it { @cash.format(:symbol => "").should eql("2.00") }
217
220
  it { @cash.format(:html => true).should eql("&yen;2.00") }
218
221
  end
219
222
 
@@ -260,6 +263,14 @@ describe Money do
260
263
  it "#- substracts the other object's amount from the current object's amount while retaining the currency" do
261
264
  (Money.new(10_00, "USD") - Money.new(90, "USD")).should == Money.new(9_10, "USD")
262
265
  end
266
+
267
+ it "should return to -@ method" do
268
+ (-(Money.new(5))).cents.should eql(-5)
269
+ end
270
+
271
+ it "should return to -@ method" do
272
+ (-(Money.new(-5))).cents.should eql(5)
273
+ end
263
274
  end
264
275
 
265
276
  describe "if the other Money object has a different currency" do
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ config = YAML.load_file(File.dirname(__FILE__) + '/db/database.yml')
15
15
  ActiveRecord::Base.logger = Logger.new("/tmp/money-debug.log")
16
16
  ActiveRecord::Base.establish_connection(config)
17
17
 
18
- db_file = File.exists?(File.dirname(__FILE__) + '/../tmp/acts_as_money.sqlite3')
19
- load(File.dirname(__FILE__) + "/db/schema.rb") unless db_file
18
+ unless File.exists?(File.dirname(__FILE__) + '/../tmp/acts_as_money.sqlite3')
19
+ load(File.dirname(__FILE__) + "/db/schema.rb")
20
+ end
20
21
 
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.10
4
+ version: 2.3.11
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-06-20 00:00:00 -07:00
12
+ date: 2009-08-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15