ldgr 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/ldgr/parser.rb +14 -5
- data/lib/ldgr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8c6866c2d4d40abc43e7a8e8ea43c58b7c84fd6
|
4
|
+
data.tar.gz: d61e4c679154b467de16b50690614bde21541a72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe0f8e4e8a9e0956e7a68e53f884ebffd33479fd2f5675729fe5df9ff88910162a61e11334c71365f0365c35888c425e47dcc11147f30c706ba179274654690
|
7
|
+
data.tar.gz: e4b89b0bffdacdbcf027ac7f1e8377b4c7fb5c5e1f86cdfd579fc6707940debd334974dee9e4324bad0679d6218fb22bd747e68215dd4ec1cc41b48617a3d1ba
|
data/README.md
CHANGED
@@ -33,11 +33,10 @@ Or install it yourself as:
|
|
33
33
|
|
34
34
|
$ gem install ldgr
|
35
35
|
|
36
|
-
##
|
36
|
+
## Customization
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
The CLI defaults the currency to **$**. You can set this yourself by adding a single currency character to `~/.config/ledger/default_currency`.
|
38
|
+
- The CLI defaults the currency to **$**. You can set a new default yourself by adding `currency: someCurrencyCharacter` to `~/.config/ledger/ldgr.yaml`.
|
39
|
+
- The CLI defaults the equity to **Cash** You can set a new default yourself by adding `equity: someEquityAccount` to `~/.config/ledger/ldgr.yaml`.
|
41
40
|
|
42
41
|
## CLI
|
43
42
|
```
|
data/lib/ldgr/parser.rb
CHANGED
@@ -6,6 +6,7 @@ require 'optparse/date'
|
|
6
6
|
require 'pathname'
|
7
7
|
require 'strscan'
|
8
8
|
require 'fileutils'
|
9
|
+
require 'yaml'
|
9
10
|
|
10
11
|
module Ldgr
|
11
12
|
class Parser
|
@@ -15,8 +16,9 @@ module Ldgr
|
|
15
16
|
PROGRAM_NAME = 'ldgr'
|
16
17
|
MATCH = /(?=(\n\d\d\d\d-\d\d-\d\d)(=\d\d\d\d-\d\d-\d\d)*)|\z/
|
17
18
|
OTHER_MATCH = /(?=(\d\d\d\d-\d\d-\d\d)(=\d\d\d\d-\d\d-\d\d)*)/
|
18
|
-
DEFAULT_CURRENCY = Pathname(FILEBASE + '/default_currency').exist? ? Pathname(FILEBASE + '/default_currency').read.chomp : '$'
|
19
19
|
COMMANDS = %w(add sort tag clear open)
|
20
|
+
SETUP_FILES = %w(transactions.dat accounts.dat budgets.dat aliases.dat commodities.dat setup.dat ledger.dat ldgr.yaml)
|
21
|
+
CONFIG_FILE = Pathname(FILEBASE + 'ldgr.yaml')
|
20
22
|
|
21
23
|
def self.parse
|
22
24
|
cli = OptionParser.new do |o|
|
@@ -51,8 +53,8 @@ module Ldgr
|
|
51
53
|
t.payee = config.fetch(:payee) { |key| error_policy.call(key) }
|
52
54
|
t.account = config.fetch(:account) { |key| error_policy.call(key) }
|
53
55
|
t.amount = config.fetch(:amount) { |key| error_policy.call(key) }
|
54
|
-
t.currency = config.fetch(:currency) {
|
55
|
-
t.equity = config.fetch(:equity) {
|
56
|
+
t.currency = config.fetch(:currency) { defaults.fetch('currency') { '$' } }
|
57
|
+
t.equity = config.fetch(:equity) { defaults.fetch('equity') { 'Cash' } }
|
56
58
|
t.cleared = config[:cleared] ? '* ' : ''
|
57
59
|
t.date = date == effective ? date : date << '=' << effective
|
58
60
|
end
|
@@ -136,17 +138,24 @@ module Ldgr
|
|
136
138
|
open_file(ARGV[1])
|
137
139
|
end
|
138
140
|
|
141
|
+
def self.defaults
|
142
|
+
defaults_hash = {}
|
143
|
+
defaults_hash.merge(YAML.load_file(CONFIG_FILE).to_h)
|
144
|
+
end
|
145
|
+
|
139
146
|
def self.setup
|
140
147
|
unless config_exist?
|
141
148
|
FileUtils.mkdir_p(FILEBASE)
|
142
|
-
|
149
|
+
SETUP_FILES.each do |file|
|
143
150
|
FileUtils.touch("#{FILEBASE}#{file}")
|
144
151
|
end
|
145
152
|
end
|
146
153
|
end
|
147
154
|
|
148
155
|
def self.config_exist?
|
149
|
-
|
156
|
+
SETUP_FILES.each do |file|
|
157
|
+
return false unless Pathname("#{FILEBASE}#{file}").exist?
|
158
|
+
end
|
150
159
|
true
|
151
160
|
end
|
152
161
|
|
data/lib/ldgr/version.rb
CHANGED