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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c152d339fb6536aa158b1c41060934381664be78
4
- data.tar.gz: ecaed26f13bbbdfdb2befa88bad5336d4e02fb62
3
+ metadata.gz: e9a55ee004d73a05996d6c5469cdc295e2c59797
4
+ data.tar.gz: 5bb9618364946b85e85f641d08d58dec0332e4e5
5
5
  SHA512:
6
- metadata.gz: e0836bf16fac2e63bcf6484eee2bfddf6cb5e8902fd2044b211c4fe6be68de4c4747287dfa62531845659932779d9447c0763b8d1235bad551a83c22f3e360de
7
- data.tar.gz: 5b665a4661aa28f7f5167e052f1892d13a532da3da38c6f1d02ad5bc5f4039dd0ea782a07321c3550d79d0028b46c784d83f696727671c5d63e1963ff03dd85f
6
+ metadata.gz: b23dbe41d7fbc541ae1c2add0fdc7805a7eb9ff10bb9306adfbef6dc3484f753a4d779ab8bbb8e8df2df7006f87f4b9467771406665d702f58681a1752f51478
7
+ data.tar.gz: 4ecad1de36c155e21e678e6169af559fd095c6956bbc343c3c5ebcfbd86718982d1dceb818b47ee8df62347fe382e875cb12b9a98c857d3c61b89568a0b6727e
@@ -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 != @base_currency || to_acc.currency != @base_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
@@ -1,3 +1,3 @@
1
1
  module BeanSprout
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bean_sprout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liqing Muyi