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.
- data/lib/money/micro_money.rb +2 -5
- data/lib/money/money.rb +25 -4
- data/money.gemspec +1 -1
- metadata +1 -1
data/lib/money/micro_money.rb
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
class MicroMoney < Money
|
|
2
2
|
|
|
3
3
|
# Forces the :units => :millicents option.
|
|
4
|
-
def
|
|
4
|
+
def initialize(money, *args)
|
|
5
5
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
6
6
|
options.merge!(:units => :millicents)
|
|
7
|
-
|
|
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
|
|
data/lib/money/money.rb
CHANGED
|
@@ -150,7 +150,7 @@ class Money
|
|
|
150
150
|
#
|
|
151
151
|
# with_currency:
|
|
152
152
|
#
|
|
153
|
-
# Money.ca_dollar(0).format => "
|
|
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?(:
|
|
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
|
-
|
|
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.
|
data/money.gemspec
CHANGED