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.
@@ -6,7 +6,7 @@ module CurrencyMagic
6
6
  methods.each do |method|
7
7
  class_eval <<-EOD
8
8
  def #{method}_#{currency}
9
- to_dollars self.#{method}
9
+ to_monetary_unit self.#{method}
10
10
  end
11
11
  def #{method}_#{currency}=(#{method})
12
12
  self.#{method} = to_cents(#{method})
@@ -18,19 +18,24 @@ module CurrencyMagic
18
18
  end
19
19
 
20
20
  private
21
- # Converts dollars to cents by multiplying by 100
21
+ # Converts a monetary unit to cents by multiplying by 100
22
22
  #
23
- # @param [Float] dollars the amount as dollars
23
+ # @param [Float] monetary_unit the amount as a whole monetary unit
24
24
  # @return [Integer] the amount as cents
25
- def to_cents(dollars)
26
- (currency_to_f(dollars) * 100).round
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 dollars by dividing by 100
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 dollars
33
- def to_dollars(an_int)
34
- an_int.to_f / 100
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: 27
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 0
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-20 00:00:00 Z
18
+ date: 2012-01-25 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
- description: Converts currency to/from cents
21
+ description: Converts monetary unit to/from cents
22
22
  email: jtanium@gmail.com
23
23
  executables: []
24
24