gnucash 1.4.0 → 1.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 52713dfe700ed99ecbde5b43d7c0614e86d3ec34
4
- data.tar.gz: d59a7c2b7069bc1c355201e4c4e9f4ec832d1d55
2
+ SHA256:
3
+ metadata.gz: a58f8fe486b5e15eb9481af7c0ae86645334d0122207bd181d39ac52fa388461
4
+ data.tar.gz: f844443866e2b33cacbb44f3e78ae24c4ccc34a66bd73ee4beeac6911eddbb47
5
5
  SHA512:
6
- metadata.gz: ed54f96c4c23bb1960895f8c3df8918faed0b83362e73b5682251501fd8b664b3458797fe0a9abd45d5fb378b81f1dc508c825ff83c2e3b9a1a376c5c1a94e0c
7
- data.tar.gz: a92fc8a0fcb6eff1a5e851f9e512fd8c7714aaec0d69053055a879a7548e1036a283ba7cde903c34f52d615dbd2e80076ceb3a532fc840541f293a9823bea4a2
6
+ metadata.gz: d0d09b83dd1d6a88dc82515edcc798680e314cd8def62e69575dbd8d3feb8e3e0ac238c60091753ca50ad229ff59b9c3cbed507d656673fee5a758bb529b3465
7
+ data.tar.gz: 5dd6b7dabb61890a3c0b3ec1c072b3a6edc816c1824b30b4b353db07d60366b21ccfb1144293fd82d5a02ca0557ee34df903b0fd06a1212a415bf7f1cc31bf5d
@@ -1,5 +1,9 @@
1
1
  # ChangeLog
2
2
 
3
+ ## v1.5.0
4
+
5
+ - add options Hash to Account#balance_on with :recursive option
6
+
3
7
  ## v1.4.0
4
8
 
5
9
  - add Account#parent_id and #parent
@@ -1,39 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gnucash (1.4.0)
4
+ gnucash (1.5.0)
5
5
  nokogiri
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.3)
11
- docile (1.1.5)
11
+ docile (1.3.1)
12
12
  json (2.1.0)
13
- mini_portile2 (2.3.0)
14
- nokogiri (1.8.1)
15
- mini_portile2 (~> 2.3.0)
16
- rake (12.3.0)
17
- rdoc (6.0.1)
18
- rspec (3.7.0)
19
- rspec-core (~> 3.7.0)
20
- rspec-expectations (~> 3.7.0)
21
- rspec-mocks (~> 3.7.0)
22
- rspec-core (3.7.1)
23
- rspec-support (~> 3.7.0)
24
- rspec-expectations (3.7.0)
13
+ mini_portile2 (2.4.0)
14
+ nokogiri (1.10.1)
15
+ mini_portile2 (~> 2.4.0)
16
+ rake (12.3.2)
17
+ rdoc (6.1.1)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.7.0)
27
- rspec-mocks (3.7.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.7.0)
30
- rspec-support (3.7.0)
31
- simplecov (0.15.1)
32
- docile (~> 1.1.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ simplecov (0.16.1)
32
+ docile (~> 1.1)
33
33
  json (>= 1.8, < 3)
34
34
  simplecov-html (~> 0.10.0)
35
35
  simplecov-html (0.10.2)
36
- yard (0.9.12)
36
+ yard (0.9.18)
37
37
 
38
38
  PLATFORMS
39
39
  ruby
data/README.md CHANGED
@@ -45,6 +45,10 @@ delta = act.balance_on("#{year}-12-31") - act.balance_on("#{year - 1}-12-31")
45
45
  puts "You've saved #{delta} this year so far!"
46
46
  ```
47
47
 
48
+ To get the balance of an account, use ```act.balance_on("#{year}-12-31")```.
49
+ To get the total balance of an account with all its children accounts,
50
+ use ```act.balance_on("#{year}-12-31", recursive: true)```.
51
+
48
52
  ## Contributing
49
53
 
50
54
  1. Fork it
@@ -99,13 +99,28 @@ module Gnucash
99
99
  # Transactions that occur on the given date are included in the returned
100
100
  # balance.
101
101
  #
102
- # @param date [String, Date] Date on which to query the balance.
102
+ # @param date [String, Date]
103
+ # Date on which to query the balance.
104
+ # @param options [Hash]
105
+ # Optional parameters.
106
+ # @option options [Boolean] :recursive
107
+ # Whether to include children account balances.
103
108
  #
104
- # @return [Value] Balance of the account as of the date given.
105
- def balance_on(date)
109
+ # @return [Value]
110
+ # Balance of the account as of the date given.
111
+ def balance_on(date, options = {})
106
112
  date = Date.parse(date) if date.is_a?(String)
107
- return Value.new(0) unless @balances.size > 0
108
- return Value.new(0) if @balances.first[:date] > date
113
+ return_value = Value.new(0)
114
+
115
+ if options[:recursive]
116
+ # Get all child accounts from this account and accumulate the balances of them.
117
+ @book.accounts.reject { |account| account.parent != self }.each do |child_account|
118
+ return_value += child_account.balance_on(date, recursive: true)
119
+ end
120
+ end
121
+
122
+ return return_value unless @balances.size > 0
123
+ return return_value if @balances.first[:date] > date
109
124
  return @balances.last[:value] if date >= @balances.last[:date]
110
125
  imin = 0
111
126
  imax = @balances.size - 2
@@ -1,4 +1,4 @@
1
1
  module Gnucash
2
2
  # gem version
3
- VERSION = "1.4.0"
3
+ VERSION = "1.5.0"
4
4
  end
@@ -54,6 +54,12 @@ module Gnucash
54
54
  it "includes transactions that occur on the given date" do
55
55
  expect(@checking.balance_on("2007-03-27")).to eq Value.new(780000)
56
56
  end
57
+
58
+ describe 'with child accounts' do
59
+ it "returns the balance with the balance of the child accounts" do
60
+ expect(@assets.balance_on("2007-03-27", recursive: true)).to eq Value.new(790000)
61
+ end
62
+ end
57
63
  end
58
64
 
59
65
  it "stores whether the account was a placeholder" do
@@ -1,5 +1,7 @@
1
1
  require "simplecov"
2
2
 
3
- SimpleCov.start
3
+ SimpleCov.start do
4
+ add_filter "/.bundle/"
5
+ end
4
6
 
5
7
  require "gnucash"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnucash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Holtrop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.6.14
152
+ rubygems_version: 2.7.6
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Extract data from XML GnuCash data files