bean_sprout 0.0.2 → 0.0.3
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4733d40d0fe67374824dead281510cda6053ec71
|
4
|
+
data.tar.gz: e8865c4596897622f821e6c379c3d766732def86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d13adb40a9589069865f7c72e217fc92017fc1db491040dc87fba2f30e8a6fa73dff009cb10a63b6a5956243e1a9a7885b5549ac87ff1f1652ba45602d201b39
|
7
|
+
data.tar.gz: 8a608a9d8d6822c9c04f4b0ae26493eedef5b9ce3c5ceb2ba39a05a35f4532e8295cc92a19486ea94cd8b12bf3192374917969428b04177ef59edfad2f08e87c
|
data/lib/bean_sprout/account.rb
CHANGED
@@ -2,19 +2,22 @@ require 'bean_sprout/struct_from_hash_mixin'
|
|
2
2
|
require 'bean_sprout/struct_archive_mixin'
|
3
3
|
|
4
4
|
module BeanSprout
|
5
|
-
class Account < Struct.new(:currency, :other_data)
|
5
|
+
class Account < Struct.new(:currency, :external_id, :other_data)
|
6
6
|
include StructFromHashMixin
|
7
7
|
include StructArchiveMixin
|
8
8
|
|
9
|
+
class BalanceHolder < Struct.new(:value)
|
10
|
+
end
|
11
|
+
|
9
12
|
def initialize *fields
|
10
13
|
super *fields
|
11
14
|
@entries = []
|
12
|
-
@
|
15
|
+
@balance = BalanceHolder.new(0)
|
13
16
|
end
|
14
17
|
|
15
18
|
def append_entry entry
|
16
19
|
@entries.push entry
|
17
|
-
@
|
20
|
+
@balance.value += entry.accurate_amount
|
18
21
|
end
|
19
22
|
|
20
23
|
def entries
|
@@ -22,7 +25,7 @@ module BeanSprout
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def balance
|
25
|
-
@
|
28
|
+
@balance.value
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -4,13 +4,13 @@ require 'bigdecimal'
|
|
4
4
|
require 'bigdecimal/util'
|
5
5
|
|
6
6
|
module BeanSprout
|
7
|
-
#
|
7
|
+
# Entry is made up of the following fields:
|
8
8
|
# 1. The account owns the entry, the currency of which is defined as the local
|
9
9
|
# currency;
|
10
10
|
# 2. The amount to be added to the account balance, in local currency;
|
11
11
|
# 3. Convention rate from local currency to the base currency;
|
12
12
|
# 4. Other arbitrary data.
|
13
|
-
class
|
13
|
+
class Entry < Struct.new(:account, :amount, :rate, :other_data)
|
14
14
|
include StructFromHashMixin
|
15
15
|
include StructArchiveMixin
|
16
16
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module BeanSprout
|
2
2
|
class GlassJar
|
3
|
+
# TODO: maybe each transaction can have its own
|
4
|
+
# currency.
|
3
5
|
attr_reader :base_currency
|
4
6
|
|
5
7
|
def initialize base_currency
|
@@ -7,6 +9,7 @@ module BeanSprout
|
|
7
9
|
|
8
10
|
@accounts = {}
|
9
11
|
@account_id = 0
|
12
|
+
@account_external_ids = {}
|
10
13
|
|
11
14
|
@transactions = {}
|
12
15
|
@transaction_id = 0
|
@@ -14,21 +17,29 @@ module BeanSprout
|
|
14
17
|
@entries = {}
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
20
|
+
def open_account account
|
18
21
|
account.archive_in_glass_jar self, next_account_id
|
19
22
|
@accounts[account.id] = account
|
23
|
+
@account_external_ids[account.external_id] = account
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_account currency, external_id = nil, other_data: nil
|
27
|
+
account = Account.new currency, external_id, other_data
|
28
|
+
open_account account
|
20
29
|
end
|
21
30
|
|
22
31
|
def accounts
|
23
32
|
@accounts.values
|
24
33
|
end
|
25
34
|
|
26
|
-
# External ID is not supported. Clients must implement
|
27
|
-
# external ID to internal ID mapping.
|
28
35
|
def account id
|
29
36
|
@accounts[id]
|
30
37
|
end
|
31
38
|
|
39
|
+
def account_for external_id
|
40
|
+
@account_external_ids[external_id]
|
41
|
+
end
|
42
|
+
|
32
43
|
def transactions
|
33
44
|
@transactions.values
|
34
45
|
end
|
@@ -75,6 +86,18 @@ module BeanSprout
|
|
75
86
|
commit_transaction(trans)
|
76
87
|
end
|
77
88
|
|
89
|
+
def new_account *args
|
90
|
+
Account.new args
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_transaction *args
|
94
|
+
Transaction.new args
|
95
|
+
end
|
96
|
+
|
97
|
+
def new_entry *args
|
98
|
+
Entry.new args
|
99
|
+
end
|
100
|
+
|
78
101
|
private
|
79
102
|
def next_account_id
|
80
103
|
@account_id += 1
|
data/lib/bean_sprout/version.rb
CHANGED
data/lib/bean_sprout.rb
CHANGED
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liqing Muyi
|
@@ -63,7 +63,7 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- lib/bean_sprout.rb
|
65
65
|
- lib/bean_sprout/account.rb
|
66
|
-
- lib/bean_sprout/
|
66
|
+
- lib/bean_sprout/entry.rb
|
67
67
|
- lib/bean_sprout/glass_jar.rb
|
68
68
|
- lib/bean_sprout/struct_archive_mixin.rb
|
69
69
|
- lib/bean_sprout/struct_from_hash_mixin.rb
|