ledger-rest 4.0.1 → 4.0.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmNiYjRiMDg1ZjlkMDg2ZjlmZmM5ZTAzNmE3OTY0NTE5MjliMzAxMA==
4
+ ZWQxMGVjNzE3M2IzYjYxNGIwZjc2NTI5MDRjZTMzMDMzNjdmNGEwYw==
5
5
  data.tar.gz: !binary |-
6
- OTZiMmU0MmMyMmI1NTYwNjBlZTlmMDZhNGMxZWU2YmVmMmZiYmJiZA==
6
+ YTU2ZmNmY2E1NWI1NGQwY2FlNzc0N2UxZDgwMzU4NDU1NDI0Yjc5Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDI5YjVkNjYxYmVhYjQwOTA0NjNmMGFhYTg3MjYyZjdlZTg4MDY0YjY3MWJl
10
- ODM0NjgyOTkzYjZlYWVjZWFkY2M0OGE5NmViMGE3NTljNmYzMWU3YjE2YmNj
11
- MmUyMDhjMTg3Nzg2Yjk1NTRjMjA2ZWVhYWI2NjUxNTg5MTY1Zjc=
9
+ MmUxMzYwMzFkMWU5NzdjZDE3ZjkwM2UyZjZmZjc2NWM0M2ExOTkwYTBmNTVi
10
+ YjY0ZTA0ZWEzY2MwMTc1ZGNkZTAxOTZmNTcxYzQ5OGM2MWZkODJlYzMzMjRl
11
+ OTE5N2RlNzFkNTgzNjg2ZGRmOTBhYTFiODhmNzI4MzRmYThlZjc=
12
12
  data.tar.gz: !binary |-
13
- YTQ4YTJkZDQyNjU1OGQ3NzU5YTVmMTc5OWYwNGEyZThjN2FjNDhlYmE1YjEz
14
- NTI4NjY1MDJkY2ExMTYzNzA5YWJhNGI3Y2ExYWI0MTdiOTQ3NDllNDdjODQy
15
- OTFmMTZjYTI2MjBhNzExNzhhYWU5YTBhNjcyZTM1NDNmNTk1MDM=
13
+ YzFjNWY5MjNjOTU1ZjBmZDVhZWE4ZmFlZDcyMTI5ODY5ZDEzMDg3NDY4OTRj
14
+ MWFlOGE5MWU2YzVhMzVhMjZiZmNmYjk3MzAxNzc5ZjEzOThiZDA4ODJjYzIx
15
+ YTcxNGU1MDg1ZjQ3YjkyNGE0MWZiOWFjYWRlNTc3MjI1MzBhMGU=
@@ -16,6 +16,7 @@ module LedgerRest
16
16
  data = JSON.parse(json(query, params), symbolize_names: true)
17
17
 
18
18
  data[:accounts] = expand_accounts(data[:accounts])
19
+
19
20
  unless query =~ /--flat/
20
21
  data[:accounts] = wrap_accounts(data[:accounts])
21
22
  end
@@ -25,7 +26,7 @@ module LedgerRest
25
26
 
26
27
  def json(query = nil, params = {})
27
28
  params = { '--format' => FORMAT }.merge(params)
28
- result = Ledger.exec("bal #{query}", params)
29
+ result = Ledger.exec("bal #{query.gsub('--flat', '')}", params)
29
30
 
30
31
  parser = Ledger::Parser.new
31
32
  result.gsub! /\[\["(?<amounts>[^"]+)"\]\]/m do |a, b|
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module LedgerRest
3
- VERSION = '4.0.1'
3
+ VERSION = '4.0.2'
4
4
  end
@@ -138,93 +138,48 @@ describe '/balance' do
138
138
  'accounts' =>
139
139
  [
140
140
  {
141
- 'totals' =>
142
- [
143
- {
144
- 'amount' => 0.25,
145
- 'commodity' => 'BTC'
146
- }
147
- ],
141
+ 'totals' => [{ 'amount' => 0.25, 'commodity' => 'BTC' }, { 'amount' => 3022.97, 'commodity' => 'EUR' }],
142
+ 'name' => 'Assets',
143
+ 'depth' => 1,
144
+ 'fullname' => 'Assets'
145
+ }, {
146
+ 'totals' => [{ 'amount' => 0.25, 'commodity' => 'BTC' }],
148
147
  'name' => 'Bitcoin',
149
148
  'depth' => 2,
150
149
  'fullname' => 'Assets:Bitcoin'
151
150
  }, {
152
- 'totals' =>
153
- [
154
- {
155
- 'amount' => 5.7,
156
- 'commodity' => 'EUR'
157
- }
158
- ],
151
+ 'totals' => [{ 'amount' => 5.7, 'commodity' => 'EUR' }],
159
152
  'name' => 'Cash',
160
153
  'depth' => 2,
161
154
  'fullname' => 'Assets:Cash'
162
155
  }, {
163
- 'totals' =>
164
- [
165
- {
166
- 'amount' => 2995.17,
167
- 'commodity' => 'EUR'
168
- }
169
- ],
156
+ 'totals' => [{ 'amount' => 2995.17, 'commodity' => 'EUR' }],
170
157
  'name' => 'Giro',
171
158
  'depth' => 2,
172
159
  'fullname' => 'Assets:Giro'
173
160
  }, {
174
- 'totals' =>
175
- [
176
- {
177
- 'amount' => 22.1,
178
- 'commodity' => 'EUR'
179
- }
180
- ],
161
+ 'totals' => [{ 'amount' => 22.1, 'commodity' => 'EUR' }],
181
162
  'name' => 'Reimbursements',
182
163
  'depth' => 2,
183
164
  'fullname' => 'Assets:Reimbursements'
184
165
  }, {
185
- 'totals' =>
186
- [
187
- {
188
- 'amount' => 22.1,
189
- 'commodity' => 'EUR'
190
- }
191
- ],
166
+ 'totals' => [{ 'amount' => 22.1, 'commodity' => 'EUR' }],
192
167
  'name' => 'Hans Maulwurf',
193
168
  'depth' => 3,
194
169
  'fullname' => 'Assets:Reimbursements:Hans Maulwurf'
195
170
  }, {
196
- 'totals' =>
197
- [
198
- {
199
- 'amount' => -12.0,
200
- 'commodity' => 'EUR'
201
- }
202
- ],
171
+ 'totals' => [{ 'amount' => -12.0, 'commodity' => 'EUR' }],
203
172
  'name' => 'Liabilities',
204
173
  'depth' => 1,
205
174
  'fullname' => 'Liabilities'
206
175
  }, {
207
- 'totals' =>
208
- [
209
- {
210
- 'amount' => -12.0,
211
- 'commodity' => 'EUR'
212
- }
213
- ],
176
+ 'totals' => [{ 'amount' => -12.0, 'commodity' => 'EUR' }],
214
177
  'name' => 'Max Mustermann',
215
178
  'depth' => 2,
216
- 'fullname' => 'Liabilities:Max Mustermann' }
217
- ],
218
- 'totals' =>
219
- [
220
- {
221
- 'amount' => 0.25,
222
- 'commodity' => 'BTC'
223
- }, {
224
- 'amount' => 3010.97,
225
- 'commodity' => 'EUR'
179
+ 'fullname' => 'Liabilities:Max Mustermann'
226
180
  }
227
- ]
181
+ ],
182
+ 'totals' => [{ 'amount' => 0.25, 'commodity' => 'BTC' }, { 'amount' => 3010.97, 'commodity' => 'EUR' }]
228
183
  }
229
184
  end
230
185
 
@@ -1,6 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe LedgerRest::Ledger::Balance do
4
+ describe '::get' do
5
+ let(:json_with_root) do
6
+ {
7
+ accounts:
8
+ [
9
+ {
10
+ totals: [{ amount: 0.25, commodity: 'BTC' }, { amount: 3022.97, commodity: 'EUR' }],
11
+ name: 'Assets',
12
+ depth: 1,
13
+ fullname: 'Assets'
14
+ }, {
15
+ totals: [{ amount: 0.25, commodity: 'BTC' }],
16
+ name: 'Bitcoin',
17
+ depth: 2,
18
+ fullname: 'Assets:Bitcoin'
19
+ }, {
20
+ totals: [{ amount: 5.7, commodity: 'EUR' }],
21
+ name: 'Cash',
22
+ depth: 2,
23
+ fullname: 'Assets:Cash'
24
+ }, {
25
+ totals: [{ amount: 2995.17, commodity: 'EUR' }],
26
+ name: 'Giro',
27
+ depth: 2,
28
+ fullname: 'Assets:Giro'
29
+ }, {
30
+ totals: [{ amount: 22.1, commodity: 'EUR' }],
31
+ name: 'Reimbursements',
32
+ depth: 2,
33
+ fullname: 'Assets:Reimbursements'
34
+ }, {
35
+ totals: [{ amount: 22.1, commodity: 'EUR' }],
36
+ name: 'Hans Maulwurf',
37
+ depth: 3,
38
+ fullname: 'Assets:Reimbursements:Hans Maulwurf'
39
+ }
40
+ ],
41
+ totals: [{ amount: 0.25, commodity: 'BTC' }, { amount: 3022.97, commodity: 'EUR' }]
42
+ }
43
+ end
44
+
45
+ it 'removes the --flat flag from ledger command to gather root accounts aswell' do
46
+ LedgerRest::Ledger::Balance.get('--flat Assets').should deep_eq json_with_root
47
+ end
48
+ end
49
+
4
50
  describe '::expand_accounts' do
5
51
  let(:accounts) do
6
52
  [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledger-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prof. MAAD