sevenwire-money 2.1.1 → 2.2.0

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.
@@ -0,0 +1,26 @@
1
+ class MicroMoney < Money
2
+
3
+ # Forces the :units => :millicents option.
4
+ def initialize_with_millicents(money, *args)
5
+ options = args.last.is_a?(Hash) ? args.pop : {}
6
+ options.merge!(:units => :millicents)
7
+ initialize_without_millicents(money, *(args << options))
8
+ end
9
+
10
+ alias :initialize_without_millicents :initialize
11
+ alias :initialize :initialize_with_millicents
12
+
13
+
14
+ ### OUTPUT/CONVERSIONS
15
+
16
+ # Conversion to MicroMoney.
17
+ def to_micro_money
18
+ self
19
+ end
20
+
21
+ # Conversion to Money.
22
+ def to_money
23
+ Money.new(millicents, currency, bank, :units => :millicents)
24
+ end
25
+
26
+ end
data/lib/money/money.rb CHANGED
@@ -83,7 +83,7 @@ class Money
83
83
 
84
84
  # Recieve the amount of this money object in another currency.
85
85
  def exchange_to(other_currency)
86
- self.class.new(@bank.exchange(millicents, currency, other_currency), other_currency, :units => :millicents)
86
+ MicroMoney.new(@bank.exchange(millicents, currency, other_currency), other_currency).to_money
87
87
  end
88
88
 
89
89
 
@@ -109,29 +109,29 @@ class Money
109
109
  # Add two money objects.
110
110
  def +(other_money)
111
111
  if currency == other_money.currency
112
- self.class.new(millicents + other_money.millicents, other_money.currency, :units => :millicents)
112
+ MicroMoney.new(millicents + other_money.millicents, other_money.currency).to_money
113
113
  else
114
- self.class.new(millicents + other_money.exchange_to(currency).millicents, currency, :units => :millicents)
114
+ MicroMoney.new(millicents + other_money.exchange_to(currency).millicents, currency).to_money
115
115
  end
116
116
  end
117
117
 
118
118
  # Subtract two money objects.
119
119
  def -(other_money)
120
120
  if currency == other_money.currency
121
- self.class.new(millicents - other_money.millicents, other_money.currency, :units => :millicents)
121
+ MicroMoney.new(millicents - other_money.millicents, other_money.currency).to_money
122
122
  else
123
- self.class.new(millicents - other_money.exchange_to(currency).millicents, currency, :units => :millicents)
123
+ MicroMoney.new(millicents - other_money.exchange_to(currency).millicents, currency).to_money
124
124
  end
125
125
  end
126
126
 
127
127
  # Multiply money by fixnum.
128
128
  def *(fixnum)
129
- self.class.new(millicents * fixnum, currency, :units => :millicents)
129
+ MicroMoney.new(millicents * fixnum, currency).to_money
130
130
  end
131
131
 
132
132
  # Divide money by fixnum.
133
133
  def /(fixnum)
134
- self.class.new(millicents / fixnum, currency, :units => :millicents)
134
+ MicroMoney.new(millicents / fixnum, currency, :units => :millicents).to_money
135
135
  end
136
136
 
137
137
  # Test if the money amount is zero.
@@ -188,9 +188,19 @@ class Money
188
188
  sprintf("%.2f", cents.to_f / 100)
189
189
  end
190
190
 
191
- # Conversation to self
191
+ # Converts to a float value.
192
+ def to_f
193
+ to_s.to_f
194
+ end
195
+
196
+ # Conversation to Money.
192
197
  def to_money
193
198
  self
194
199
  end
195
200
 
201
+ # Conversion to MicroMoney.
202
+ def to_micro_money
203
+ MicroMoney.new(millicents, currency, bank)
204
+ end
205
+
196
206
  end
data/lib/money.rb CHANGED
@@ -4,3 +4,4 @@ require 'money/currencies'
4
4
  require 'money/errors'
5
5
  require 'money/core_extensions'
6
6
  require 'money/money'
7
+ require 'money/micro_money'
data/money.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "money"
3
- s.version = "2.1.1"
4
- s.summary = "Money and currency exchange support library"
3
+ s.version = "2.2.0"
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"
7
- s.description = "Money and currency exchange support library."
7
+ s.description = "Money and MicroMoney with currency exchange support library."
8
8
  s.has_rdoc = true
9
9
  s.rubyforge_project = "money"
10
10
  s.authors = ["Tobias Luetke", "Hongli Lai", "Brandon Arbini"]
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  "lib/money/core_extensions.rb",
16
16
  "lib/money/currencies.rb",
17
17
  "lib/money/errors.rb",
18
+ "lib/money/micro_money.rb",
18
19
  "lib/money/money.rb",
19
20
  "lib/money/variable_exchange_bank.rb",
20
21
  "test/core_extensions_spec.rb",
data/test/money_spec.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
2
2
  require 'money/money'
3
+ require 'money/micro_money'
3
4
  require 'money/currencies'
4
5
 
5
6
  describe Money do
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.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -15,7 +15,7 @@ date: 2008-12-22 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
18
- description: Money and currency exchange support library.
18
+ description: Money and MicroMoney with currency exchange support library.
19
19
  email: brandon@sevenwire.com
20
20
  executables: []
21
21
 
@@ -32,6 +32,7 @@ files:
32
32
  - lib/money/core_extensions.rb
33
33
  - lib/money/currencies.rb
34
34
  - lib/money/errors.rb
35
+ - lib/money/micro_money.rb
35
36
  - lib/money/money.rb
36
37
  - lib/money/variable_exchange_bank.rb
37
38
  - test/core_extensions_spec.rb
@@ -62,6 +63,6 @@ rubyforge_project: money
62
63
  rubygems_version: 1.2.0
63
64
  signing_key:
64
65
  specification_version: 2
65
- summary: Money and currency exchange support library
66
+ summary: Money and MicroMoney with currency exchange support library
66
67
  test_files: []
67
68