money 3.1.0.pre3 → 3.1.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.
- data/CHANGELOG.md +196 -0
- data/README.md +217 -0
- data/lib/money/bank/base.rb +73 -32
- data/lib/money/bank/variable_exchange.rb +128 -27
- data/lib/money/core_extensions.rb +39 -18
- data/lib/money/currency.rb +146 -53
- data/lib/money/defaults.rb +8 -2
- data/lib/money/deprecations.rb +8 -5
- data/lib/money/money.rb +363 -170
- metadata +45 -54
- data/.document +0 -5
- data/.gitignore +0 -21
- data/CHANGELOG.rdoc +0 -68
- data/README.rdoc +0 -212
- data/Rakefile +0 -49
- data/VERSION +0 -1
- data/money.gemspec +0 -77
- data/spec/bank/base_spec.rb +0 -78
- data/spec/bank/variable_exchange_spec.rb +0 -311
- data/spec/core_extensions_spec.rb +0 -111
- data/spec/currency_spec.rb +0 -126
- data/spec/deprecations_spec.rb +0 -16
- data/spec/money_spec.rb +0 -799
- data/spec/spec_helper.rb +0 -8
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
|
11
|
-
version: 3.1.0.pre3
|
10
|
+
version: 3.1.0
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Tobias Luetke
|
@@ -20,7 +19,7 @@ autorequire:
|
|
20
19
|
bindir: bin
|
21
20
|
cert_chain: []
|
22
21
|
|
23
|
-
date: 2010-
|
22
|
+
date: 2010-09-13 00:00:00 -04:00
|
24
23
|
default_executable:
|
25
24
|
dependencies:
|
26
25
|
- !ruby/object:Gem::Dependency
|
@@ -31,16 +30,14 @@ dependencies:
|
|
31
30
|
requirements:
|
32
31
|
- - ">="
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
hash:
|
33
|
+
hash: 3
|
35
34
|
segments:
|
36
|
-
-
|
37
|
-
|
38
|
-
- 9
|
39
|
-
version: 1.2.9
|
35
|
+
- 0
|
36
|
+
version: "0"
|
40
37
|
type: :development
|
41
38
|
version_requirements: *id001
|
42
39
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
40
|
+
name: yard
|
44
41
|
prerelease: false
|
45
42
|
requirement: &id002 !ruby/object:Gem::Requirement
|
46
43
|
none: false
|
@@ -50,30 +47,34 @@ dependencies:
|
|
50
47
|
hash: 3
|
51
48
|
segments:
|
52
49
|
- 0
|
53
|
-
|
54
|
-
- 12
|
55
|
-
version: 0.1.12
|
50
|
+
version: "0"
|
56
51
|
type: :development
|
57
52
|
version_requirements: *id002
|
58
|
-
|
59
|
-
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: json
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: This library aids one in handling money and different currencies.
|
68
|
+
email:
|
69
|
+
- hongli@phusion.nl
|
70
|
+
- semmons99+RubyMoney@gmail.com
|
60
71
|
executables: []
|
61
72
|
|
62
73
|
extensions: []
|
63
74
|
|
64
|
-
extra_rdoc_files:
|
65
|
-
|
66
|
-
- LICENSE
|
67
|
-
- README.rdoc
|
75
|
+
extra_rdoc_files: []
|
76
|
+
|
68
77
|
files:
|
69
|
-
- .document
|
70
|
-
- .gitignore
|
71
|
-
- CHANGELOG.rdoc
|
72
|
-
- LICENSE
|
73
|
-
- README.rdoc
|
74
|
-
- Rakefile
|
75
|
-
- VERSION
|
76
|
-
- lib/money.rb
|
77
78
|
- lib/money/bank/base.rb
|
78
79
|
- lib/money/bank/variable_exchange.rb
|
79
80
|
- lib/money/core_extensions.rb
|
@@ -81,21 +82,17 @@ files:
|
|
81
82
|
- lib/money/defaults.rb
|
82
83
|
- lib/money/deprecations.rb
|
83
84
|
- lib/money/money.rb
|
84
|
-
- money.
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
- spec/currency_spec.rb
|
89
|
-
- spec/deprecations_spec.rb
|
90
|
-
- spec/money_spec.rb
|
91
|
-
- spec/spec_helper.rb
|
85
|
+
- lib/money.rb
|
86
|
+
- CHANGELOG.md
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
92
89
|
has_rdoc: true
|
93
|
-
homepage: http://money.rubyforge.org
|
90
|
+
homepage: http://money.rubyforge.org
|
94
91
|
licenses: []
|
95
92
|
|
96
93
|
post_install_message:
|
97
|
-
rdoc_options:
|
98
|
-
|
94
|
+
rdoc_options: []
|
95
|
+
|
99
96
|
require_paths:
|
100
97
|
- lib
|
101
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -110,26 +107,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
108
|
none: false
|
112
109
|
requirements:
|
113
|
-
- - "
|
110
|
+
- - ">="
|
114
111
|
- !ruby/object:Gem::Version
|
115
|
-
hash:
|
112
|
+
hash: 21
|
116
113
|
segments:
|
117
114
|
- 1
|
118
115
|
- 3
|
119
|
-
-
|
120
|
-
version: 1.3.
|
121
|
-
requirements:
|
122
|
-
|
116
|
+
- 7
|
117
|
+
version: 1.3.7
|
118
|
+
requirements:
|
119
|
+
- json if you plan to import/export rates formatted as json
|
123
120
|
rubyforge_project: money
|
124
121
|
rubygems_version: 1.3.7
|
125
122
|
signing_key:
|
126
123
|
specification_version: 3
|
127
|
-
summary: Money and currency exchange support library
|
128
|
-
test_files:
|
129
|
-
|
130
|
-
- spec/bank/variable_exchange_spec.rb
|
131
|
-
- spec/core_extensions_spec.rb
|
132
|
-
- spec/currency_spec.rb
|
133
|
-
- spec/deprecations_spec.rb
|
134
|
-
- spec/money_spec.rb
|
135
|
-
- spec/spec_helper.rb
|
124
|
+
summary: Money and currency exchange support library.
|
125
|
+
test_files: []
|
126
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/CHANGELOG.rdoc
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
== Money 3.1.0.pre3
|
2
|
-
* added google_currency.gem to list of Currency Exchange Implementations
|
3
|
-
* updated HKD :subunit_to_unit from 10 to 100 (closes #20)
|
4
|
-
* added #(export/import)_rates to Money::Bank::VariableExchange (closes #21)
|
5
|
-
|
6
|
-
== Money 3.1.0.pre2
|
7
|
-
* moved @rounding_method from Money::Bank::VariableExchange to
|
8
|
-
Money::Bank::Base (closes #18)
|
9
|
-
* added #setup and call after #initialize in Money::Bank::Base (closes #19)
|
10
|
-
* update/fix documentation (closes #17)
|
11
|
-
|
12
|
-
== Money 3.1.0.pre1
|
13
|
-
* Implemented Money::Bank::Base (closes #14)
|
14
|
-
* Added Bank::Base#exchange_with
|
15
|
-
* Deprecated Bank::Base#exchange (removal in 3.2.0)
|
16
|
-
* Implented Money::Bank::VariableExchange
|
17
|
-
* Deprecated Money::VariableExchangeBank (removal in 3.2.0)
|
18
|
-
* Set Money::SYMBOLS, Money::SEPARATORS and Money::DELIMITERS
|
19
|
-
deprecation target to Money 3.2.0. (closes #16)
|
20
|
-
* Fixed rounding error in Numeric#to_money (closes #15)
|
21
|
-
* Implemented #has for Money and Money::Currency
|
22
|
-
* Refactored test suite to conform to RSpec conventions
|
23
|
-
* Moved project from github.com/FooBarWidget to github.com/RubyMoney
|
24
|
-
* Added Simone Carletti to list of authors
|
25
|
-
|
26
|
-
== Money 3.0.5
|
27
|
-
* Added Money#abs
|
28
|
-
* Updated Currency#subunit_to_unit documentation (it's an integer not a string)
|
29
|
-
* Fixed issue when exchanging currencies with different :subunit_to_unit values
|
30
|
-
* Added ability to pass a block to VariableExchangeBank#new or #exchange,
|
31
|
-
specifying a custom truncation method
|
32
|
-
* Added optional currency argument to Numeric#to_money
|
33
|
-
* Added optional currency argument to String#to_money
|
34
|
-
* Numeric#to_money now respects :subunit_to_unit
|
35
|
-
* Use '¤' as the default currency symbol
|
36
|
-
|
37
|
-
== Money 3.0.4
|
38
|
-
* Updated #exchange to avoid floating point rounding errors
|
39
|
-
* Use :subunit_to_unit in #to_s, #to_f and #format
|
40
|
-
* Added :separator and :delimiter to Currency
|
41
|
-
* Deprecated Money#SEPARATORS and Money#DELIMITERS
|
42
|
-
* Updated the attributes of the Chilean Peso
|
43
|
-
|
44
|
-
== Money 3.0.3
|
45
|
-
* Added #currency_as_string and #currency_as_string= for easier integration
|
46
|
-
with ActiveRecord/Rails
|
47
|
-
|
48
|
-
== Money 3.0.2
|
49
|
-
* Added #div, #divmod, #modulo, #% and #remainder methods
|
50
|
-
|
51
|
-
== Money 3.0.1
|
52
|
-
* Added #eql? method
|
53
|
-
* Updated Numeric#to_money to work with all children of Numeric
|
54
|
-
(BigDecimal, Integer, Fixnum, etc)
|
55
|
-
|
56
|
-
== Money 3.0.0
|
57
|
-
* Version Bump due to compatibility changes with ActiveRecord. See
|
58
|
-
http://github.com/RubyMoney/money/issues#issue/4/comment/224880 for more information.
|
59
|
-
|
60
|
-
== Money 2.3.0
|
61
|
-
* Currency is now represented by a Currency Object instead of a string.
|
62
|
-
|
63
|
-
== Money 2.2.0
|
64
|
-
* Can now divide two Money objects by one another [#/]
|
65
|
-
* Can now convert a Money object to a float [#to_f]
|
66
|
-
* Users can now specify Seperators and Delimiters [#format]
|
67
|
-
* Support for Brazilian Real [Money.new(1_00, :BRL)]
|
68
|
-
* Migrated to Jeweler
|
data/README.rdoc
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
= Introduction
|
2
|
-
|
3
|
-
This library aids one in handling money and different currencies. Features:
|
4
|
-
|
5
|
-
- Provides a <tt>Money</tt> class which encapsulates all information about an certain
|
6
|
-
amount of money, such as its value and its currency.
|
7
|
-
- Provides a <tt>Money::Currency</tt> class which encapsulates all information about
|
8
|
-
a monetary unit.
|
9
|
-
- Represents monetary values as integers, in cents. This avoids floating point
|
10
|
-
rounding errors.
|
11
|
-
- Represents currency as <tt>Money::Currency</tt> instances providing an high level of flexibility.
|
12
|
-
- Provides APIs for exchanging money from one currency to another.
|
13
|
-
- Has the ability to parse a money and currency strings
|
14
|
-
into the corresponding Money/Currency object.
|
15
|
-
|
16
|
-
Resources:
|
17
|
-
|
18
|
-
- Website: http://money.rubyforge.org
|
19
|
-
- RDoc API: http://money.rubyforge.org
|
20
|
-
- Git repository: http://github.com/RubyMoney/money
|
21
|
-
|
22
|
-
== Attention
|
23
|
-
|
24
|
-
Starting in v3.1.0 we will be making two changes to the exchange process. First
|
25
|
-
a new `Bank::Base` class will be available. This will allow users to more
|
26
|
-
easily create custom `Bank` classes. Secondly the default `#exchange` method
|
27
|
-
will be depreciated and a new `#exchange_with` method will be used. Currently
|
28
|
-
`#exchange` passes the `cents` attribute. `#exchange_with` will pass the
|
29
|
-
actual `Money` object instead.
|
30
|
-
|
31
|
-
== Download
|
32
|
-
|
33
|
-
Install stable releases with the following command:
|
34
|
-
|
35
|
-
gem install money
|
36
|
-
|
37
|
-
The development version (hosted on Github) can be installed with:
|
38
|
-
|
39
|
-
git clone git://github.com/RubyMoney/money.git
|
40
|
-
cd money
|
41
|
-
rake install
|
42
|
-
|
43
|
-
== Usage
|
44
|
-
|
45
|
-
=== Synopsis
|
46
|
-
|
47
|
-
require 'money'
|
48
|
-
|
49
|
-
# 10.00 USD
|
50
|
-
money = Money.new(1000, "USD")
|
51
|
-
money.cents # => 1000
|
52
|
-
money.currency # => Currency.new("USD")
|
53
|
-
|
54
|
-
# Comparisons
|
55
|
-
Money.new(1000, "USD") == Money.new(1000, "USD") # => true
|
56
|
-
Money.new(1000, "USD") == Money.new(100, "USD") # => false
|
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")
|
69
|
-
|
70
|
-
=== Currency
|
71
|
-
|
72
|
-
Currencies are consistently represented as instances of <tt>Money::Currency</tt>.
|
73
|
-
The most part of <tt>Money</tt> APIs allows you to supply either a <tt>String</tt> or a <tt>Money::Currency</tt>.
|
74
|
-
|
75
|
-
Money.new(1000, "USD") == Money.new(900, Currency.new("USD"))
|
76
|
-
Money.new(1000, "EUR").currency == Currency.new("EUR")
|
77
|
-
|
78
|
-
A <tt>Money::Currency</tt> instance holds all the information about the currency,
|
79
|
-
including the currency symbol, name and much more.
|
80
|
-
|
81
|
-
currency = Money.new(1000, "USD").currency
|
82
|
-
currency.iso_code
|
83
|
-
# => "USD"
|
84
|
-
currency.name
|
85
|
-
# => "United States Dollar"
|
86
|
-
|
87
|
-
To define a new <tt>Money::Currency</tt> simply add a new item to the <tt>Money::Currency::TABLE</tt> hash,
|
88
|
-
where the key is the identifier for the currency object and the value is a hash
|
89
|
-
containing all the currency attributes.
|
90
|
-
|
91
|
-
Money::Currency::TABLE[:usd] = {
|
92
|
-
:priority => 1,
|
93
|
-
:iso_code => "USD",
|
94
|
-
:name => "United States Dollar",
|
95
|
-
:symbol => "$",
|
96
|
-
:subunit => "Cent"
|
97
|
-
:subunit_to_unit => 100,
|
98
|
-
:separator => ".",
|
99
|
-
:delimiter => ","
|
100
|
-
}
|
101
|
-
|
102
|
-
The pre-defined set of attributes includes:
|
103
|
-
|
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
|
112
|
-
|
113
|
-
All attributes are optional. Some attributes, such as <tt>:symbol</tt>, are used by the Money class
|
114
|
-
to print out a representation of the object. Other attributes, such as <tt>:name</tt> or <tt>:priority</tt>,
|
115
|
-
exist to provide a basic API you can take advantage of to build your application.
|
116
|
-
|
117
|
-
==== priority
|
118
|
-
|
119
|
-
The priority attribute is an arbitrary numerical value you can assign to the <tt>Money::Currency</tt>
|
120
|
-
and use in sorting/grouping operation.
|
121
|
-
|
122
|
-
For instance, let's assume your Rails application needs to render a currency selector
|
123
|
-
like the one available at http://finance.yahoo.com/currency-converter/
|
124
|
-
You can create a couple of custom methods to return the list of major_currencies
|
125
|
-
and all_currencies as follows:
|
126
|
-
|
127
|
-
# Returns an array of currency id where
|
128
|
-
# priority < 10
|
129
|
-
def major_currencies(hash)
|
130
|
-
hash.inject([]) do |array, (id, attributes)|
|
131
|
-
priority = attributes[:priority]
|
132
|
-
if priority && priority < 10
|
133
|
-
array[priority] ||= []
|
134
|
-
array[priority] << id
|
135
|
-
end
|
136
|
-
array
|
137
|
-
end.compact.flatten
|
138
|
-
end
|
139
|
-
|
140
|
-
# Returns an array of all currency id
|
141
|
-
def all_currencies(hash)
|
142
|
-
hash.keys
|
143
|
-
end
|
144
|
-
|
145
|
-
major_currencies(Money::Currency::TABLE)
|
146
|
-
# => [ :usd, :eur, :bgp, :cad ]
|
147
|
-
|
148
|
-
all_currencies(Money::Currency::TABLE)
|
149
|
-
# => [ :aed, :afn, all, ... ]
|
150
|
-
|
151
|
-
|
152
|
-
=== Default Currency
|
153
|
-
|
154
|
-
By default <tt>Money</tt> defaults to USD as its currency. This can be overwritten using
|
155
|
-
|
156
|
-
Money.default_currency = Money::Currency.new("CAD")
|
157
|
-
|
158
|
-
If you use Rails, then <tt>environment.rb</tt> is a very good place to put this.
|
159
|
-
|
160
|
-
=== Currency Exchange
|
161
|
-
|
162
|
-
Exchanging money is performed through an exchange bank object. The default
|
163
|
-
exchange bank object requires one to manually specify the exchange rate. Here's
|
164
|
-
an example of how it works:
|
165
|
-
|
166
|
-
Money.add_rate("USD", "CAD", 1.24515)
|
167
|
-
Money.add_rate("CAD", "USD", 0.803115)
|
168
|
-
|
169
|
-
Money.us_dollar(100).exchange_to("CAD") # => Money.new(124, "CAD")
|
170
|
-
Money.ca_dollar(100).exchange_to("USD") # => Money.new(80, "USD")
|
171
|
-
|
172
|
-
Comparison and arithmetic operations work as expected:
|
173
|
-
|
174
|
-
Money.new(1000, "USD") <=> Money.new(900, "USD") # => 1; 9.00 USD is smaller
|
175
|
-
Money.new(1000, "EUR") + Money.new(10, "EUR") == Money.new(1010, "EUR")
|
176
|
-
|
177
|
-
Money.add_rate("USD", "EUR", 0.5)
|
178
|
-
Money.new(1000, "EUR") + Money.new(1000, "USD") == Money.new(1500, "EUR")
|
179
|
-
|
180
|
-
There is nothing stopping you from creating bank objects which scrapes
|
181
|
-
www.xe.com for the current rates or just returns <tt>rand(2)</tt>:
|
182
|
-
|
183
|
-
Money.default_bank = ExchangeBankWhichScrapesXeDotCom.new
|
184
|
-
|
185
|
-
=== Currency Exchange (Money::Bank::*) Implementations
|
186
|
-
|
187
|
-
The following is a list of Money.gem compatible currency exchange rate
|
188
|
-
implementations.
|
189
|
-
|
190
|
-
* eu_central_bank.gem: http://github.com/RubyMoney/eu_central_bank
|
191
|
-
* google_currency.gem: http://github.com/RubyMoney/google_currency
|
192
|
-
|
193
|
-
=== Ruby on Rails
|
194
|
-
|
195
|
-
Use the +compose_of+ helper to let Active Record deal with embedding the money
|
196
|
-
object in your models. The following example requires a +cents+ and a +currency+
|
197
|
-
field.
|
198
|
-
|
199
|
-
composed_of :price,
|
200
|
-
:class_name => "Money",
|
201
|
-
:mapping => [%w(cents cents), %w(currency currency_as_string)],
|
202
|
-
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) }
|
203
|
-
|
204
|
-
For Money 2.2.x and previous versions, simply use the following
|
205
|
-
<tt>composed_of</tt> definition:
|
206
|
-
|
207
|
-
composed_of :price,
|
208
|
-
:class_name => "Money",
|
209
|
-
:mapping => [%w(cents cents), %w(currency currency)],
|
210
|
-
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) }
|
211
|
-
|
212
|
-
For further details read the full discussion at http://github.com/RubyMoney/money/issues/4#comment_224880
|