sevenwire-money 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,12 @@
1
1
  class MicroMoney < Money
2
2
 
3
3
  # Forces the :units => :millicents option.
4
- def initialize_with_millicents(money, *args)
4
+ def initialize(money, *args)
5
5
  options = args.last.is_a?(Hash) ? args.pop : {}
6
6
  options.merge!(:units => :millicents)
7
- initialize_without_millicents(money, *(args << options))
7
+ super(money, *(args << options))
8
8
  end
9
9
 
10
- alias :initialize_without_millicents :initialize
11
- alias :initialize :initialize_with_millicents
12
-
13
10
 
14
11
  ### OUTPUT/CONVERSIONS
15
12
 
@@ -150,7 +150,7 @@ class Money
150
150
  #
151
151
  # with_currency:
152
152
  #
153
- # Money.ca_dollar(0).format => "free"
153
+ # Money.ca_dollar(0).format => "$0.00"
154
154
  # Money.ca_dollar(100).format => "$1.00"
155
155
  # Money.ca_dollar(100).format(:with_currency) => "$1.00 CAD"
156
156
  # Money.us_dollar(85).format(:with_currency) => "$0.85 USD"
@@ -166,10 +166,20 @@ class Money
166
166
  # html:
167
167
  #
168
168
  # Money.ca_dollar(570).format(:html, :with_currency) => "$5.70 <span class=\"currency\">CAD</span>"
169
+ #
170
+ # fractional:
171
+ #
172
+ # MicroMoney.new(500).format(:tenths) => "$0.005"
169
173
  def format(*rules)
170
174
  rules = rules.flatten
171
175
 
172
- if rules.include?(:no_cents)
176
+ if rules.include?(:tenths)
177
+ formatted = sprintf("$%.3f", millicents.to_f / 100000)
178
+ elsif rules.include?(:hundredths)
179
+ formatted = sprintf("$%.4f", millicents.to_f / 100000)
180
+ elsif rules.include?(:thousandths)
181
+ formatted = sprintf("$%.5f", millicents.to_f / 100000)
182
+ elsif rules.include?(:no_cents)
173
183
  formatted = sprintf("$%d", cents.to_f / 100)
174
184
  else
175
185
  formatted = sprintf("$%.2f", cents.to_f / 100)
@@ -187,8 +197,19 @@ class Money
187
197
  # Output a money object as a string.
188
198
  # Example:
189
199
  # Money.new(100).to_s => "1.00"
190
- def to_s
191
- sprintf("%.2f", cents.to_f / 100)
200
+ def to_s(precision)
201
+ case precision
202
+ when :tenths
203
+ sprintf("%.3f", millicents.to_f / 100000)
204
+ when :hundredths
205
+ sprintf("%.4f", millicents.to_f / 100000)
206
+ when :thousandths
207
+ sprintf("%.5f", millicents.to_f / 100000)
208
+ when :no_cents
209
+ sprintf("%d", cents.to_f / 100)
210
+ else
211
+ sprintf("%.2f", cents.to_f / 100)
212
+ end
192
213
  end
193
214
 
194
215
  # Converts to a float value.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "money"
3
- s.version = "2.3.3"
3
+ s.version = "2.3.4"
4
4
  s.summary = "Money and MicroMoney with currency exchange support library"
5
5
  s.email = "brandon@sevenwire.com"
6
6
  s.homepage = "http://github.com/sevenwire/money"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevenwire-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke