money 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/money/money.rb CHANGED
@@ -157,7 +157,10 @@ class Money
157
157
  # html:
158
158
  #
159
159
  # Money.ca_dollar(570).format(:html => true, :with_currency => true) => "$5.70 <span class=\"currency\">CAD</span>"
160
- def format(rules = {})
160
+ def format(*rules)
161
+ # support for old format parameters
162
+ rules = normalize_formatting_rules(rules)
163
+
161
164
  if cents == 0
162
165
  if rules[:display_free].respond_to?(:to_str)
163
166
  return rules[:display_free]
@@ -218,4 +221,19 @@ class Money
218
221
  def to_money
219
222
  self
220
223
  end
224
+
225
+ private
226
+
227
+ def normalize_formatting_rules(rules)
228
+ if rules.size == 1
229
+ rules = rules.pop
230
+ rules = { rules => true } if rules.is_a?(Symbol)
231
+ else
232
+ rules = rules.inject({}) do |h,s|
233
+ h[s] = true
234
+ h
235
+ end
236
+ end
237
+ rules
238
+ end
221
239
  end
data/money.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "money"
3
- s.version = "2.1.0"
3
+ s.version = "2.1.1"
4
4
  s.summary = "Money and currency exchange support library"
5
5
  s.email = "hongli@phusion.nl"
6
6
  s.homepage = "http://money.rubyforge.org/"
data/test/money_spec.rb CHANGED
@@ -105,6 +105,12 @@ describe Money do
105
105
  specify "#format(:with_currency => true) works as documented" do
106
106
  Money.ca_dollar(100).format(:with_currency => true).should == "$1.00 CAD"
107
107
  Money.us_dollar(85).format(:with_currency => true).should == "$0.85 USD"
108
+ Money.us_dollar(85).format(:with_currency).should == "$0.85 USD"
109
+ end
110
+
111
+ specify "#format(:with_currency) works as documented" do
112
+ Money.ca_dollar(100).format(:with_currency).should == "$1.00 CAD"
113
+ Money.us_dollar(85).format(:with_currency).should == "$0.85 USD"
108
114
  end
109
115
 
110
116
  specify "#format(:no_cents => true) works as documented" do
@@ -113,6 +119,13 @@ describe Money do
113
119
  Money.ca_dollar(570).format(:no_cents => true, :with_currency => true).should == "$5 CAD"
114
120
  Money.ca_dollar(39000).format(:no_cents => true).should == "$390"
115
121
  end
122
+
123
+ specify "#format(:no_cents) works as documented" do
124
+ Money.ca_dollar(100).format(:no_cents).should == "$1"
125
+ Money.ca_dollar(599).format(:no_cents).should == "$5"
126
+ Money.ca_dollar(570).format(:no_cents, :with_currency).should == "$5 CAD"
127
+ Money.ca_dollar(39000).format(:no_cents).should == "$390"
128
+ end
116
129
 
117
130
  specify "#format(:symbol => ...) works as documented" do
118
131
  Money.new(100, :currency => "GBP").format(:symbol => "£").should == "£1.00"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-02-15 00:00:00 +01:00
14
+ date: 2009-02-19 00:00:00 +01:00
15
15
  default_executable:
16
16
  dependencies: []
17
17