quickpep 0.1.0 → 0.1.3
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
- checksums.yaml.gz.sig +0 -0
- data/lib/quickpep.rb +86 -12
- data.tar.gz.sig +0 -0
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b7cb104e2090fb59936478625cf3802e3cb994b22279e1ee22b973749daed1
|
4
|
+
data.tar.gz: 051e2bc9b41b8fa555a47f0af0f2a069ce472ab65a60426d7a3c7dd8f0fee88f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64e8b74f36ec2486e985e9c936735d7e6394315c479b829b95de2b426abb2d477be0497e6a37241c95993d487bafbe144f796084e9de8cd9fcacf9c4fa775dc2
|
7
|
+
data.tar.gz: d17d3b85c28bc7cfc7c633927122d28ef1d5644d7d9a48f440700fb19228a656fcab5f6c2a1ae09601a56262e2fddcc58df7d7b5e1c2d6fe4ac484b283dbe16b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/quickpep.rb
CHANGED
@@ -6,18 +6,62 @@ require 'dynarex'
|
|
6
6
|
require 'event_nlp'
|
7
7
|
|
8
8
|
# Quick Personal Expenses Planner - for people too lazy to use a
|
9
|
-
# spreadsheet or
|
9
|
+
# spreadsheet or sfinance app
|
10
10
|
#
|
11
11
|
class QuickPep
|
12
|
+
using ColouredText
|
12
13
|
|
13
14
|
attr_reader :to_s
|
14
15
|
|
15
|
-
def initialize(s, balance: 0, currency: '', debug: false)
|
16
|
+
def initialize(s, balance: 0, currency: '', today: Date.today, debug: false)
|
16
17
|
|
17
18
|
@balance, @currency, @debug = balance, currency, debug
|
18
|
-
|
19
|
+
@today = today
|
20
|
+
@warnings = []
|
19
21
|
@to_s = calc_expenses(s)
|
20
22
|
|
23
|
+
warnings() if @warnings.any?
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
# options: year, month, weel, day
|
28
|
+
#
|
29
|
+
def annual_costs(perx=:year, per: perx)
|
30
|
+
|
31
|
+
rows = @date_events.map do |date, title|
|
32
|
+
|
33
|
+
amount = @h[title].amount
|
34
|
+
|
35
|
+
prefix = amount[0] == '+' ? '' : '-'
|
36
|
+
amountx = (prefix + amount.gsub(/\D/,'')).to_f
|
37
|
+
|
38
|
+
[date, title, amountx]
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
a = rows.group_by {|date,title, amount| title }\
|
43
|
+
.map {|key, rows| [key, rows.map(&:last).sum]}.sort_by(&:last)
|
44
|
+
|
45
|
+
a.map do |title, total|
|
46
|
+
|
47
|
+
amount = case per.to_sym
|
48
|
+
when :year
|
49
|
+
total
|
50
|
+
when :month
|
51
|
+
total / (12 - @today.month)
|
52
|
+
when :week
|
53
|
+
total / (52 - @today.cweek )
|
54
|
+
when :day
|
55
|
+
total / (365 - @today.yday)
|
56
|
+
end
|
57
|
+
|
58
|
+
[title, amount.round(2)]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def warnings()
|
64
|
+
@warnings.each {|warning| puts warning.warn }
|
21
65
|
end
|
22
66
|
|
23
67
|
private
|
@@ -26,9 +70,9 @@ class QuickPep
|
|
26
70
|
|
27
71
|
dx = Dynarex.new(s)
|
28
72
|
|
29
|
-
h = dx.all.map {|x| [x.title, x]}.to_h
|
73
|
+
@h = dx.all.map {|x| [x.title, x]}.to_h
|
30
74
|
|
31
|
-
date_events = dx.all.flat_map do |rx|
|
75
|
+
@date_events = dx.all.flat_map do |rx|
|
32
76
|
|
33
77
|
title = [rx.title, rx.day, rx.recurring].join(' ')
|
34
78
|
puts '1. title: ' + title.inspect if @debug
|
@@ -44,26 +88,56 @@ class QuickPep
|
|
44
88
|
|
45
89
|
# opening balance
|
46
90
|
bal = @balance
|
91
|
+
@warnings = []
|
47
92
|
|
48
|
-
a = date_events.map do |date, title|
|
93
|
+
a = @date_events.map do |date, title|
|
94
|
+
|
95
|
+
if @debug then
|
96
|
+
puts '2. title: ' + title.inspect
|
97
|
+
puts 'date: ' + date.inspect
|
98
|
+
end
|
49
99
|
|
50
|
-
puts '2. title: ' + title.inspect if @debug
|
51
100
|
credit, debit = 0.0, 0.0
|
52
|
-
amount = h[title].amount
|
101
|
+
amount = @h[title].amount
|
53
102
|
|
54
103
|
if amount[0] == '+' then
|
104
|
+
|
55
105
|
credit = amount.gsub(/\D/,'').to_f
|
106
|
+
|
107
|
+
if @debug then
|
108
|
+
puts 'credit: ' + credit.inspect
|
109
|
+
puts 'balance: ' + bal.inspect
|
110
|
+
end
|
111
|
+
|
56
112
|
bal +=credit
|
113
|
+
puts 'after credit, balance: ' + bal.inspect if @debug
|
114
|
+
|
57
115
|
else
|
116
|
+
|
58
117
|
debit = amount.gsub(/\D/,'').to_f
|
118
|
+
|
119
|
+
if @debug then
|
120
|
+
puts 'debit: ' + debit.inspect
|
121
|
+
puts 'balance: ' + bal.inspect
|
122
|
+
end
|
123
|
+
|
59
124
|
bal -= debit
|
125
|
+
|
126
|
+
puts 'after debug, balance: ' + bal.inspect if @debug
|
127
|
+
|
128
|
+
if bal < 0 then
|
129
|
+
@warnings << "date: %s, balance is below zero at %s" % [date,
|
130
|
+
bal.to_s.sub(/-/,'-' + @currency)]
|
131
|
+
end
|
132
|
+
|
60
133
|
end
|
61
134
|
|
62
135
|
[date, title, debit, credit, bal]
|
63
136
|
|
64
137
|
end
|
65
138
|
|
66
|
-
dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)')
|
139
|
+
dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)', debug: @debug)
|
140
|
+
dx2.default_key = :uid
|
67
141
|
|
68
142
|
a.each do |date, title, debit, credit, balance|
|
69
143
|
|
@@ -74,14 +148,14 @@ class QuickPep
|
|
74
148
|
title: title,
|
75
149
|
debit: debit > 0 ? (@currency + "%.2f" % debit) : '',
|
76
150
|
credit: credit > 0 ? (@currency + "%.2f" % credit) : '',
|
77
|
-
balance: @currency + "%.2f" % balance
|
151
|
+
balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/, + '-' + @currency)
|
78
152
|
}
|
79
153
|
|
80
154
|
dx2.create row
|
81
155
|
end
|
82
156
|
|
83
|
-
dx2.to_table
|
157
|
+
dx2.to_table #(fields: %i(date title debit: credit: balance:))
|
158
|
+
|
84
159
|
end
|
85
160
|
|
86
161
|
end
|
87
|
-
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickpep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
kmcJnzHNiVwSBry7rnILYU3ouLJeHEtQY1v/S4KqPXGNS1FPvas3Wb429Cui2LtB
|
36
36
|
CkYfvLZCZS1SZGB2dGilreNS
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2022-04-
|
38
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: event_nlp
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '0.6'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.6.
|
49
|
+
version: 0.6.6
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version: '0.6'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.6.
|
59
|
+
version: 0.6.6
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: dynarex
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|