thefox-wallet 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +4 -5
- data/Gemfile +8 -0
- data/Makefile +7 -2
- data/Makefile.common +8 -6
- data/README.md +1 -1
- data/bin/dev +12 -0
- data/bin/wallet +35 -22
- data/lib/wallet/command.rb +6 -2
- data/lib/wallet/command_add.rb +7 -4
- data/lib/wallet/command_categories.rb +1 -3
- data/lib/wallet/command_csv.rb +5 -4
- data/lib/wallet/command_html.rb +10 -3
- data/lib/wallet/command_list.rb +38 -30
- data/lib/wallet/entry.rb +2 -2
- data/lib/wallet/version.rb +2 -2
- data/lib/wallet/wallet.rb +180 -176
- data/thefox-wallet.gemspec +2 -1
- metadata +20 -6
- data/bin/.gitignore +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbb979259e323ea7267d725982ce79a4031b915
|
4
|
+
data.tar.gz: 97e01ebf34e7fe376b1898fc4154527f64e41f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbb7973fbd8bbe143409c33d2c329480e04d4acb20bfbedd31ce3fce400e3c9856174c9b715bccc2dc4595971d1253dbf95a2d62701f4deb037ce61e50948e8e
|
7
|
+
data.tar.gz: 9be10133bac53c6b17ad37905345517c408f9b1d0b1b1a68b957820ce0c436dc94b83075211f53d9563a5881fd6c6c337911d06866132311a108e965564fc0bf
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
before_script:
|
2
|
-
- ruby -v
|
3
2
|
- gem update --system
|
4
3
|
- gem install bundler -v '~>1.13'
|
5
4
|
- bundler --version
|
@@ -14,7 +13,7 @@ test_21:
|
|
14
13
|
stage: test
|
15
14
|
environment: test
|
16
15
|
only:
|
17
|
-
-
|
16
|
+
- tags
|
18
17
|
script:
|
19
18
|
- make test
|
20
19
|
|
@@ -23,7 +22,7 @@ test_22:
|
|
23
22
|
stage: test
|
24
23
|
environment: test
|
25
24
|
only:
|
26
|
-
-
|
25
|
+
- tags
|
27
26
|
script:
|
28
27
|
- make test
|
29
28
|
|
@@ -32,14 +31,14 @@ test_23:
|
|
32
31
|
stage: test
|
33
32
|
environment: test
|
34
33
|
only:
|
35
|
-
-
|
34
|
+
- tags
|
36
35
|
script:
|
37
36
|
- make test
|
38
37
|
|
39
38
|
release_gem:
|
40
39
|
image: ruby:2.3
|
41
40
|
stage: release
|
42
|
-
environment:
|
41
|
+
environment: gem
|
43
42
|
only:
|
44
43
|
- tags
|
45
44
|
script:
|
data/Gemfile
CHANGED
data/Makefile
CHANGED
@@ -3,6 +3,10 @@ GEM_NAME = thefox-wallet
|
|
3
3
|
|
4
4
|
include Makefile.common
|
5
5
|
|
6
|
+
.PHONY: dev
|
7
|
+
dev:
|
8
|
+
$(BUNDLER) exec ./bin/wallet -w wallet_test2 add -t 'test' -e 5 -c 'test'
|
9
|
+
|
6
10
|
.PHONY: test
|
7
11
|
test:
|
8
12
|
RUBYOPT=-w $(BUNDLER) exec ./test/suite_all.rb -v
|
@@ -11,5 +15,6 @@ test:
|
|
11
15
|
cov:
|
12
16
|
RUBYOPT=-w TZ=Europe/Vienna COVERAGE=1 $(BUNDLER) exec ./test/suite_all.rb -v
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
.PHONY: cov_local
|
19
|
+
cov_local:
|
20
|
+
RUBYOPT=-w TZ=Europe/Vienna SIMPLECOV_PHPUNIT_LOAD_PATH=../simplecov-phpunit COVERAGE=1 $(BUNDLER) exec ./test/suite_all.rb -v
|
data/Makefile.common
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
|
2
|
-
# Ruby Common Big
|
3
|
-
# 2016-05-20
|
2
|
+
# Ruby Common Big 2016-11-08
|
4
3
|
|
5
4
|
MV = mv -nv
|
6
5
|
RM = rm -rfd
|
7
6
|
MKDIR = mkdir -p
|
8
7
|
CHMOD = chmod
|
9
|
-
BUNDLER =
|
8
|
+
BUNDLER = bundler
|
10
9
|
BUNDLER_OPTIONS = --jobs=5 --retry=3
|
11
10
|
GEMSPEC_FILE = $(GEM_NAME).gemspec
|
12
11
|
|
@@ -17,18 +16,21 @@ all: setup $(ALL_TARGETS_EXT)
|
|
17
16
|
setup: .setup
|
18
17
|
|
19
18
|
.setup:
|
19
|
+
which ruby &> /dev/null
|
20
|
+
which $(BUNDLER) &> /dev/null
|
21
|
+
ruby -v
|
20
22
|
$(BUNDLER) install $(BUNDLER_OPTIONS)
|
21
23
|
touch $@
|
22
24
|
|
23
25
|
.PHONY: install
|
24
26
|
install:
|
25
|
-
gem_file=$$(gem build $(GEMSPEC_FILE) | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
|
26
|
-
|
27
|
+
gem_file=$$(gem build $(GEMSPEC_FILE) 2> /dev/null | grep 'File:' | tail -1 | awk '{ print $$2 }'); \
|
28
|
+
gem install $$gem_file; \
|
27
29
|
$(RM) $$gem_file
|
28
30
|
|
29
31
|
.PHONY: uninstall
|
30
32
|
uninstall:
|
31
|
-
|
33
|
+
gem uninstall $(GEM_NAME)
|
32
34
|
|
33
35
|
.PHONY: update
|
34
36
|
update:
|
data/README.md
CHANGED
data/bin/dev
ADDED
data/bin/wallet
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
+
require 'pathname'
|
5
|
+
require 'logger'
|
6
|
+
require 'date'
|
4
7
|
require 'wallet'
|
5
|
-
require 'tempfile'
|
6
8
|
|
7
|
-
|
9
|
+
@logger = Logger.new(STDOUT)
|
10
|
+
@logger.level = Logger::INFO
|
11
|
+
|
12
|
+
@options = Hash.new
|
13
|
+
@options[:logger] = @logger
|
8
14
|
opts = OptionParser.new do |o|
|
9
15
|
o.banner = 'Usage: wallet <command> [options]'
|
10
16
|
o.separator('')
|
@@ -19,64 +25,71 @@ opts = OptionParser.new do |o|
|
|
19
25
|
o.separator('')
|
20
26
|
|
21
27
|
o.on('-w', '--wallet <path>', 'Path to wallet directory.') do |path|
|
22
|
-
options[:wallet_path] = path
|
28
|
+
@options[:wallet_path] = Pathname.new(path).expand_path
|
23
29
|
end
|
24
30
|
|
25
31
|
o.on('--id <id>', 'ID used for the entry.') do |id|
|
26
|
-
options[:entry_id] = id
|
32
|
+
@options[:entry_id] = id
|
27
33
|
end
|
28
34
|
|
29
35
|
o.on('-t', '--title <title>', 'Title used for the entry.') do |title|
|
30
|
-
options[:entry_title] = title
|
36
|
+
@options[:entry_title] = title
|
31
37
|
end
|
32
38
|
|
33
39
|
o.on('-d', '--date <date>', 'Date used for the entry.') do |date|
|
34
|
-
|
35
|
-
|
40
|
+
@options[:entry_date] = date
|
41
|
+
end
|
42
|
+
|
43
|
+
o.on('--start <date>', 'Start date used for a range.') do |date|
|
44
|
+
@options[:entry_date_start] = Date.parse(date)
|
36
45
|
end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
47
|
+
o.on('--end <date>', 'End date used for a range.') do |date|
|
48
|
+
@options[:entry_date_end] = Date.parse(date)
|
49
|
+
end
|
41
50
|
|
42
51
|
o.on('-r', '--revenue <revenue>', 'Revenue used for the entry.') do |revenue|
|
43
|
-
options[:entry_revenue] = revenue.to_s.sub(/,/, '.').to_f.abs
|
52
|
+
@options[:entry_revenue] = revenue.to_s.sub(/,/, '.').to_f.abs
|
44
53
|
end
|
45
54
|
|
46
55
|
o.on('-e', '--expense <expense>', 'Expense used for the entry.') do |expense|
|
47
|
-
options[:entry_expense] = -expense.to_s.sub(/,/, '.').to_f.abs
|
56
|
+
@options[:entry_expense] = -expense.to_s.sub(/,/, '.').to_f.abs
|
48
57
|
end
|
49
58
|
|
50
59
|
o.on('-c', '--category <category>', 'Category used for the entry.') do |category|
|
51
|
-
options[:entry_category] = category
|
60
|
+
@options[:entry_category] = category
|
52
61
|
end
|
53
62
|
|
54
63
|
o.on('-o', '--comment <comment>', 'Comment used for the entry.') do |comment|
|
55
|
-
options[:entry_comment] = comment
|
64
|
+
@options[:entry_comment] = comment
|
56
65
|
end
|
57
66
|
|
58
67
|
o.on('--import', 'Import') do
|
59
|
-
options[:is_import] = true
|
68
|
+
@options[:is_import] = true
|
60
69
|
end
|
61
70
|
|
62
71
|
o.on('--export', 'Export') do
|
63
|
-
options[:is_export] = true
|
72
|
+
@options[:is_export] = true
|
64
73
|
end
|
65
74
|
|
66
75
|
o.on('-p', '--path <path>', 'Path used for csv import/export.') do |path|
|
67
|
-
options[:path] = path
|
76
|
+
@options[:path] = path
|
68
77
|
end
|
69
78
|
|
70
79
|
o.on('-i', '--interactive', 'Use some commands interactively.') do
|
71
|
-
options[:is_interactively] = true
|
80
|
+
@options[:is_interactively] = true
|
72
81
|
end
|
73
82
|
|
74
83
|
o.on('-f', '--force', 'Force add command.') do
|
75
|
-
options[:force] = true
|
84
|
+
@options[:force] = true
|
76
85
|
end
|
77
86
|
|
78
87
|
o.on('--no-force', 'Do not force add command.') do
|
79
|
-
options[:force] = false
|
88
|
+
@options[:force] = false
|
89
|
+
end
|
90
|
+
|
91
|
+
o.on('-v', '--verbose', 'Log on debug level.') do
|
92
|
+
@logger.level = Logger::DEBUG
|
80
93
|
end
|
81
94
|
|
82
95
|
o.on_tail('-V', '--version', 'Show version.') do
|
@@ -97,10 +110,10 @@ command_name = commands.shift
|
|
97
110
|
|
98
111
|
if command_name
|
99
112
|
begin
|
100
|
-
command = TheFox::Wallet::Command.create_by_name(command_name, options)
|
113
|
+
command = TheFox::Wallet::Command.create_by_name(command_name, @options)
|
101
114
|
command.run
|
102
115
|
rescue Exception => e
|
103
|
-
|
116
|
+
@logger.error(e.to_s)
|
104
117
|
exit 1
|
105
118
|
end
|
106
119
|
else
|
data/lib/wallet/command.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'date'
|
3
|
-
|
3
|
+
require 'pathname'
|
4
4
|
|
5
5
|
module TheFox::Wallet
|
6
6
|
|
@@ -10,10 +10,14 @@ module TheFox::Wallet
|
|
10
10
|
|
11
11
|
def initialize(options = Hash.new)
|
12
12
|
@options = options || Hash.new
|
13
|
-
@options[:
|
13
|
+
@options[:logger] ||= nil
|
14
|
+
|
15
|
+
@options[:wallet_path] ||= Pathname.new('wallet')
|
14
16
|
@options[:entry_id] ||= nil
|
15
17
|
@options[:entry_title] ||= nil
|
16
18
|
@options[:entry_date] ||= Date.today.to_s
|
19
|
+
@options[:entry_date_start] ||= Date.parse('1970-01-01')
|
20
|
+
@options[:entry_date_end] ||= Date.today
|
17
21
|
@options[:entry_revenue] ||= 0.0
|
18
22
|
@options[:entry_expense] ||= 0.0
|
19
23
|
@options[:entry_category] ||= nil
|
data/lib/wallet/command_add.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
|
2
|
+
require 'date'
|
3
|
+
|
2
4
|
module TheFox::Wallet
|
5
|
+
|
3
6
|
class AddCommand < Command
|
4
7
|
|
5
8
|
NAME = 'add'
|
@@ -57,10 +60,10 @@ module TheFox::Wallet
|
|
57
60
|
|
58
61
|
puts "id: '#{@options[:entry_id]}'"
|
59
62
|
puts "title: '#{@options[:entry_title]}'"
|
60
|
-
puts "date: "
|
61
|
-
puts "revenue: "
|
62
|
-
puts "expense: "
|
63
|
-
puts "balance: "
|
63
|
+
puts "date: " << Date.parse(@options[:entry_date]).to_s
|
64
|
+
puts "revenue: " << NUMBER_FORMAT % @options[:entry_revenue]
|
65
|
+
puts "expense: " << NUMBER_FORMAT % @options[:entry_expense]
|
66
|
+
puts "balance: " << NUMBER_FORMAT % [@options[:entry_revenue] + @options[:entry_expense]]
|
64
67
|
puts "category: #{@options[:entry_category]}"
|
65
68
|
puts "comment: '#{@options[:entry_comment]}'"
|
66
69
|
puts "force: #{@options[:force] ? 'YES' : 'NO'}"
|
data/lib/wallet/command_csv.rb
CHANGED
@@ -11,15 +11,16 @@ module TheFox::Wallet
|
|
11
11
|
end
|
12
12
|
|
13
13
|
wallet = Wallet.new(@options[:wallet_path])
|
14
|
+
wallet.logger = @options[:logger]
|
14
15
|
|
15
16
|
if @options[:is_import] || !@options[:is_export]
|
16
|
-
|
17
|
+
@options[:logger].info("import csv #{@options[:path]} ...") if @options[:logger]
|
17
18
|
wallet.import_csv_file(@options[:path])
|
18
|
-
|
19
|
+
@options[:logger].info("import csv #{@options[:path]} done") if @options[:logger]
|
19
20
|
elsif @options[:is_export]
|
20
|
-
|
21
|
+
@options[:logger].info("export csv #{@options[:path]} ...") if @options[:logger]
|
21
22
|
wallet.export_csv_file(@options[:path])
|
22
|
-
|
23
|
+
@options[:logger].info("export csv #{@options[:path]} done") if @options[:logger]
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
data/lib/wallet/command_html.rb
CHANGED
@@ -7,9 +7,16 @@ module TheFox::Wallet
|
|
7
7
|
|
8
8
|
def run
|
9
9
|
wallet = Wallet.new(@options[:wallet_path])
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
wallet.logger = @options[:logger]
|
11
|
+
|
12
|
+
html_path = Pathname.new('html').expand_path(wallet.dir_path)
|
13
|
+
if @options[:path]
|
14
|
+
html_path = Pathname.new(@options[:path]).expand_path
|
15
|
+
end
|
16
|
+
|
17
|
+
@options[:logger].info("generate html to #{html_path} ...") if @options[:logger]
|
18
|
+
wallet.gen_html(html_path, @options[:entry_date_start], @options[:entry_date_end], @options[:entry_category])
|
19
|
+
@options[:logger].info('generate html done') if @options[:logger]
|
13
20
|
end
|
14
21
|
|
15
22
|
end
|
data/lib/wallet/command_list.rb
CHANGED
@@ -78,23 +78,27 @@ module TheFox::Wallet
|
|
78
78
|
comment_l = 25
|
79
79
|
end
|
80
80
|
|
81
|
-
entries_f =
|
82
|
-
title_f =
|
83
|
-
revenue_f =
|
84
|
-
expense_f =
|
85
|
-
balance_f =
|
86
|
-
category_f =
|
87
|
-
comment_f =
|
81
|
+
entries_f = "%#{entries_l}s"
|
82
|
+
title_f = "%-#{title_l}s"
|
83
|
+
revenue_f = "%#{revenue_l}s"
|
84
|
+
expense_f = "%#{expense_l}s"
|
85
|
+
balance_f = "%#{balance_l}s"
|
86
|
+
category_f = "%-#{category_l}s"
|
87
|
+
comment_f = "%-#{comment_l}s"
|
88
88
|
|
89
89
|
header = ''
|
90
|
-
header
|
91
|
-
header
|
92
|
-
header
|
93
|
-
header
|
94
|
-
header
|
95
|
-
header
|
96
|
-
|
97
|
-
|
90
|
+
header << '#' * entries_l << ' '
|
91
|
+
header << 'Date ' << ' ' * 7
|
92
|
+
header << title_f % 'Title' << ' '
|
93
|
+
header << revenue_f % 'Revenue' << ' '
|
94
|
+
header << expense_f % 'Expense' << ' '
|
95
|
+
header << balance_f % 'Balance'
|
96
|
+
if has_category_col
|
97
|
+
header << ' ' << category_f % 'Category'
|
98
|
+
end
|
99
|
+
if has_comment_col
|
100
|
+
header << ' ' << comment_f % 'Comment'
|
101
|
+
end
|
98
102
|
|
99
103
|
header_l = header.length
|
100
104
|
header.sub!(/ +$/, '')
|
@@ -111,7 +115,9 @@ module TheFox::Wallet
|
|
111
115
|
entry_no += 1
|
112
116
|
|
113
117
|
title = entry['title']
|
114
|
-
|
118
|
+
if title.length >= 25
|
119
|
+
title = title[0, 22] << '...'
|
120
|
+
end
|
115
121
|
|
116
122
|
revenue_total += entry['revenue']
|
117
123
|
expense_total += entry['expense']
|
@@ -121,17 +127,19 @@ module TheFox::Wallet
|
|
121
127
|
# has_category = category != ''
|
122
128
|
|
123
129
|
comment = entry['comment']
|
124
|
-
|
130
|
+
if comment.length >= 25
|
131
|
+
comment = comment[0, 22] << '...'
|
132
|
+
end
|
125
133
|
|
126
134
|
out = ''
|
127
|
-
out
|
128
|
-
out
|
129
|
-
out
|
130
|
-
out
|
131
|
-
out
|
132
|
-
out
|
133
|
-
out
|
134
|
-
out
|
135
|
+
out << entries_f % entry_no
|
136
|
+
out << ' ' << '%10s' % (entry['date'] == previous_date ? '' : entry['date'])
|
137
|
+
out << ' ' << title_f % title
|
138
|
+
out << ' ' << revenue_f % (NUMBER_FORMAT % entry['revenue'])
|
139
|
+
out << ' ' << expense_f % (NUMBER_FORMAT % entry['expense'])
|
140
|
+
out << ' ' << balance_f % (NUMBER_FORMAT % entry['balance'])
|
141
|
+
out << ' ' << category_f % category if has_category_col
|
142
|
+
out << ' ' << comment_f % comment if has_comment_col
|
135
143
|
|
136
144
|
out.sub!(/ +$/, '')
|
137
145
|
puts out
|
@@ -142,11 +150,11 @@ module TheFox::Wallet
|
|
142
150
|
puts
|
143
151
|
|
144
152
|
out = ''
|
145
|
-
out
|
146
|
-
out
|
147
|
-
out
|
148
|
-
out
|
149
|
-
out
|
153
|
+
out << ' ' * (12 + entries_l)
|
154
|
+
out << ' ' << title_f % 'TOTAL'
|
155
|
+
out << ' ' << revenue_f % (NUMBER_FORMAT % revenue_total)
|
156
|
+
out << ' ' << expense_f % (NUMBER_FORMAT % expense_total)
|
157
|
+
out << ' ' << balance_f % (NUMBER_FORMAT % balance_total)
|
150
158
|
puts out
|
151
159
|
end
|
152
160
|
|
data/lib/wallet/entry.rb
CHANGED
@@ -78,7 +78,7 @@ module TheFox
|
|
78
78
|
revenue_t = revenue.to_f
|
79
79
|
|
80
80
|
if revenue_t < 0
|
81
|
-
raise RangeError,
|
81
|
+
raise RangeError, "revenue (#{revenue_t}) cannot be < 0. use expense instead!"
|
82
82
|
end
|
83
83
|
|
84
84
|
@revenue = revenue_t
|
@@ -89,7 +89,7 @@ module TheFox
|
|
89
89
|
expense_t = expense.to_f
|
90
90
|
|
91
91
|
if expense_t > 0
|
92
|
-
raise RangeError,
|
92
|
+
raise RangeError, "expense (#{expense_t}) cannot be > 0. use revenue instead!"
|
93
93
|
end
|
94
94
|
|
95
95
|
@expense = expense_t
|