currency_magic 0.1.0 → 0.2.1
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/currency_magic/class_methods.rb +1 -1
- data/lib/currency_magic.rb +13 -8
- metadata +5 -5
data/lib/currency_magic.rb
CHANGED
@@ -18,19 +18,24 @@ module CurrencyMagic
|
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
|
-
# Converts
|
21
|
+
# Converts a monetary unit to cents by multiplying by 100
|
22
22
|
#
|
23
|
-
# @param [Float]
|
23
|
+
# @param [Float] monetary_unit the amount as a whole monetary unit
|
24
24
|
# @return [Integer] the amount as cents
|
25
|
-
def to_cents(
|
26
|
-
|
25
|
+
def to_cents(monetary_unit)
|
26
|
+
f = currency_to_f(monetary_unit)
|
27
|
+
return nil if f.nil?
|
28
|
+
|
29
|
+
(f * 100).round
|
27
30
|
end
|
28
31
|
|
29
|
-
# Converts cents to
|
32
|
+
# Converts cents to a monetary unit by dividing by 100
|
30
33
|
#
|
31
34
|
# @param [Integer] cents the amount as cents
|
32
|
-
# @return [Float] the amount as
|
33
|
-
def
|
34
|
-
|
35
|
+
# @return [Float] the amount as a monetary unit
|
36
|
+
def to_monetary_unit(cents)
|
37
|
+
return nil if cents.nil?
|
38
|
+
|
39
|
+
cents.to_f / 100
|
35
40
|
end
|
36
41
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 2
|
8
9
|
- 1
|
9
|
-
|
10
|
-
version: 0.1.0
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Edwards
|
@@ -15,10 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-25 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description: Converts
|
21
|
+
description: Converts monetary unit to/from cents
|
22
22
|
email: jtanium@gmail.com
|
23
23
|
executables: []
|
24
24
|
|