more_money 0.0.10 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -0
- data/lib/more_money/core_extensions.rb +23 -4
- data/lib/more_money/more_money.rb +2 -2
- data/lib/more_money/price.rb +236 -0
- data/lib/more_money/version.rb +2 -2
- data/test/more_money_test.rb +19 -0
- data/test/price_test.rb +150 -0
- metadata +49 -36
data/Manifest.txt
CHANGED
@@ -2,9 +2,18 @@
|
|
2
2
|
# 100.to_money => #<Money @cents=10000>
|
3
3
|
# 100.37.to_money => #<Money @cents=10037>
|
4
4
|
class Numeric
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def to_money(currency = nil)
|
7
|
+
args = [(self * 100), currency].compact
|
8
|
+
Money.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_price(opts = {})
|
12
|
+
money = to_money(opts[:currency])
|
13
|
+
args = [opts[:tax_code], opts[:tax_inclusive]].compact
|
14
|
+
Price.new(money.cents, money.currency, *args)
|
7
15
|
end
|
16
|
+
|
8
17
|
end
|
9
18
|
|
10
19
|
# Allows Writing of '100'.to_money for +String+ types
|
@@ -12,10 +21,11 @@ end
|
|
12
21
|
# '100'.to_money => #<Money @cents=10000>
|
13
22
|
# '100.37'.to_money => #<Money @cents=10037>
|
14
23
|
class String
|
15
|
-
|
24
|
+
|
25
|
+
def to_money(currency = nil)
|
16
26
|
# Get the currency
|
17
27
|
matches = scan(/([A-Z]{2,3})/)
|
18
|
-
currency
|
28
|
+
currency ||= matches[0] ? matches[0][0] : MoreMoney::Money.default_currency
|
19
29
|
|
20
30
|
# Get the cents amount
|
21
31
|
matches = scan(/(\-?\d+(\.(\d+))?)/)
|
@@ -23,10 +33,19 @@ class String
|
|
23
33
|
|
24
34
|
MoreMoney::Money.new(cents, currency)
|
25
35
|
end
|
36
|
+
|
37
|
+
def to_price(opts = {})
|
38
|
+
money = to_money(opts[:currency])
|
39
|
+
args = [opts[:tax_code], opts[:tax_inclusive]].compact
|
40
|
+
Price.new(money.cents, money.currency, *args)
|
41
|
+
end
|
42
|
+
|
26
43
|
end
|
27
44
|
|
28
45
|
class NilClass
|
46
|
+
|
29
47
|
def to_money(currency = MoreMoney::Money.default_currency)
|
30
48
|
MoreMoney::Money.new(nil, currency)
|
31
49
|
end
|
50
|
+
|
32
51
|
end
|
@@ -121,7 +121,7 @@ module MoreMoney
|
|
121
121
|
#
|
122
122
|
def self.curr_symbol(currency = Money.default_currency)
|
123
123
|
check_currency(currency)
|
124
|
-
CURRENCIES[currency][:symbol]
|
124
|
+
CURRENCIES[currency][:symbol].dup
|
125
125
|
end
|
126
126
|
|
127
127
|
# Creates a new money object.
|
@@ -244,7 +244,7 @@ module MoreMoney
|
|
244
244
|
newstr = []
|
245
245
|
3.times { newstr << formatted.shift } unless rules.include?(:no_cents)
|
246
246
|
formatted.each_with_index do |num, index|
|
247
|
-
newstr << ',' if index !=0 && index % 3 == 0
|
247
|
+
newstr << ',' if index !=0 && num != '-' && index % 3 == 0
|
248
248
|
newstr << num
|
249
249
|
end
|
250
250
|
formatted = newstr.to_s.reverse!
|
@@ -0,0 +1,236 @@
|
|
1
|
+
module MoreMoney
|
2
|
+
|
3
|
+
class TaxMissingMethod < StandardError# :nodoc:
|
4
|
+
end
|
5
|
+
|
6
|
+
class PricesWithDifferentTaxesCompared < StandardError# :nodoc:
|
7
|
+
end
|
8
|
+
|
9
|
+
class PricesWithDifferentInclusiveClause < StandardError# :nodoc:
|
10
|
+
end
|
11
|
+
|
12
|
+
class PriceInvalidTax < StandardError# :nodoc:
|
13
|
+
end
|
14
|
+
|
15
|
+
class Price
|
16
|
+
|
17
|
+
include Comparable
|
18
|
+
|
19
|
+
TAXES = {}
|
20
|
+
|
21
|
+
#the current default tax
|
22
|
+
def self.default_tax
|
23
|
+
@default_tax
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#set the default tax
|
28
|
+
# MoreMoney::Money.default_tax_rate = 'GBP'
|
29
|
+
#
|
30
|
+
def self.default_tax=(tax_code)
|
31
|
+
@default_tax = tax_code
|
32
|
+
end
|
33
|
+
|
34
|
+
#show if by default prices are tax inclusive/exclusive
|
35
|
+
def self.default_inclusive
|
36
|
+
@default_inclusive
|
37
|
+
end
|
38
|
+
|
39
|
+
#set if by default prices are tax inclusive
|
40
|
+
def self.default_inclusive=(default_inclusive)
|
41
|
+
raise ArgumentError, "default inclusive can be only true or false" unless [TrueClass, FalseClass].member?(default_inclusive.class)
|
42
|
+
@default_inclusive = default_inclusive
|
43
|
+
end
|
44
|
+
|
45
|
+
#adds a tax to the set of available ones.
|
46
|
+
#
|
47
|
+
# MoreMoney::Price.add_tax(tax_obj)
|
48
|
+
#
|
49
|
+
#a tax object is a generic ruby object that responds to the methods
|
50
|
+
#
|
51
|
+
# * apply -> lamba that applies the tax to a net value
|
52
|
+
# * discount -> lambda that drops the tax from the gross value
|
53
|
+
# * code -> short code for the tax
|
54
|
+
# * formatted code -> code for display purpouse
|
55
|
+
#
|
56
|
+
def self.add_tax(tax)
|
57
|
+
case tax
|
58
|
+
when Hash
|
59
|
+
TAXES[tax[:code]] = tax[:taxes].map { |t| TAXES[t] }
|
60
|
+
else
|
61
|
+
mandatory_methods = [:apply, :discount, :code, :formatted_code]
|
62
|
+
mandatory_methods.each do |m|
|
63
|
+
raise TaxMissingMethod, "#{m} method is not defined by #{tax.inspect}" unless tax.respond_to? m
|
64
|
+
end
|
65
|
+
TAXES[tax.code] = tax
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.check_tax(tax_code)
|
70
|
+
raise PriceInvalidTax, "#{tax_code} is not defined as a tax" unless TAXES.key?(tax_code)
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_reader :money, :tax, :tax_inclusive, :tax_amounts, :tax_code
|
74
|
+
|
75
|
+
# Creates a new price object.
|
76
|
+
#
|
77
|
+
# Price.new(100)
|
78
|
+
#
|
79
|
+
def initialize(cents, currency = Money.default_currency, tax = Price.default_tax, tax_inclusive = Price.default_inclusive)
|
80
|
+
@money = Money.new(cents, currency)
|
81
|
+
self.class.check_tax(tax)
|
82
|
+
@tax = TAXES[tax]
|
83
|
+
@tax_code = tax
|
84
|
+
@tax_amounts = []
|
85
|
+
@tax_inclusive = tax_inclusive
|
86
|
+
@tax_inclusive ? discount_tax : apply_tax
|
87
|
+
end
|
88
|
+
|
89
|
+
def tax_inclusive?
|
90
|
+
tax_inclusive
|
91
|
+
end
|
92
|
+
|
93
|
+
#returns a Money object with the net amount
|
94
|
+
def net
|
95
|
+
tax_inclusive ? tax_amounts.inject(gross) { |sum, a| sum - a[1] } : money
|
96
|
+
end
|
97
|
+
|
98
|
+
#returns a Money object with the gross amount
|
99
|
+
def gross
|
100
|
+
tax_inclusive ? money : tax_amounts.inject(net) { |sum, a| sum + a[1] }
|
101
|
+
end
|
102
|
+
|
103
|
+
def cents
|
104
|
+
money.cents
|
105
|
+
end
|
106
|
+
|
107
|
+
#currency
|
108
|
+
def currency
|
109
|
+
money.currency
|
110
|
+
end
|
111
|
+
|
112
|
+
# Do two money objects equal? Only works if both objects are of the same currency
|
113
|
+
def eql?(other_price)
|
114
|
+
raise_different_tax(other_price)
|
115
|
+
net == other_price.net
|
116
|
+
end
|
117
|
+
|
118
|
+
def <=>(other_price)
|
119
|
+
raise_different_tax(other_price)
|
120
|
+
net <=> other_price.net
|
121
|
+
end
|
122
|
+
|
123
|
+
%w(+ -).each do |operator|
|
124
|
+
class_eval <<-EOE
|
125
|
+
def #{operator}(other_price)
|
126
|
+
raise_different_tax(other_price)
|
127
|
+
raise_different_inclusive(other_price)
|
128
|
+
if tax_inclusive == other_price.tax_inclusive
|
129
|
+
new_money = money #{operator} other_price.money
|
130
|
+
Price.new(new_money.cents, currency, tax_code, tax_inclusive)
|
131
|
+
else
|
132
|
+
new_money = net #{operator} other_price.net
|
133
|
+
Price.new(new_money.cents, currency, tax_code, false)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
EOE
|
137
|
+
end
|
138
|
+
|
139
|
+
def -@
|
140
|
+
self.class.new(-cents, currency, tax_code, tax_inclusive)
|
141
|
+
end
|
142
|
+
|
143
|
+
# multiply money by fixnum
|
144
|
+
def *(fixnum)
|
145
|
+
Price.new(money.cents * fixnum, currency, tax_code, tax_inclusive)
|
146
|
+
end
|
147
|
+
|
148
|
+
# divide money by fixnum
|
149
|
+
def /(fixnum)
|
150
|
+
Price.new(money.cents / fixnum, currency, tax_code, tax_inclusive)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Test if the price is zero
|
154
|
+
def zero?
|
155
|
+
return money.zero?
|
156
|
+
end
|
157
|
+
|
158
|
+
# Test if the price is zero
|
159
|
+
def no_cost?
|
160
|
+
return (money.zero? || money.cents.nil?)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Format the price according rules
|
164
|
+
#
|
165
|
+
# Currently supported are :with_tax_inclusion, :with_tax
|
166
|
+
# All the extra rules specified will be passed to the money object
|
167
|
+
#
|
168
|
+
def format(*rules)
|
169
|
+
rules = rules.flatten
|
170
|
+
price_string = []
|
171
|
+
price_string << (tax.formatted_code) if rules.delete(:with_tax)
|
172
|
+
price_string << (tax_inclusive ? 'inc.' : 'exc.') if rules.delete(:with_tax_inclusion)
|
173
|
+
([money.format(rules)] + price_string).join(' ')
|
174
|
+
end
|
175
|
+
|
176
|
+
# Money.new(100, 'USD').to_s => "1.00"
|
177
|
+
def to_s
|
178
|
+
cents.nil? ? '' : sprintf("%.2f", money.cents.to_f / 100 )
|
179
|
+
end
|
180
|
+
|
181
|
+
# Conversation to self
|
182
|
+
def to_price
|
183
|
+
self
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
def raise_different_tax(other_price)
|
189
|
+
raise PricesWithDifferentTaxesCompared, "Can not compare prices with different taxation" unless tax == other_price.tax
|
190
|
+
end
|
191
|
+
|
192
|
+
def raise_different_inclusive(other_price)
|
193
|
+
raise PricesWithDifferentInclusiveClause, "Can not add/subtract prices with different inclusive clause.\n Look at Price.sum method" unless tax_inclusive == other_price.tax_inclusive
|
194
|
+
end
|
195
|
+
|
196
|
+
def apply_tax(tax_to_apply = @tax)
|
197
|
+
if tax_to_apply.is_a? Array
|
198
|
+
tax_to_apply.each { |t| apply_tax(t) }
|
199
|
+
else
|
200
|
+
@tax_amounts << [tax_to_apply, tax_to_apply.apply.call(self)]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def discount_tax(tax_to_discount = @tax)
|
205
|
+
if tax_to_discount.is_a? Array
|
206
|
+
tax_to_discount.reverse.each { |t| discount_tax(t) }
|
207
|
+
else
|
208
|
+
@tax_amounts << [tax_to_discount, tax_to_discount.discount.call(self)]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
#class methods for price
|
215
|
+
|
216
|
+
class Price
|
217
|
+
|
218
|
+
#returns an array with the sum of the given arguments grouped by tax code
|
219
|
+
#it can only sum
|
220
|
+
def self.partial_sum(*args)
|
221
|
+
return nil if (to_sum = args.flatten.compact).size == 0
|
222
|
+
raise PricesWithDifferentInclusiveClause unless to_sum.collect { |p| p.tax_inclusive }.uniq.size == 1
|
223
|
+
same_tax_groups = to_sum.collect { |p| p.tax }.uniq.map { |tax| to_sum.select { |p| p.tax == tax } }
|
224
|
+
same_tax_group_sums = same_tax_groups.map { |g| g.inject(Price.new(0, g.first.currency, g.first.tax_code, g.first.tax_inclusive)) { |tot, p| tot + p } }
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.sum(*args)
|
228
|
+
return nil if args.flatten.size == 0
|
229
|
+
type = args.last.is_a?(Symbol) ? args.pop : :gross
|
230
|
+
partial = [true, false].map { |t| partial_sum(args.flatten.select { |a| a.tax_inclusive == t }) }.flatten.compact
|
231
|
+
partial.inject(Money.new(0, partial.first.currency)) { |tot, p| tot + p.send(type == :gross ? :gross : :net) }
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
data/lib/more_money/version.rb
CHANGED
data/test/more_money_test.rb
CHANGED
@@ -68,6 +68,17 @@ class MoreMoneyTest < Test::Unit::TestCase
|
|
68
68
|
assert_equal "free as in a beer", Money.gb_pound(0).format
|
69
69
|
end
|
70
70
|
|
71
|
+
def test_format_negative_amount
|
72
|
+
ten_pounds = Money.gb_pound(-1000)
|
73
|
+
hundred_pounds = Money.gb_pound(-10000)
|
74
|
+
hundred_thousand_pounds = Money.gb_pound(-10000000)
|
75
|
+
million_pounds = Money.gb_pound(-100000000)
|
76
|
+
assert_equal "£ -10.00", ten_pounds.format(:with_thousands)
|
77
|
+
assert_equal "£ -100.00", hundred_pounds.format(:with_thousands)
|
78
|
+
assert_equal "£ -100,000.00", hundred_thousand_pounds.format(:with_thousands)
|
79
|
+
assert_equal "£ -1,000,000.00", million_pounds.format(:with_thousands)
|
80
|
+
end
|
81
|
+
|
71
82
|
def test_nil
|
72
83
|
a = Money.new(nil)
|
73
84
|
assert_equal nil, a.cents
|
@@ -144,4 +155,12 @@ class MoreMoneyTest < Test::Unit::TestCase
|
|
144
155
|
assert_equal [ 100, 'GBP'], c.exchange_to('GBP').instance_eval("[cents, currency]")
|
145
156
|
assert_raise(MoreMoney::MoneyMissingExchangeRate) { d.exchange_to('GBP') }
|
146
157
|
end
|
158
|
+
|
159
|
+
def test_multiple_currency_protected
|
160
|
+
10.times do
|
161
|
+
assert_equal '£ 10.00', Money.new(1000, 'GBP').format(:with_thousands)
|
162
|
+
Money.curr_symbol('GBP') << ' '
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
147
166
|
end
|
data/test/price_test.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
include MoreMoney
|
4
|
+
|
5
|
+
Tax = Struct.new(:apply, :discount, :code, :formatted_code, :rate)
|
6
|
+
|
7
|
+
class MoreMoneyPriceTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
Money.load_std_currencies
|
11
|
+
Money.default_currency = 'GBP'
|
12
|
+
define_taxes
|
13
|
+
Price.default_inclusive = false
|
14
|
+
@net_price = Price.new(1000)
|
15
|
+
@gross_price = Price.new(1175, 'GBP', 'UK_175', true)
|
16
|
+
@price_net_quebec = Price.new(10000, 'GBP', 'CAD_QUEBEC')
|
17
|
+
@price_gross_quebec = Price.new(11395, 'GBP', 'CAD_QUEBEC', true)
|
18
|
+
@price_net_ontario = Price.new(10000, 'GBP', 'CAD_ONTARIO')
|
19
|
+
@price_gross_ontario = Price.new(11400, 'GBP', 'CAD_ONTARIO', true)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_simple_tax
|
23
|
+
price = Price.new(1000)
|
24
|
+
assert_equal 1000, price.money.cents
|
25
|
+
assert_equal 1175, price.gross.cents
|
26
|
+
price2 = Price.new(1175, 'GBP', 'UK_175', true)
|
27
|
+
assert_equal 1175, price2.gross.cents
|
28
|
+
assert_equal 1000, price2.net.cents
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_tax_amounts
|
32
|
+
assert_equal [600, 795], @price_net_quebec.tax_amounts.collect { |a| a[1].cents }
|
33
|
+
assert_equal [795, 600], @price_gross_quebec.tax_amounts.collect { |a| a[1].cents }
|
34
|
+
assert_equal [600, 800], @price_net_ontario.tax_amounts.collect { |a| a[1].cents }
|
35
|
+
assert_equal [800, 600], @price_gross_ontario.tax_amounts.collect { |a| a[1].cents }
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def test_taxes_on_taxes_gross
|
40
|
+
assert_equal 11395, @price_net_quebec.gross.cents
|
41
|
+
assert_equal 11395, @price_gross_quebec.gross.cents
|
42
|
+
assert_equal 11400, @price_net_ontario.gross.cents
|
43
|
+
assert_equal 11400, @price_gross_ontario.gross.cents
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_taxes_on_taxes_net
|
47
|
+
assert_equal 10000, @price_net_quebec.net.cents
|
48
|
+
assert_equal 10000, @price_gross_quebec.net.cents
|
49
|
+
assert_equal 10000, @price_net_ontario.net.cents
|
50
|
+
assert_equal 10000, @price_gross_ontario.net.cents
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_core_extention_number
|
54
|
+
assert_equal Price.new(1000), 10.to_price
|
55
|
+
assert_equal @price_net_quebec, 100.to_price(:currency => 'GBP', :tax_code => 'CAD_QUEBEC')
|
56
|
+
assert_equal @price_gross_quebec, 113.95.to_price(:currency => 'GBP', :tax_code => 'CAD_QUEBEC', :tax_inclusive => true)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_core_extention_string
|
60
|
+
assert_equal Price.new(1000), '10.00'.to_price
|
61
|
+
assert_equal @price_net_quebec, '100.00'.to_price(:currency => 'GBP', :tax_code => 'CAD_QUEBEC')
|
62
|
+
assert_equal @price_gross_quebec, '113.95'.to_price(:currency => 'GBP', :tax_code => 'CAD_QUEBEC', :tax_inclusive => true)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_unary_minus
|
66
|
+
np = - @price_net_quebec
|
67
|
+
assert_equal (- @price_net_quebec.cents), np.cents
|
68
|
+
assert_equal 100.to_price(:currency => 'GBP', :tax_code => 'CAD_QUEBEC'), (- np)
|
69
|
+
end
|
70
|
+
|
71
|
+
#def test_rounding
|
72
|
+
# (100..10000).each do |n|
|
73
|
+
# p "testing #{n}"
|
74
|
+
# p = Price.new(n, 'GBP', 'UK_175', true)
|
75
|
+
# assert_equal n, p.money.cents
|
76
|
+
# assert_equal p.money.cents, Price.new(p.net.cents).gross.cents
|
77
|
+
# end
|
78
|
+
#end
|
79
|
+
|
80
|
+
def test_sum
|
81
|
+
to_sum = [@net_price, @price_net_quebec, @price_net_ontario]
|
82
|
+
assert_equal Price.sum(to_sum), Price.sum(*to_sum)
|
83
|
+
assert_equal 21000, Price.sum(to_sum, :net).cents
|
84
|
+
assert_equal 23970, Price.sum(to_sum, :gross).cents
|
85
|
+
assert_equal 'GBP', Price.sum(to_sum, :net).currency
|
86
|
+
to_sum = [@net_price, @price_net_quebec, @price_net_ontario, @price_gross_ontario]
|
87
|
+
assert_equal Price.sum(to_sum), Price.sum(*to_sum)
|
88
|
+
assert_equal 31000, Price.sum(to_sum, :net).cents
|
89
|
+
assert_equal 35370, Price.sum(to_sum, :gross).cents
|
90
|
+
assert_equal 'GBP', Price.sum(to_sum, :net).currency
|
91
|
+
to_sum = [@net_price, @price_net_quebec, @price_net_ontario, @price_net_ontario]
|
92
|
+
assert_equal Price.sum(to_sum), Price.sum(*to_sum)
|
93
|
+
assert_equal 31000, Price.sum(to_sum, :net).cents
|
94
|
+
assert_equal 35370, Price.sum(to_sum, :gross).cents
|
95
|
+
assert_equal 'GBP', Price.sum(to_sum, :net).currency
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_partial_sum
|
99
|
+
to_sum = [@net_price, @price_net_quebec, @price_net_ontario]
|
100
|
+
assert_equal Price.partial_sum(to_sum), Price.partial_sum(*to_sum)
|
101
|
+
#assert_equal 21000, Price.partial_sum(to_sum).cents
|
102
|
+
#assert_equal 23970, Price.partial_sum(to_sum).cents
|
103
|
+
#assert_equal 'GBP', Price.partial_sum(to_sum).currency
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def define_taxes
|
109
|
+
|
110
|
+
revert_rate = lambda { |rate| rate / (1 + rate) }
|
111
|
+
gb_std = Tax.new
|
112
|
+
gb_std.rate = 0.175
|
113
|
+
gb_std.apply = lambda { |price| price.net * 0.175 }
|
114
|
+
gb_std.discount = lambda { |price| price.gross * revert_rate.call(0.175) }
|
115
|
+
gb_std.code = "UK_175"
|
116
|
+
gb_std.formatted_code = "VAT 17.5%"
|
117
|
+
Price.add_tax(gb_std)
|
118
|
+
|
119
|
+
cad_gst = Tax.new
|
120
|
+
cad_gst.rate = 0.06
|
121
|
+
cad_gst.apply = lambda { |price| price.net * cad_gst.rate }
|
122
|
+
cad_gst.discount = lambda { |price| price.net * revert_rate.call(cad_gst.rate) }
|
123
|
+
cad_gst.code = "CAD_GST"
|
124
|
+
cad_gst.formatted_code = "GST 6%"
|
125
|
+
Price.add_tax(cad_gst)
|
126
|
+
|
127
|
+
cad_pst_quebec = Tax.new
|
128
|
+
cad_pst_quebec.rate = 0.075
|
129
|
+
cad_pst_quebec.apply = lambda { |price| price.gross * 0.075 }
|
130
|
+
cad_pst_quebec.discount = lambda { |price| price.net * revert_rate.call(0.075) }
|
131
|
+
cad_pst_quebec.code = "CAD_PST_QUEBEC"
|
132
|
+
cad_pst_quebec.formatted_code = "PST Quebec 7.5%"
|
133
|
+
Price.add_tax(cad_pst_quebec)
|
134
|
+
|
135
|
+
cad_pst_ontario = Tax.new
|
136
|
+
cad_pst_ontario.rate = 0.08
|
137
|
+
cad_pst_ontario.apply = lambda { |price| price.net * 0.08 }
|
138
|
+
cad_pst_ontario.discount = lambda { |price| price.net * 0.08 / (1 + 0.08 + Price::TAXES['CAD_GST'].rate) }
|
139
|
+
cad_pst_ontario.code = "CAD_PST_ONTARIO"
|
140
|
+
cad_pst_ontario.formatted_code = "PST Ontario 8%"
|
141
|
+
Price.add_tax(cad_pst_ontario)
|
142
|
+
|
143
|
+
cad_quebec = {:code => 'CAD_QUEBEC', :taxes => ['CAD_GST', 'CAD_PST_QUEBEC']}
|
144
|
+
Price.add_tax(cad_quebec)
|
145
|
+
cad_ontario = {:code => 'CAD_ONTARIO', :taxes => ['CAD_GST', 'CAD_PST_ONTARIO']}
|
146
|
+
Price.add_tax(cad_ontario)
|
147
|
+
Price.default_tax = gb_std.code
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
metadata
CHANGED
@@ -1,33 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: more_money
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-02-14 00:00:00 +00:00
|
8
|
-
summary: handles money objects in any currency using just integer as backend
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: use rubyforge to contact
|
12
|
-
homepage: http://moremoney.rubyforge.org
|
13
|
-
rubyforge_project: moremoney
|
14
|
-
description: handles money objects in any currency using just integer as backend
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.1.1
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Paolo Negri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-20 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: handles money objects in any currency using just integer as backend
|
17
|
+
email: use rubyforge to contact
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- Manifest.txt
|
24
|
+
- CHANGELOG.txt
|
25
|
+
- README.txt
|
31
26
|
files:
|
32
27
|
- Manifest.txt
|
33
28
|
- CHANGELOG.txt
|
@@ -39,19 +34,37 @@ files:
|
|
39
34
|
- lib/more_money/version.rb
|
40
35
|
- lib/more_money/core_extensions.rb
|
41
36
|
- lib/more_money/more_money.rb
|
37
|
+
- lib/more_money/price.rb
|
42
38
|
- test/test_helper.rb
|
43
39
|
- test/more_money_test.rb
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
- test/price_test.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://moremoney.rubyforge.org
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.txt
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
54
61
|
requirements: []
|
55
62
|
|
56
|
-
|
57
|
-
|
63
|
+
rubyforge_project: moremoney
|
64
|
+
rubygems_version: 1.1.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: handles money objects in any currency using just integer as backend
|
68
|
+
test_files:
|
69
|
+
- test/more_money_test.rb
|
70
|
+
- test/price_test.rb
|