bean_sprout 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bean_sprout/ledger.rb +8 -6
- data/lib/bean_sprout/transaction.rb +8 -0
- data/lib/bean_sprout/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9a55ee004d73a05996d6c5469cdc295e2c59797
|
4
|
+
data.tar.gz: 5bb9618364946b85e85f641d08d58dec0332e4e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b23dbe41d7fbc541ae1c2add0fdc7805a7eb9ff10bb9306adfbef6dc3484f753a4d779ab8bbb8e8df2df7006f87f4b9467771406665d702f58681a1752f51478
|
7
|
+
data.tar.gz: 4ecad1de36c155e21e678e6169af559fd095c6956bbc343c3c5ebcfbd86718982d1dceb818b47ee8df62347fe382e875cb12b9a98c857d3c61b89568a0b6727e
|
data/lib/bean_sprout/ledger.rb
CHANGED
@@ -17,6 +17,7 @@ module BeanSprout
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def create_account currency, other_data: nil
|
20
|
+
currency ||= @base_currency
|
20
21
|
bean = @beans.store do |next_id|
|
21
22
|
Bean.new(next_id, currency)
|
22
23
|
end
|
@@ -46,22 +47,22 @@ module BeanSprout
|
|
46
47
|
Transaction.new(sprout_bunch, other_data)
|
47
48
|
end
|
48
49
|
|
49
|
-
def transfer from_acc, to_acc, amount
|
50
|
-
if from_acc.currency !=
|
50
|
+
def transfer from_acc, to_acc, amount, other_data: nil
|
51
|
+
if from_acc.currency != to_acc.currency
|
51
52
|
raise "Cannot transfer between two forex accounts."
|
52
53
|
end
|
53
54
|
|
54
55
|
entry0 = create_entry from_acc, -amount
|
55
56
|
entry1 = create_entry to_acc, amount
|
56
|
-
commit_entries [entry0, entry1]
|
57
|
+
commit_entries [entry0, entry1], other_data
|
57
58
|
end
|
58
59
|
|
59
|
-
def forex_transfer from_acc, to_acc, from_amount, to_amount
|
60
|
+
def forex_transfer from_acc, to_acc, from_amount, to_amount, other_data: nil
|
60
61
|
entry0 = create_entry from_acc, -from_amount
|
61
62
|
entry1 = create_entry (dummy_account from_acc.currency), from_amount
|
62
63
|
entry2 = create_entry to_acc, to_amount
|
63
64
|
entry3 = create_entry (dummy_account to_acc.currency), -to_amount
|
64
|
-
commit_entries [entry0, entry1, entry2, entry3]
|
65
|
+
commit_entries [entry0, entry1, entry2, entry3], other_data
|
65
66
|
end
|
66
67
|
|
67
68
|
# TODO: clients can't access ID.
|
@@ -107,9 +108,10 @@ module BeanSprout
|
|
107
108
|
obj.instance_variable_get :@target
|
108
109
|
end
|
109
110
|
|
110
|
-
def commit_entries entries
|
111
|
+
def commit_entries entries, other_data = nil
|
111
112
|
trans = create_transaction entries
|
112
113
|
trans.commit
|
114
|
+
trans.other_data = other_data
|
113
115
|
trans
|
114
116
|
end
|
115
117
|
end
|
@@ -86,5 +86,13 @@ module BeanSprout
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
# If this transaction only involves one local currency.
|
91
|
+
def local?
|
92
|
+
currency = sprouts[0].bean.currency
|
93
|
+
sprouts.inject(true) do |acc, sprout|
|
94
|
+
acc && sprout.bean.currency == currency
|
95
|
+
end
|
96
|
+
end
|
89
97
|
end
|
90
98
|
end
|
data/lib/bean_sprout/version.rb
CHANGED