thefox-wallet 0.8.2 → 0.9.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/Makefile +3 -0
- data/Makefile.common +3 -3
- data/README.md +1 -0
- data/bin/wallet +227 -191
- data/lib/wallet/entry.rb +3 -3
- data/lib/wallet/version.rb +3 -2
- data/lib/wallet/wallet.rb +40 -34
- data/thefox-wallet.gemspec +0 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b777e3c55bf57dfcef12a6f140f714b53ac43b91
|
4
|
+
data.tar.gz: 8c889702061c3f94edd2853d7f790233d4f1262c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5658968fafe93f915466bc7f76dea49fb15b30fb6773ba6f41436a3512c3602c0b692ddc943423aef9fb1ef3b075f60c95971e86399acea52a09794e5a584e3
|
7
|
+
data.tar.gz: 300e6b51667e753e5fac037e8f9d34c56a4c90b726baa9954ef40a3098e911dc142ed826f7e38dbe1ea2cf230426de6a8f047e2534a82b8f4f8059867fb5993d
|
data/Makefile
CHANGED
data/Makefile.common
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
# Ruby Common Big
|
3
|
-
#
|
3
|
+
# 2016-02-14
|
4
4
|
|
5
5
|
MV = mv -nv
|
6
6
|
RM = rm -rf
|
@@ -9,8 +9,8 @@ BUNDLER = bundle
|
|
9
9
|
BUNDLER_OPTIONS = --jobs=5 --retry=3
|
10
10
|
GEMSPEC_FILE = $(GEM_NAME).gemspec
|
11
11
|
|
12
|
-
.PHONY: all
|
13
|
-
all: setup
|
12
|
+
.PHONY: all
|
13
|
+
all: setup $(ALL_TARGETS_EXT)
|
14
14
|
|
15
15
|
.PHONY: setup
|
16
16
|
setup: .setup
|
data/README.md
CHANGED
data/bin/wallet
CHANGED
@@ -1,205 +1,219 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'pp'
|
4
|
+
require 'optparse'
|
4
5
|
require 'wallet'
|
5
|
-
require 'ArgsParser'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
parser.bind(:wallet, :w, 'Wallet', 'wallet')
|
10
|
-
parser.bind(:title, :t, 'Title')
|
11
|
-
parser.bind(:date, :d, 'Date', Date.today.to_s)
|
12
|
-
parser.bind(:revenue, :r, 'Revenue', 0)
|
13
|
-
parser.bind(:expense, :e, 'Expense', 0)
|
14
|
-
parser.bind(:category, :c, 'Category')
|
15
|
-
parser.bind(:comment, :o, 'Comment')
|
16
|
-
parser.bind(:path, :p, 'Path')
|
17
|
-
|
18
|
-
command, params = parser.parse(ARGV)
|
19
|
-
command = command.to_s
|
20
|
-
|
21
|
-
# puts 'command: ' + command.to_s
|
22
|
-
# puts 'params: ' + params.to_s
|
23
|
-
# puts
|
24
|
-
|
25
|
-
# Command Aliases
|
26
|
-
if command == 'i'
|
27
|
-
command = 'int'
|
28
|
-
elsif command == 'l'
|
29
|
-
command = 'list'
|
30
|
-
elsif command == 'lc'
|
31
|
-
command = 'cat'
|
32
|
-
end
|
33
|
-
|
34
|
-
wallet = params[:wallet].to_s
|
35
|
-
title = params[:title].to_s
|
36
|
-
date = params[:date].to_s
|
37
|
-
revenue = params[:revenue].to_s.gsub('.', '').sub(/,/, '.').to_f.round(3).abs
|
38
|
-
category = params[:category].to_s
|
39
|
-
comment = params[:comment].to_s
|
40
|
-
path = params[:path].to_s
|
41
|
-
import = params[:i]
|
42
|
-
|
43
|
-
path_is_temp = false
|
44
|
-
|
45
|
-
expense = 0.0
|
46
|
-
export = false
|
47
|
-
if params[:expense].is_a? TrueClass
|
48
|
-
export = true
|
49
|
-
else
|
50
|
-
expense = -params[:expense].to_s.gsub('.', '').sub(/,/, '.').to_f.round(3).abs
|
51
|
-
end
|
52
|
-
|
53
|
-
# puts 'argv len: ' + ARGV.length.to_s
|
54
|
-
# puts 'command: ' + '%-10s' % command.class.to_s + ' "' + command.to_s + '"'
|
55
|
-
# puts 'wallet: ' + '%-10s' % wallet.class.to_s + ' "' + wallet.to_s + '"'
|
56
|
-
# puts 'title: ' + '%-10s' % title.class.to_s + ' "' + title + '"'
|
57
|
-
# puts 'date: ' + '%-10s' % date.class.to_s + ' "' + date + '"'
|
58
|
-
# puts 'revenue: ' + '%-10s' % revenue.class.to_s + ' "' + revenue.to_s + '"'
|
59
|
-
# puts 'expense: ' + '%-10s' % expense.class.to_s + ' "' + expense.to_s + '"'
|
60
|
-
# puts 'category: ' + '%-10s' % category.class.to_s + ' "' + category + '"'
|
61
|
-
# puts 'comment: ' + '%-10s' % comment.class.to_s + ' "' + comment.to_s + '"'
|
62
|
-
# puts 'path: ' + '%-10s' % path.class.to_s + ' "' + path.to_s + '"'
|
63
|
-
# puts
|
64
|
-
|
65
|
-
if command == 'help' || command.length == 0
|
66
|
-
script_name = File.basename(__FILE__)
|
67
|
-
padding = ' ' * (script_name.length + 8)
|
7
|
+
options = {
|
8
|
+
:wallet_path => 'wallet',
|
68
9
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
puts padding + 'l|list List entries'
|
77
|
-
puts padding + 'lc|cat List categories'
|
78
|
-
puts padding + 'html Generate HTML files'
|
79
|
-
puts padding + 'csv Import/Export CSV file'
|
80
|
-
puts padding + 'vi Import per VIM editor'
|
81
|
-
puts
|
82
|
-
puts 'Options:'
|
83
|
-
puts padding + '-w|--wallet PATH Optional'
|
84
|
-
puts padding + '-t|--title TITLE Required for command "add"'
|
85
|
-
puts padding + '-d|--date Optional'
|
86
|
-
puts padding + '-r|--revenue Optional. Default: 0'
|
87
|
-
puts padding + '-e|--expense Optional. Default: 0'
|
88
|
-
puts padding + '-c|--category Optional. Default: default'
|
89
|
-
puts padding + '-o|--comment Optional'
|
90
|
-
puts padding + '-i|-e Import or Export. Default: -i'
|
91
|
-
puts padding + '-p|--path PATH Required for command "csv"'
|
92
|
-
|
93
|
-
exit 3
|
94
|
-
end
|
95
|
-
|
96
|
-
if command == 'int'
|
97
|
-
command = 'add'
|
10
|
+
:entry_title => nil,
|
11
|
+
:entry_date => Date.today.to_s,
|
12
|
+
#:entry_end_date => nil,
|
13
|
+
:entry_revenue => 0.0,
|
14
|
+
:entry_expense => 0.0,
|
15
|
+
:entry_category => nil,
|
16
|
+
:entry_comment => nil,
|
98
17
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
18
|
+
:is_import => false,
|
19
|
+
:is_export => false,
|
20
|
+
:path => nil,
|
21
|
+
:is_interactively => false,
|
22
|
+
}
|
23
|
+
balance = 0.0
|
24
|
+
opts = OptionParser.new do |o|
|
25
|
+
o.banner = 'Usage: wallet <command> [options]'
|
26
|
+
o.separator('')
|
27
|
+
o.separator('Commands:')
|
28
|
+
o.separator('')
|
29
|
+
o.separator(' add Add a new entry')
|
30
|
+
o.separator(' list List entries')
|
31
|
+
o.separator(' categories List categories')
|
32
|
+
o.separator(' html Generate HTML files')
|
33
|
+
o.separator(' csv Import/Export CSV file')
|
34
|
+
o.separator(' vi Import per VIM editor')
|
35
|
+
o.separator('')
|
36
|
+
|
37
|
+
o.on('-w', '--wallet <path>', 'Path to wallet directory.') do |path|
|
38
|
+
options[:wallet_path] = path
|
103
39
|
end
|
104
40
|
|
105
|
-
|
106
|
-
|
107
|
-
if date_t.length > 0
|
108
|
-
date = date_t
|
41
|
+
o.on('-t', '--title <title>', 'Title used for the entry.') do |title|
|
42
|
+
options[:entry_title] = title
|
109
43
|
end
|
110
44
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
revenue = revenue_t.to_s.gsub('.', '').sub(/,/, '.').to_f.round(3).abs
|
45
|
+
o.on('-d', '--date <date>', 'Date used for the entry.') do |date|
|
46
|
+
#o.on('-d', '--date <date>', 'Start date or date used for the entry.') do |date|
|
47
|
+
options[:entry_date] = date
|
115
48
|
end
|
116
49
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
50
|
+
#o.on('-z', '--end <date>', 'End date.') do |date|
|
51
|
+
# options[:entry_end_date] = date
|
52
|
+
#end
|
53
|
+
|
54
|
+
o.on('-r', '--revenue <revenue>', 'Revenue used for the entry.') do |revenue|
|
55
|
+
options[:entry_revenue] = revenue.to_s.sub(/,/, '.').to_f.abs
|
56
|
+
balance += options[:entry_revenue]
|
121
57
|
end
|
122
58
|
|
123
|
-
|
124
|
-
|
59
|
+
o.on('-e', '--expense <expense>', 'Expense used for the entry.') do |expense|
|
60
|
+
options[:entry_expense] = -expense.to_s.sub(/,/, '.').to_f.abs
|
61
|
+
balance += options[:entry_expense]
|
125
62
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
category = category_t
|
63
|
+
|
64
|
+
o.on('-c', '--category <category>', 'Category used for the entry.') do |category|
|
65
|
+
options[:entry_category] = category
|
130
66
|
end
|
131
67
|
|
132
|
-
|
133
|
-
|
134
|
-
if comment_t.length > 0
|
135
|
-
comment = comment_t
|
68
|
+
o.on('-o', '--comment <comment>', 'Comment used for the entry.') do |comment|
|
69
|
+
options[:entry_comment] = comment
|
136
70
|
end
|
137
71
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
vi_file.puts('# This is a comment line.')
|
142
|
-
vi_file.puts('# Date,Title,Revenue,Expense,Category,Comment')
|
143
|
-
vi_file.puts('# Date,Title,Expense')
|
144
|
-
vi_file.close
|
72
|
+
o.on('--import', 'Import') do
|
73
|
+
options[:is_import] = true
|
74
|
+
end
|
145
75
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
sleep 1
|
76
|
+
o.on('--export', 'Export') do
|
77
|
+
options[:is_export] = true
|
78
|
+
end
|
150
79
|
|
151
|
-
|
152
|
-
|
80
|
+
o.on('-p', '--path <path>', 'Path used for csv import/export.') do |path|
|
81
|
+
options[:path] = path
|
82
|
+
end
|
83
|
+
|
84
|
+
o.on('-i', 'Use some commands interactively.') do
|
85
|
+
options[:is_interactively] = true
|
86
|
+
end
|
153
87
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
88
|
+
o.on_tail('-V', '--version', 'Show version.') do
|
89
|
+
puts "#{::TheFox::Wallet::NAME} #{::TheFox::Wallet::VERSION} (#{::TheFox::Wallet::DATE})"
|
90
|
+
puts TheFox::Wallet::HOMEPAGE
|
91
|
+
exit
|
92
|
+
end
|
158
93
|
|
159
|
-
|
94
|
+
o.on_tail('-h', '--help', 'Show this message.') do
|
95
|
+
puts o
|
96
|
+
puts
|
97
|
+
exit 3
|
98
|
+
end
|
160
99
|
end
|
100
|
+
ARGV << '-h' if ARGV.count == 0
|
101
|
+
commands = opts.parse(ARGV)
|
102
|
+
command = commands.shift
|
161
103
|
|
162
|
-
|
104
|
+
#pp commands
|
105
|
+
#pp command
|
163
106
|
|
164
|
-
|
165
|
-
|
166
|
-
|
107
|
+
case command
|
108
|
+
when 'add'
|
109
|
+
if options[:entry_category].nil?
|
110
|
+
options[:entry_category] = 'default'
|
111
|
+
end
|
112
|
+
if options[:is_interactively]
|
113
|
+
print "title: [#{options[:entry_title]}] "
|
114
|
+
title_t = STDIN.gets.strip
|
115
|
+
if title_t.length > 0
|
116
|
+
options[:entry_title] = title_t
|
117
|
+
end
|
118
|
+
|
119
|
+
print "date: [#{options[:entry_date]}] "
|
120
|
+
date_t = STDIN.gets.strip
|
121
|
+
if date_t.length > 0
|
122
|
+
options[:entry_date] = date_t
|
123
|
+
end
|
124
|
+
|
125
|
+
print "revenue: [#{options[:entry_revenue]}] "
|
126
|
+
revenue_t = STDIN.gets.strip
|
127
|
+
if revenue_t.length > 0
|
128
|
+
options[:entry_revenue] = revenue_t.to_s.sub(/,/, '.').to_f.round(TheFox::Wallet::NUMBER_ROUND).abs
|
129
|
+
end
|
130
|
+
|
131
|
+
print "expense: [#{options[:entry_expense]}] "
|
132
|
+
expense_t = STDIN.gets.strip
|
133
|
+
if expense_t.length > 0
|
134
|
+
options[:entry_expense] = -expense_t.to_s.sub(/,/, '.').to_f.round(TheFox::Wallet::NUMBER_ROUND).abs
|
135
|
+
end
|
136
|
+
|
137
|
+
print "category: [#{options[:entry_category]}] "
|
138
|
+
category_t = STDIN.gets.strip
|
139
|
+
if category_t.length > 0
|
140
|
+
options[:entry_category] = category_t
|
141
|
+
end
|
142
|
+
|
143
|
+
print "comment: [#{options[:entry_comment]}] "
|
144
|
+
comment_t = STDIN.gets.strip
|
145
|
+
if comment_t.length > 0
|
146
|
+
options[:entry_comment] = comment_t
|
147
|
+
end
|
148
|
+
|
149
|
+
puts '-' * 20
|
167
150
|
end
|
168
151
|
|
169
|
-
if
|
170
|
-
puts
|
152
|
+
if options[:entry_title].nil?
|
153
|
+
puts "ERROR: Option --title is required for command '#{command}'"
|
171
154
|
exit 1
|
172
155
|
end
|
173
156
|
|
174
|
-
puts
|
175
|
-
puts
|
176
|
-
puts
|
177
|
-
puts
|
178
|
-
puts
|
179
|
-
puts
|
180
|
-
puts
|
157
|
+
puts "title: '#{options[:entry_title]}'"
|
158
|
+
puts "date: " + Date.parse(options[:entry_date]).to_s
|
159
|
+
puts "revenue: " + TheFox::Wallet::NUMBER_FORMAT % options[:entry_revenue]
|
160
|
+
puts "expense: " + TheFox::Wallet::NUMBER_FORMAT % options[:entry_expense]
|
161
|
+
puts "balance: " + TheFox::Wallet::NUMBER_FORMAT % balance
|
162
|
+
puts "category: #{options[:entry_category]}"
|
163
|
+
puts "comment: '#{options[:entry_comment]}'"
|
181
164
|
|
182
|
-
|
183
|
-
|
165
|
+
entry = TheFox::Wallet::Entry.new(options[:entry_title], options[:entry_date], options[:entry_revenue], options[:entry_expense], options[:entry_category], options[:entry_comment])
|
166
|
+
wallet = TheFox::Wallet::Wallet.new(options[:wallet_path])
|
167
|
+
wallet.add(entry)
|
168
|
+
when 'list'
|
184
169
|
puts
|
185
170
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
}
|
171
|
+
wallet = TheFox::Wallet::Wallet.new(options[:wallet_path])
|
172
|
+
entries = wallet.entries(options[:entry_date], options[:entry_category].to_s)
|
173
|
+
#entries = wallet.entries(options[:entry_date], options[:entry_end_date], options[:entry_category].to_s)
|
190
174
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
175
|
+
entries_l = entries
|
176
|
+
.map{ |day_name, day_items| day_items.count }
|
177
|
+
.inject{ |sum, n| sum + n }
|
178
|
+
.to_s
|
179
|
+
.length
|
180
|
+
title_l = entries
|
181
|
+
.map{ |month_item| month_item[1].map{ |day_item| day_item['title'].length }}
|
182
|
+
.flatten
|
183
|
+
.max
|
184
|
+
.to_i
|
185
|
+
revenue_l = entries
|
186
|
+
.map{ |month_item| month_item[1].map{ |day_item| (TheFox::Wallet::NUMBER_FORMAT % day_item['revenue']).length } }
|
187
|
+
.flatten
|
188
|
+
.max
|
189
|
+
.to_i
|
190
|
+
expense_l = entries
|
191
|
+
.map{ |month_item| month_item[1].map{ |day_item| (TheFox::Wallet::NUMBER_FORMAT % day_item['expense']).length } }
|
192
|
+
.flatten
|
193
|
+
.max
|
194
|
+
.to_i
|
195
|
+
balance_l = entries
|
196
|
+
.map{ |month_item| month_item[1].map{ |day_item| (TheFox::Wallet::NUMBER_FORMAT % day_item['balance']).length } }
|
197
|
+
.flatten
|
198
|
+
.max
|
199
|
+
.to_i
|
200
|
+
category_l = entries
|
201
|
+
.map{ |month_item| month_item[1].map{ |day_item| day_item['category'].length } }
|
202
|
+
.flatten
|
203
|
+
.max
|
204
|
+
.to_i
|
205
|
+
comment_l = entries
|
206
|
+
.map{ |month_item| month_item[1].map{ |day_item| day_item['comment'].length } }
|
207
|
+
.flatten
|
208
|
+
.max
|
209
|
+
.to_i
|
200
210
|
|
201
211
|
has_category_col = entries.map{ |month_item| month_item[1].map{ |day_item| day_item['category'] } }.flatten.select{ |i| i != 'default' }.count > 0
|
202
|
-
has_comment_col = entries
|
212
|
+
has_comment_col = entries
|
213
|
+
.map{ |month_item| month_item[1].map{ |day_item| day_item['comment'] } }
|
214
|
+
.flatten
|
215
|
+
.select{ |i| i != '' }
|
216
|
+
.count > 0
|
203
217
|
|
204
218
|
if title_l < 6
|
205
219
|
title_l = 6
|
@@ -273,9 +287,9 @@ elsif command == 'list'
|
|
273
287
|
out += entries_f % entry_no
|
274
288
|
out += ' ' + '%10s' % (entry['date'] == previous_date ? '' : entry['date'])
|
275
289
|
out += ' ' + title_f % title
|
276
|
-
out += ' ' + revenue_f % (
|
277
|
-
out += ' ' + expense_f % (
|
278
|
-
out += ' ' + balance_f % (
|
290
|
+
out += ' ' + revenue_f % (TheFox::Wallet::NUMBER_FORMAT % entry['revenue'])
|
291
|
+
out += ' ' + expense_f % (TheFox::Wallet::NUMBER_FORMAT % entry['expense'])
|
292
|
+
out += ' ' + balance_f % (TheFox::Wallet::NUMBER_FORMAT % entry['balance'])
|
279
293
|
out += ' ' + category_f % category if has_category_col
|
280
294
|
out += ' ' + comment_f % comment if has_comment_col
|
281
295
|
|
@@ -290,38 +304,60 @@ elsif command == 'list'
|
|
290
304
|
out = ''
|
291
305
|
out += ' ' * (12 + entries_l)
|
292
306
|
out += ' ' + title_f % 'TOTAL'
|
293
|
-
out += ' ' + revenue_f % (
|
294
|
-
out += ' ' + expense_f % (
|
295
|
-
out += ' ' + balance_f % (
|
307
|
+
out += ' ' + revenue_f % (TheFox::Wallet::NUMBER_FORMAT % revenue_total)
|
308
|
+
out += ' ' + expense_f % (TheFox::Wallet::NUMBER_FORMAT % expense_total)
|
309
|
+
out += ' ' + balance_f % (TheFox::Wallet::NUMBER_FORMAT % balance_total)
|
296
310
|
puts out
|
297
|
-
|
311
|
+
when 'categories'
|
312
|
+
wallet = TheFox::Wallet::Wallet.new(options[:wallet_path])
|
298
313
|
categories = wallet.categories
|
299
|
-
puts
|
300
|
-
categories.
|
301
|
-
|
302
|
-
|
303
|
-
elsif command == 'html'
|
314
|
+
puts "categories: #{categories.count}"
|
315
|
+
puts "\t" + categories.join("\n\t")
|
316
|
+
when 'html'
|
317
|
+
wallet = TheFox::Wallet::Wallet.new(options[:wallet_path])
|
304
318
|
puts 'generate html to ' + wallet.html_path + ' ...'
|
305
319
|
wallet.gen_html
|
306
320
|
puts 'generate html done'
|
307
|
-
|
308
|
-
if
|
309
|
-
|
321
|
+
when 'csv'
|
322
|
+
if options[:is_interactively]
|
323
|
+
vi_file = Tempfile.create('wallet-vi-import', '/tmp')
|
324
|
+
vi_file.puts('# This is a comment line.')
|
325
|
+
vi_file.puts('# Date,Title,Revenue,Expense,Category,Comment')
|
326
|
+
vi_file.puts('# Date,Title,Expense')
|
327
|
+
vi_file.puts
|
328
|
+
vi_file.puts
|
329
|
+
vi_file.close
|
330
|
+
|
331
|
+
puts 'cwd: ' + Dir.pwd
|
332
|
+
puts 'editor: ' + ENV['EDITOR']
|
333
|
+
puts 'file: ' + vi_file.path
|
334
|
+
|
335
|
+
system("#{ENV['EDITOR']} #{vi_file.path}")
|
336
|
+
system("grep -v '#' #{vi_file.path} | grep -v ^$ > #{vi_file.path}.ok")
|
337
|
+
|
338
|
+
options[:path] = "#{vi_file.path}.ok"
|
339
|
+
File.unlink(vi_file.path)
|
340
|
+
end
|
341
|
+
|
342
|
+
if options[:path].nil?
|
343
|
+
puts "ERROR: Option --path is required for command '#{command}'"
|
310
344
|
exit 1
|
311
345
|
end
|
312
346
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
puts
|
347
|
+
wallet = TheFox::Wallet::Wallet.new(options[:wallet_path])
|
348
|
+
|
349
|
+
if options[:is_import] || !options[:is_export]
|
350
|
+
puts "import csv #{options[:path]} ..."
|
351
|
+
wallet.import_csv_file(options[:path])
|
352
|
+
puts "import csv #{options[:path]} done"
|
317
353
|
|
318
|
-
if
|
319
|
-
puts
|
320
|
-
File.unlink(path)
|
354
|
+
if options[:is_interactively]
|
355
|
+
puts "delete #{options[:path]}"
|
356
|
+
File.unlink(options[:path])
|
321
357
|
end
|
322
|
-
elsif
|
323
|
-
puts
|
324
|
-
wallet.export_csv_file
|
325
|
-
puts
|
358
|
+
elsif options[:is_export]
|
359
|
+
puts "export csv #{options[:path]} ..."
|
360
|
+
wallet.export_csv_file(options[:path])
|
361
|
+
puts "export csv #{options[:path]} done"
|
326
362
|
end
|
327
363
|
end
|
data/lib/wallet/entry.rb
CHANGED
@@ -40,9 +40,9 @@ module TheFox
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def date=(date)
|
43
|
-
if date.is_a?
|
43
|
+
if date.is_a?(String)
|
44
44
|
@date = Date.parse(date)
|
45
|
-
elsif date.is_a?
|
45
|
+
elsif date.is_a?(Date)
|
46
46
|
@date = date
|
47
47
|
else
|
48
48
|
raise ArgumentError, 'date must be a String or a Date instance'
|
@@ -94,7 +94,7 @@ module TheFox
|
|
94
94
|
private
|
95
95
|
|
96
96
|
def calc_balance
|
97
|
-
@balance = (@revenue.round(
|
97
|
+
@balance = (@revenue.round(NUMBER_ROUND) + @expense.round(NUMBER_ROUND)).to_f.round(NUMBER_ROUND)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
data/lib/wallet/version.rb
CHANGED
data/lib/wallet/wallet.rb
CHANGED
@@ -178,9 +178,9 @@ module TheFox
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
revenue = revenue.to_f.round(
|
182
|
-
expense = expense.to_f.round(
|
183
|
-
balance = (revenue + expense).round(
|
181
|
+
revenue = revenue.to_f.round(NUMBER_ROUND)
|
182
|
+
expense = expense.to_f.round(NUMBER_ROUND)
|
183
|
+
balance = (revenue + expense).round(NUMBER_ROUND)
|
184
184
|
|
185
185
|
diff = revenue + expense - balance
|
186
186
|
if diff != 0
|
@@ -198,57 +198,63 @@ module TheFox
|
|
198
198
|
sum(nil, nil, nil, category)
|
199
199
|
end
|
200
200
|
|
201
|
-
def entries(
|
202
|
-
|
203
|
-
|
204
|
-
day_f = '%02d' % day.to_i
|
201
|
+
def entries(begin_date, category = nil)
|
202
|
+
#def entries(year = nil, month = nil, day = nil, category = nil)
|
203
|
+
begin_year, begin_month, begin_day = begin_date.split('-').map{ |n| n.to_i }
|
205
204
|
|
206
|
-
|
207
|
-
|
205
|
+
begin_year_s = begin_year.to_i.to_s
|
206
|
+
begin_month_f = '%02d' % begin_month.to_i
|
207
|
+
begin_day_f = '%02d' % begin_day.to_i
|
208
|
+
|
209
|
+
glob = "#{@data_path}/month_"
|
210
|
+
if begin_year == nil && begin_month == nil
|
208
211
|
glob += '*.yml'
|
209
|
-
elsif
|
210
|
-
glob +=
|
211
|
-
elsif
|
212
|
-
glob +=
|
212
|
+
elsif begin_year && begin_month == nil
|
213
|
+
glob += "#{begin_year_s}_*.yml"
|
214
|
+
elsif begin_year && begin_month
|
215
|
+
glob += "#{begin_year_s}_#{begin_month_f}.yml"
|
213
216
|
end
|
214
217
|
|
218
|
+
category = category.to_s.downcase
|
219
|
+
|
215
220
|
# puts 'glob: ' + glob
|
216
|
-
# puts '
|
217
|
-
# puts '
|
218
|
-
# puts '
|
219
|
-
# puts 'category:
|
221
|
+
# puts 'begin_year: ' + '%-10s' % begin_year.class.to_s + ' = "' + begin_year.to_s + '"'
|
222
|
+
# puts 'begin_month: ' + '%-10s' % begin_month.class.to_s + ' = "' + begin_month.to_s + '"'
|
223
|
+
# puts 'begin_day: ' + '%-10s' % begin_day.class.to_s + ' = "' + begin_day.to_s + '"'
|
224
|
+
# puts 'category: ' + '%-10s' % category.class.to_s + ' = "' + category.to_s + '"'
|
220
225
|
# puts
|
221
226
|
|
222
227
|
entries_a = {}
|
223
228
|
Dir[glob].each do |file_path|
|
229
|
+
#puts "path: #{file_path}"
|
230
|
+
|
224
231
|
data = YAML.load_file(file_path)
|
225
|
-
if category.
|
226
|
-
if
|
227
|
-
day_key =
|
232
|
+
if category.length == 0
|
233
|
+
if begin_day
|
234
|
+
day_key = begin_year_s + '-' + begin_month_f + '-' + begin_day_f
|
228
235
|
if data['days'].has_key?(day_key)
|
229
236
|
entries_a[day_key] = data['days'][day_key]
|
230
237
|
end
|
231
238
|
else
|
232
|
-
entries_a.merge!
|
239
|
+
entries_a.merge!(data['days'])
|
233
240
|
end
|
234
241
|
else
|
235
|
-
|
236
|
-
|
237
|
-
day_key = year_s + '-' + month_f + '-' + day_f
|
242
|
+
if begin_day
|
243
|
+
day_key = begin_year_s + '-' + begin_month_f + '-' + begin_day_f
|
238
244
|
if data['days'].has_key?(day_key)
|
239
245
|
entries_a[day_key] = data['days'][day_key].keep_if{ |day_item|
|
240
246
|
day_item['category'].downcase == category
|
241
247
|
}
|
242
248
|
end
|
243
249
|
else
|
244
|
-
entries_a.merge!
|
250
|
+
entries_a.merge!(data['days'].map{ |day_name, day_items|
|
245
251
|
day_items.keep_if{ |day_item|
|
246
252
|
day_item['category'].downcase == category
|
247
253
|
}
|
248
254
|
[day_name, day_items]
|
249
255
|
}.to_h.keep_if{ |day_name, day_items|
|
250
256
|
day_items.count > 0
|
251
|
-
}
|
257
|
+
})
|
252
258
|
end
|
253
259
|
end
|
254
260
|
|
@@ -492,9 +498,9 @@ module TheFox
|
|
492
498
|
expense_year += expense_month
|
493
499
|
balance_year += balance_month
|
494
500
|
|
495
|
-
revenue_month_r = revenue_month.round(
|
496
|
-
expense_month_r = expense_month.round(
|
497
|
-
balance_month_r = balance_month.round(
|
501
|
+
revenue_month_r = revenue_month.round(NUMBER_ROUND)
|
502
|
+
expense_month_r = expense_month.round(NUMBER_ROUND)
|
503
|
+
balance_month_r = balance_month.round(NUMBER_ROUND)
|
498
504
|
|
499
505
|
year_total[month_n] = ::OpenStruct.new({
|
500
506
|
month: month_n.to_i,
|
@@ -538,7 +544,7 @@ module TheFox
|
|
538
544
|
year_file.write('</tr>')
|
539
545
|
end
|
540
546
|
|
541
|
-
year_total.sort.inject(0.0){ |sum, item| item[1].balance_total = (sum + item[1].balance).round(
|
547
|
+
year_total.sort.inject(0.0){ |sum, item| item[1].balance_total = (sum + item[1].balance).round(NUMBER_ROUND) }
|
542
548
|
|
543
549
|
year_file.write('
|
544
550
|
<tr>
|
@@ -629,13 +635,13 @@ module TheFox
|
|
629
635
|
|
630
636
|
years_total[year_s] = ::OpenStruct.new({
|
631
637
|
year: year_s,
|
632
|
-
revenue: revenue_year.round(
|
633
|
-
expense: expense_year.round(
|
634
|
-
balance: balance_year.round(
|
638
|
+
revenue: revenue_year.round(NUMBER_ROUND),
|
639
|
+
expense: expense_year.round(NUMBER_ROUND),
|
640
|
+
balance: balance_year.round(NUMBER_ROUND),
|
635
641
|
})
|
636
642
|
end
|
637
643
|
|
638
|
-
years_total.sort.inject(0.0){ |sum, item| item[1].balance_total = (sum + item[1].balance).round(
|
644
|
+
years_total.sort.inject(0.0){ |sum, item| item[1].balance_total = (sum + item[1].balance).round(NUMBER_ROUND) }
|
639
645
|
|
640
646
|
index_file.write('
|
641
647
|
<table class="list">
|
data/thefox-wallet.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thefox-wallet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Mayer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: ArgsParser
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.0'
|
41
27
|
description: A Ruby library for tracking your finances.
|
42
28
|
email: christian@fox21.at
|
43
29
|
executables:
|