thefox-wallet 0.14.0 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83c52b0183b88eef28a1e430a10266cbc926be80
4
- data.tar.gz: 313cbc717b9eea9cb79444fb871bba40a6f9cad1
3
+ metadata.gz: 2cbb979259e323ea7267d725982ce79a4031b915
4
+ data.tar.gz: 97e01ebf34e7fe376b1898fc4154527f64e41f71
5
5
  SHA512:
6
- metadata.gz: ceb2875dbc61138cc094ea6a8d0f755f599017869bd966ed42960efa863d712320b270d69c59807cf8539ef709cebdd1720f159cf03b97c1f6a69418e61216af
7
- data.tar.gz: ce729b9878f78f02f923bc37c15a6ec3827dfb6e44069b12a68996fa0ff6c182da8c74e63c3aba9f04558ddae2fe9b3dba04b7a46027a968674f1f261214036b
6
+ metadata.gz: dbb7973fbd8bbe143409c33d2c329480e04d4acb20bfbedd31ce3fce400e3c9856174c9b715bccc2dc4595971d1253dbf95a2d62701f4deb037ce61e50948e8e
7
+ data.tar.gz: 9be10133bac53c6b17ad37905345517c408f9b1d0b1b1a68b957820ce0c436dc94b83075211f53d9563a5881fd6c6c337911d06866132311a108e965564fc0bf
data/.gitignore CHANGED
@@ -2,11 +2,12 @@
2
2
  .setup
3
3
  CHANGELOG-*.txt
4
4
  /coverage/
5
- /bin/test
6
5
  Gemfile.lock
7
6
  /releases/
7
+ /test_wallet/
8
8
  /tmp/
9
9
  /wallet/
10
10
  /wallet_test/
11
+ /wallet_test2/
11
12
  *.csv
12
13
  *.txt
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
- - master
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
- - master
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
- - master
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: release
41
+ environment: gem
43
42
  only:
44
43
  - tags
45
44
  script:
data/Gemfile CHANGED
@@ -1,3 +1,11 @@
1
1
 
2
2
  source 'https://rubygems.org'
3
+
4
+ group(:development) do
5
+ if ENV['SIMPLECOV_PHPUNIT_LOAD_PATH']
6
+ # Load SimpleCov PHPUnit Formatter from a local path.
7
+ gem 'simplecov-phpunit', :path => ENV['SIMPLECOV_PHPUNIT_LOAD_PATH']
8
+ end
9
+ end
10
+
3
11
  gemspec
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
- dev:
15
- bundler exec ./bin/wallet -w test_wallet add -t 'test' -e 5 -c 'test'
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 = bundle
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
- sudo gem install $$gem_file; \
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
- sudo gem uninstall $(GEM_NAME)
33
+ gem uninstall $(GEM_NAME)
32
34
 
33
35
  .PHONY: update
34
36
  update:
data/README.md CHANGED
@@ -24,7 +24,7 @@ The preferred method of installation is via RubyGems.org:
24
24
 
25
25
  or via `Gemfile`:
26
26
 
27
- gem 'thefox-wallet', '~>0.14'
27
+ gem 'thefox-wallet', '~>0.15'
28
28
 
29
29
  Use it in your sources:
30
30
 
data/bin/dev ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require 'pry'
5
+ require 'pathname'
6
+ require 'wallet'
7
+
8
+ include TheFox::Wallet
9
+
10
+ wallet = Wallet.new(Pathname.new('wallet_test2'))
11
+
12
+ binding.pry
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
- options = Hash.new
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
- #o.on('-d', '--date <date>', 'Start date or date used for the entry.') do |date|
35
- options[:entry_date] = date
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
- #o.on('-z', '--end <date>', 'End date.') do |date|
39
- # options[:entry_end_date] = date
40
- #end
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
- puts "ERROR: #{e}"
116
+ @logger.error(e.to_s)
104
117
  exit 1
105
118
  end
106
119
  else
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'date'
3
- #require 'pp'
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[:wallet_path] ||= 'wallet'
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
@@ -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: " + Date.parse(@options[:entry_date]).to_s
61
- puts "revenue: " + NUMBER_FORMAT % @options[:entry_revenue]
62
- puts "expense: " + NUMBER_FORMAT % @options[:entry_expense]
63
- puts "balance: " + NUMBER_FORMAT % [@options[:entry_revenue] + @options[:entry_expense]]
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'}"
@@ -7,9 +7,7 @@ module TheFox::Wallet
7
7
 
8
8
  def run
9
9
  wallet = Wallet.new(@options[:wallet_path])
10
- categories = wallet.categories
11
- puts "categories: #{categories.count}"
12
- puts "\t" + categories.join("\n\t")
10
+ puts wallet.categories
13
11
  end
14
12
 
15
13
  end
@@ -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
- puts "import csv #{@options[:path]} ..."
17
+ @options[:logger].info("import csv #{@options[:path]} ...") if @options[:logger]
17
18
  wallet.import_csv_file(@options[:path])
18
- puts "import csv #{@options[:path]} done"
19
+ @options[:logger].info("import csv #{@options[:path]} done") if @options[:logger]
19
20
  elsif @options[:is_export]
20
- puts "export csv #{@options[:path]} ..."
21
+ @options[:logger].info("export csv #{@options[:path]} ...") if @options[:logger]
21
22
  wallet.export_csv_file(@options[:path])
22
- puts "export csv #{@options[:path]} done"
23
+ @options[:logger].info("export csv #{@options[:path]} done") if @options[:logger]
23
24
  end
24
25
  end
25
26
 
@@ -7,9 +7,16 @@ module TheFox::Wallet
7
7
 
8
8
  def run
9
9
  wallet = Wallet.new(@options[:wallet_path])
10
- puts 'generate html to ' + wallet.html_path + ' ...'
11
- wallet.gen_html
12
- puts 'generate html done'
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
@@ -78,23 +78,27 @@ module TheFox::Wallet
78
78
  comment_l = 25
79
79
  end
80
80
 
81
- entries_f = '%' + entries_l.to_s + 's'
82
- title_f = '%-' + title_l.to_s + 's'
83
- revenue_f = '%' + revenue_l.to_s + 's'
84
- expense_f = '%' + expense_l.to_s + 's'
85
- balance_f = '%' + balance_l.to_s + 's'
86
- category_f = '%-' + category_l.to_s + 's'
87
- comment_f = '%-' + comment_l.to_s + 's'
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 += '#' * 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
- header += ' ' + category_f % 'Category' if has_category_col
97
- header += ' ' + comment_f % 'Comment' if has_comment_col
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
- title = title[0, 22] + '...' if title.length >= 25
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
- comment = comment[0, 22] + '...' if comment.length >= 25
130
+ if comment.length >= 25
131
+ comment = comment[0, 22] << '...'
132
+ end
125
133
 
126
134
  out = ''
127
- out += entries_f % entry_no
128
- out += ' ' + '%10s' % (entry['date'] == previous_date ? '' : entry['date'])
129
- out += ' ' + title_f % title
130
- out += ' ' + revenue_f % (NUMBER_FORMAT % entry['revenue'])
131
- out += ' ' + expense_f % (NUMBER_FORMAT % entry['expense'])
132
- out += ' ' + balance_f % (NUMBER_FORMAT % entry['balance'])
133
- out += ' ' + category_f % category if has_category_col
134
- out += ' ' + comment_f % comment if has_comment_col
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 += ' ' * (12 + entries_l)
146
- out += ' ' + title_f % 'TOTAL'
147
- out += ' ' + revenue_f % (NUMBER_FORMAT % revenue_total)
148
- out += ' ' + expense_f % (NUMBER_FORMAT % expense_total)
149
- out += ' ' + balance_f % (NUMBER_FORMAT % balance_total)
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, 'revenue (' + revenue_t.to_s + ') cannot be < 0. use expense instead!'
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, 'expense (' + expense_t.to_s + ') cannot be > 0. use revenue instead!'
92
+ raise RangeError, "expense (#{expense_t}) cannot be > 0. use revenue instead!"
93
93
  end
94
94
 
95
95
  @expense = expense_t
@@ -2,8 +2,8 @@
2
2
  module TheFox
3
3
  module Wallet
4
4
  NAME = 'Wallet'
5
- VERSION = '0.14.0'
6
- DATE = '2016-10-20'
5
+ VERSION = '0.15.0'
6
+ DATE = '2016-11-13'
7
7
  HOMEPAGE = 'https://github.com/TheFox/wallet'
8
8
 
9
9
  NUMBER_FORMAT = '%.2f'