money 3.1.0.pre1 → 3.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == Money 3.1.0.pre2
2
+ * moved @rounding_method from Money::Bank::VariableExchange to
3
+ Money::Bank::Base (closes #18)
4
+ * added #setup and call after #initialize in Money::Bank::Base (closes #19)
5
+ * update/fix documentation (closes #17)
6
+
1
7
  == Money 3.1.0.pre1
2
8
  * Implemented Money::Bank::Base (closes #14)
3
9
  * Added Bank::Base#exchange_with
data/README.rdoc CHANGED
@@ -51,9 +51,21 @@ The development version (hosted on Github) can be installed with:
51
51
  money.cents # => 1000
52
52
  money.currency # => Currency.new("USD")
53
53
 
54
+ # Comparisons
54
55
  Money.new(1000, "USD") == Money.new(1000, "USD") # => true
55
56
  Money.new(1000, "USD") == Money.new(100, "USD") # => false
56
57
  Money.new(1000, "USD") == Money.new(1000, "EUR") # => false
58
+ Money.new(1000, "USD") != Money.new(1000, "EUR") # => true
59
+
60
+ # Arithmetic
61
+ Money.new(1000, "USD") + Money.new(500, "USD") == Money.new(1500, "USD")
62
+ Money.new(1000, "USD") - Money.new(200, "USD") == Money.new(800, "USD")
63
+ Money.new(1000, "USD") / 5 == Money.new(200, "USD")
64
+ Money.new(1000, "USD") * 5 == Money.new(5000, "USD")
65
+
66
+ # Currency conversions
67
+ some_code_to_setup_exchange_rates
68
+ Money.new(1000, "USD").exchange_to("EUR") == Money.new(some_value, "EUR")
57
69
 
58
70
  === Currency
59
71
 
@@ -66,7 +78,7 @@ The most part of <tt>Money</tt> APIs allows you to supply either a <tt>String</t
66
78
  A <tt>Money::Currency</tt> instance holds all the information about the currency,
67
79
  including the currency symbol, name and much more.
68
80
 
69
- currency = Money.new(1000, "USD")
81
+ currency = Money.new(1000, "USD").currency
70
82
  currency.iso_code
71
83
  # => "USD"
72
84
  currency.name
@@ -89,14 +101,14 @@ containing all the currency attributes.
89
101
 
90
102
  The pre-defined set of attributes includes:
91
103
 
92
- * priority: a numerical value you can use to sort/group the currency list
93
- * iso_code: the international 3-letter code as defined by the ISO 4217 standard
94
- * name: the currency name
95
- * symbol: the currency symbol (UTF-8 encoded)
96
- * subunit: the name of the fractional monetary unit
97
- * subunit_to_unit: the proportion between the unit and the subunit
98
- * separator: character between the whole and fraction amounts
99
- * delimiter: character between each thousands place
104
+ - priority: a numerical value you can use to sort/group the currency list
105
+ - iso_code: the international 3-letter code as defined by the ISO 4217 standard
106
+ - name: the currency name
107
+ - symbol: the currency symbol (UTF-8 encoded)
108
+ - subunit: the name of the fractional monetary unit
109
+ - subunit_to_unit: the proportion between the unit and the subunit
110
+ - separator: character between the whole and fraction amounts
111
+ - delimiter: character between each thousands place
100
112
 
101
113
  All attributes are optional. Some attributes, such as <tt>:symbol</tt>, are used by the Money class
102
114
  to print out a representation of the object. Other attributes, such as <tt>:name</tt> or <tt>:priority</tt>,
@@ -133,7 +145,7 @@ and all_currencies as follows:
133
145
  major_currencies(Money::Currency::TABLE)
134
146
  # => [ :usd, :eur, :bgp, :cad ]
135
147
 
136
- major_currencies(Money::Currency::TABLE)
148
+ all_currencies(Money::Currency::TABLE)
137
149
  # => [ :aed, :afn, all, ... ]
138
150
 
139
151
 
@@ -175,7 +187,7 @@ www.xe.com for the current rates or just returns <tt>rand(2)</tt>:
175
187
  The following is a list of Money.gem compatible currency exchange rate
176
188
  implementations.
177
189
 
178
- * eu_central_bank.gem: http://github.com/liangzan/eu_central_bank
190
+ * eu_central_bank.gem: http://github.com/RubyMoney/eu_central_bank
179
191
 
180
192
  === Ruby on Rails
181
193
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.pre1
1
+ 3.1.0.pre2
@@ -41,6 +41,19 @@ class Money
41
41
  @@singleton ||= self.new
42
42
  end
43
43
 
44
+ attr_reader :rounding_method
45
+
46
+ # Initializes a new Money::Bank::Base object. An optional block can be
47
+ # passed to dictate the rounding method that +exchange_with+ can use.
48
+ def initialize(&block)
49
+ @rounding_method = block
50
+ setup
51
+ end
52
+
53
+ # Called after initialize. Subclasses can use this method to setup
54
+ # variables, etc that they normally would in +#initialize+.
55
+ def setup
56
+ end
44
57
 
45
58
  # @deprecated +#exchange+ will be removed in v3.2.0, use +#exchange_with+
46
59
  #
@@ -22,10 +22,9 @@ class Money
22
22
  #
23
23
  class VariableExchange < Base
24
24
 
25
- def initialize(&block)
25
+ def setup
26
26
  @rates = {}
27
27
  @mutex = Mutex.new
28
- @rounding_method = block
29
28
  end
30
29
 
31
30
 
data/lib/money/money.rb CHANGED
@@ -149,6 +149,10 @@ class Money
149
149
  end
150
150
  end
151
151
 
152
+ # Returns a new Money object containing the sum of the two operands'
153
+ # monetary values. If +other_money+ has a different currency then its
154
+ # monetary value is automatically exchanged to this object's currency
155
+ # using +exchange_to+.
152
156
  def +(other_money)
153
157
  if currency == other_money.currency
154
158
  Money.new(cents + other_money.cents, other_money.currency)
@@ -157,6 +161,10 @@ class Money
157
161
  end
158
162
  end
159
163
 
164
+ # Returns a new Money object containing the difference between the two
165
+ # operands' monetary values. If +other_money+ has a different currency
166
+ # then its monetary value is automatically exchanged to this object's
167
+ # currency using +exchange_to+.
160
168
  def -(other_money)
161
169
  if currency == other_money.currency
162
170
  Money.new(cents - other_money.cents, other_money.currency)
@@ -165,17 +173,25 @@ class Money
165
173
  end
166
174
  end
167
175
 
168
- # get the cents value of the object
176
+ # Gets the cents value of this money object.
177
+ #
178
+ # Money.new(15_00, "USD").cents # => 15_00
169
179
  def cents
170
180
  @cents
171
181
  end
172
182
 
173
- # multiply money by fixnum
183
+ # Multiplies the monetary value with the given number and returns a
184
+ # new Money object with this monetary value and the same currency.
185
+ #
186
+ # Multiplying with another Money object is currently not supported.
174
187
  def *(fixnum)
175
188
  Money.new(cents * fixnum, currency)
176
189
  end
177
190
 
178
- # divide money by money or fixnum
191
+ # Divides the monetary value with the given number and returns a
192
+ # new Money object with this monetary value and the same currency.
193
+ #
194
+ # Dividing with another Money object is currently not supported.
179
195
  def /(val)
180
196
  if val.is_a?(Money)
181
197
  if currency == val.currency
@@ -188,7 +204,7 @@ class Money
188
204
  end
189
205
  end
190
206
 
191
- # synonym for #/
207
+ # Synonym for #/.
192
208
  def div(val)
193
209
  self / val
194
210
  end
data/money.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{money}
8
- s.version = "3.1.0.pre1"
8
+ s.version = "3.1.0.pre2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin", "Shane Emmons", "Simone Carletti"]
12
- s.date = %q{2010-08-03}
12
+ s.date = %q{2010-08-10}
13
13
  s.description = %q{Money and currency exchange support library.}
14
14
  s.email = %q{hongli@phusion.nl}
15
15
  s.extra_rdoc_files = [
@@ -1,11 +1,33 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Money::Bank::Base do
4
-
5
4
  before :each do
6
5
  @bank = Money::Bank::Base.new
7
6
  end
8
7
 
8
+ describe '#new with &block' do
9
+ it 'should store @rounding_method' do
10
+ proc = Proc.new{|n| n.ceil}
11
+ bank = Money::Bank::Base.new(&proc)
12
+ bank.rounding_method.should == proc
13
+ end
14
+ end
15
+
16
+ describe '#setup' do
17
+ it 'should call #setup after #initialize' do
18
+ class MyBank < Money::Bank::Base
19
+ attr_reader :setup_called
20
+
21
+ def setup
22
+ @setup_called = true
23
+ end
24
+ end
25
+
26
+ bank = MyBank.new
27
+ bank.setup_called.should == true
28
+ end
29
+ end
30
+
9
31
  describe '#exchange' do
10
32
  it 'should raise NotImplementedError' do
11
33
  lambda { @bank.exchange(100, 'USD', 'EUR') }.should raise_exception(NotImplementedError)
@@ -53,5 +75,4 @@ describe Money::Bank::Base do
53
75
  lambda{@bank.send(:same_currency?, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
54
76
  end
55
77
  end
56
-
57
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33582789
4
+ hash: 341127967
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
- - pre1
11
- version: 3.1.0.pre1
10
+ - pre2
11
+ version: 3.1.0.pre2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Tobias Luetke
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2010-08-03 00:00:00 -04:00
23
+ date: 2010-08-10 00:00:00 -04:00
24
24
  default_executable:
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency