ledgerjournal 0.5.1 → 0.6.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 +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +6 -0
- data/README.md +25 -4
- data/ledgerjournal.gemspec +2 -2
- data/lib/ledgerjournal/journal.rb +4 -3
- data/lib/ledgerjournal/options.rb +3 -0
- data/lib/ledgerjournal/posting.rb +3 -2
- data/lib/ledgerjournal/transaction.rb +3 -3
- data/lib/ledgerjournal/version.rb +1 -1
- metadata +21 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bb59ca2d7f64a129c519354a4d9cdfb5d3eb4b7f97cb58d2232a4558315cfb2
|
4
|
+
data.tar.gz: 2ee806a9ab9755e980581d1b96910d8f692c7ff03cdd9700fbd0d673f6e592e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ecd9601da9786418765ebc5d5c7488ba225fce0c332a70919e13809387278d633905eb211eef170c3a87c50daa5f6c6a53d019b4c200819279cb53bc1d21d7
|
7
|
+
data.tar.gz: bc1f7e4b702408d90ec302617ffa37514530e2542d85d92033b72e8d42ecce0834935a084a44c9fb526a2fbd0cd2c45b83cae50818f31c6207b7ce29ea4e9df5
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,12 +8,17 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
docile (1.3.2)
|
11
12
|
mini_portile2 (2.4.0)
|
12
13
|
minitest (5.14.0)
|
13
14
|
nokogiri (1.10.9)
|
14
15
|
mini_portile2 (~> 2.4.0)
|
15
16
|
open4 (1.3.4)
|
16
17
|
rake (12.3.3)
|
18
|
+
simplecov (0.18.5)
|
19
|
+
docile (~> 1.1)
|
20
|
+
simplecov-html (~> 0.11)
|
21
|
+
simplecov-html (0.12.2)
|
17
22
|
|
18
23
|
PLATFORMS
|
19
24
|
ruby
|
@@ -22,6 +27,7 @@ DEPENDENCIES
|
|
22
27
|
ledgerjournal!
|
23
28
|
minitest (~> 5.0)
|
24
29
|
rake (~> 12.0)
|
30
|
+
simplecov
|
25
31
|
|
26
32
|
BUNDLED WITH
|
27
33
|
2.1.4
|
data/README.md
CHANGED
@@ -10,16 +10,16 @@ The ledger binary needs to be installed to parse and pretty-print.
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
Parsing a
|
13
|
+
Parsing a ledger journal file:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
journal = Ledger::Journal.new(path: "example_journal.
|
16
|
+
journal = Ledger::Journal.new(path: "example_journal.dat")
|
17
17
|
journal.transactions.each do |tx|
|
18
18
|
puts tx.date, tx.payee
|
19
19
|
end
|
20
20
|
```
|
21
21
|
|
22
|
-
Creating a ledger:
|
22
|
+
Creating a ledger file from scratch:
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
journal = Ledger::Journal.new()
|
@@ -37,9 +37,30 @@ journal.transactions << Ledger::Transaction.new(
|
|
37
37
|
puts(journal.to_s)
|
38
38
|
```
|
39
39
|
|
40
|
+
Appending to a ledger journal:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
journal = Ledger::Journal.new(path: "example_journal.dat")
|
44
|
+
journal.transactions << Ledger::Transaction.new(
|
45
|
+
date: Date.new(2020, 1, 2),
|
46
|
+
payee: 'Example Payee',
|
47
|
+
postings: [
|
48
|
+
Ledger::Posting.new(account: "Expenses:Unknown", currency: "EUR", amount: BigDecimal('1234.56')),
|
49
|
+
Ledger::Posting.new(account: "Assets:Checking", currency: "EUR", amount: BigDecimal('-1234.56'))
|
50
|
+
]
|
51
|
+
)
|
52
|
+
journal.save!
|
53
|
+
```
|
54
|
+
|
55
|
+
Running ledger commands:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
puts Ledger.defaults.run('--version')
|
59
|
+
```
|
60
|
+
|
40
61
|
### Locale-specific settings
|
41
62
|
|
42
|
-
By default ledgerjournal
|
63
|
+
By default ledgerjournal expects the date format '%Y/%m/%d' and amounts with decimal point (1234.56). This is configurable:
|
43
64
|
|
44
65
|
```ruby
|
45
66
|
Ledger.defaults = Options.new(date_format: '%d.%m.%Y', decimal_comma: true)
|
data/ledgerjournal.gemspec
CHANGED
@@ -17,10 +17,9 @@ The ledger binary needs to be installed to parse and pretty-print.'
|
|
17
17
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
18
18
|
|
19
19
|
spec.metadata = {
|
20
|
-
'homepage_uri' => spec.homepage,
|
21
20
|
'source_code_uri' => 'https://github.com/ralfebert/ledgerjournal.git',
|
22
21
|
'bug_tracker_uri' => 'https://github.com/ralfebert/ledgerjournal/issues',
|
23
|
-
'documentation_uri' =>
|
22
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/ledgerjournal/'
|
24
23
|
}
|
25
24
|
|
26
25
|
# Specify which files should be added to the gem when it is released.
|
@@ -32,4 +31,5 @@ The ledger binary needs to be installed to parse and pretty-print.'
|
|
32
31
|
|
33
32
|
spec.add_dependency 'nokogiri', '~> 1.10'
|
34
33
|
spec.add_dependency 'open4', '~> 1.3'
|
34
|
+
spec.add_development_dependency 'simplecov'
|
35
35
|
end
|
@@ -23,8 +23,7 @@ module Ledger
|
|
23
23
|
@path = path
|
24
24
|
raise Error, "#{@path} not found" unless File.exist?(@path)
|
25
25
|
|
26
|
-
|
27
|
-
read_ledger(ledger_args: args)
|
26
|
+
read_ledger(ledger_args: ["-f #{@path.shellescape}", ledger_args].compact.join(' '))
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
@@ -38,6 +37,8 @@ module Ledger
|
|
38
37
|
# @param [Boolean] pretty_print calls ledger to format the journal if true
|
39
38
|
def to_s(pretty_print: true)
|
40
39
|
str = transactions.map(&:to_s).join("\n\n")
|
40
|
+
# add a newline at the end of the file - see https://github.com/ledger/ledger/issues/516
|
41
|
+
str += "\n"
|
41
42
|
if pretty_print
|
42
43
|
begin
|
43
44
|
str = Ledger.defaults.run('-f - print', stdin: str)
|
@@ -69,7 +70,7 @@ module Ledger
|
|
69
70
|
def read_ledger(ledger_args: '')
|
70
71
|
xml_result = Ledger.defaults.run(ledger_args + ' xml')
|
71
72
|
xml = Nokogiri::XML(xml_result)
|
72
|
-
@transactions = xml.
|
73
|
+
@transactions = xml.xpath('ledger/transactions/transaction').map { |tx_xml| Transaction.parse_xml(tx_xml) }
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
@@ -3,6 +3,9 @@
|
|
3
3
|
module Ledger
|
4
4
|
# Options for interaction with ledger-cli
|
5
5
|
class Options
|
6
|
+
attr_reader :date_format
|
7
|
+
attr_reader :decimal_comma
|
8
|
+
|
6
9
|
# @param [String] date_format like '%Y/%m/%d' to pass to ledger-cli
|
7
10
|
# @param [Boolean] decimal_comma pass true to use a comma as decimal separator, otherwise a dot is used
|
8
11
|
def initialize(date_format:, decimal_comma:)
|
@@ -43,10 +43,11 @@ module Ledger
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_s
|
46
|
-
posting_line = "#{account}
|
46
|
+
posting_line = "#{account} "
|
47
|
+
posting_line += "#{currency} #{Ledger.defaults.format(amount)}".rjust(48 - posting_line.length, ' ')
|
47
48
|
posting_line += " = #{currency} #{Ledger.defaults.format(balance_assignment)}" if balance_assignment
|
48
49
|
lines = [posting_line]
|
49
|
-
lines += metadata.to_a.
|
50
|
+
lines += metadata.to_a.collect { |m| "; #{m[0]}: #{m[1]}" } unless metadata.empty?
|
50
51
|
return lines.join("\n")
|
51
52
|
end
|
52
53
|
|
@@ -21,7 +21,7 @@ module Ledger
|
|
21
21
|
|
22
22
|
def self.parse_xml(xml)
|
23
23
|
Transaction.new(
|
24
|
-
date: Date.strptime(xml.xpath('date').text,
|
24
|
+
date: Date.strptime(xml.xpath('date').text, Ledger.defaults.date_format),
|
25
25
|
payee: xml.xpath('payee').text,
|
26
26
|
state: xml['state'].to_sym,
|
27
27
|
metadata: Hash[xml.xpath('metadata/value').collect { |m| [m['key'], m.xpath('string').text] }],
|
@@ -38,11 +38,11 @@ module Ledger
|
|
38
38
|
states = { pending: '!', cleared: '*' }
|
39
39
|
lines = ["#{date_str} #{states[state]} #{payee}"]
|
40
40
|
|
41
|
-
lines += metadata.to_a.
|
41
|
+
lines += metadata.to_a.collect { |m| " ; #{m[0]}: #{m[1]}" } unless metadata.empty?
|
42
42
|
|
43
43
|
lines += postings.map { |posting| posting.to_s.lines.map { |line| ' ' + line }.join }
|
44
44
|
|
45
|
-
return lines.join("\n")
|
45
|
+
return lines.join("\n")
|
46
46
|
end
|
47
47
|
|
48
48
|
# @param [String, Array<String>] accounts name(s)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledgerjournal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ralf Ebert
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: |-
|
42
56
|
ledgerjournal is a Ruby gem to read and write ledger accounting files.
|
43
57
|
For parsing, it uses the xml output from ledger. For outputting, it formats the ledger data to String in custom Ruby code.
|
@@ -69,11 +83,10 @@ homepage: https://github.com/ralfebert/ledgerjournal
|
|
69
83
|
licenses:
|
70
84
|
- MIT
|
71
85
|
metadata:
|
72
|
-
homepage_uri: https://github.com/ralfebert/ledgerjournal
|
73
86
|
source_code_uri: https://github.com/ralfebert/ledgerjournal.git
|
74
87
|
bug_tracker_uri: https://github.com/ralfebert/ledgerjournal/issues
|
75
|
-
documentation_uri: https://www.rubydoc.info/gems/ledgerjournal/
|
76
|
-
post_install_message:
|
88
|
+
documentation_uri: https://www.rubydoc.info/gems/ledgerjournal/
|
89
|
+
post_install_message:
|
77
90
|
rdoc_options: []
|
78
91
|
require_paths:
|
79
92
|
- lib
|
@@ -88,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
101
|
- !ruby/object:Gem::Version
|
89
102
|
version: '0'
|
90
103
|
requirements: []
|
91
|
-
rubygems_version: 3.0.
|
92
|
-
signing_key:
|
104
|
+
rubygems_version: 3.0.8
|
105
|
+
signing_key:
|
93
106
|
specification_version: 4
|
94
107
|
summary: Library to read and write ledger accounting files.
|
95
108
|
test_files: []
|