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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28d904e9b9e8cb5832fad842b351741e6d38771b
4
- data.tar.gz: 040151e2ca4142af1549f83b59f44e27adfd3aaf
3
+ metadata.gz: c8c6866c2d4d40abc43e7a8e8ea43c58b7c84fd6
4
+ data.tar.gz: d61e4c679154b467de16b50690614bde21541a72
5
5
  SHA512:
6
- metadata.gz: 856d4e4cad9b6f3ca8606fb87d5616b4fbf6fcbd1081413153427f4c6de934e6f062bc7309cc3c6390d6e4050aff24a809c7f865033e4620a5ebe66fc839ace1
7
- data.tar.gz: 96c1afabba60d90737cc83f922c4f7f6535f044ec254a1496fb604d20630b3f4fdc479b34c16151dab78fb5c3afaa7c53dd906a9b6f2fb0304d384e728d48c9c
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
- ## Usage
36
+ ## Customization
37
37
 
38
- Type `ldgr -h` at the command-line to see available commands and options.
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) { DEFAULT_CURRENCY }
55
- t.equity = config.fetch(:equity) { "Cash" }
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
- %w(transactions.dat accounts.dat budgets.dat aliases.dat commodities.dat setup.dat ledger.dat).each do |file|
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
- return false unless Pathname(FILEBASE).exist?
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
@@ -1,3 +1,3 @@
1
1
  module Ldgr
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Pittman