quickpep 0.1.1 → 0.1.4
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 +50 -8
- 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: b1d800b406053b5a60a9974e32518ec1ec168f2239c47022e86abbc86068b6fc
|
4
|
+
data.tar.gz: 9af8af2752cde50599b286177acdf358acf8b9c7c9e1437aab1671607892cd48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d09c1c82b93b4a68475648177884d649be20cfbb8a8e3ed96ffc44491ef2cf5d6584e761b539ff802883fb4d6981e49355eb33dd873bbefe18d2cb00f587225
|
7
|
+
data.tar.gz: 88c9fd772da20eb20c1813d30d3775ae747696a72d91ba1c4227219de8210102aeab7efaf86a744f6a6f5fa71087a494c5dfcd7d2b4700412820e9f3c3b41dcd
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/quickpep.rb
CHANGED
@@ -11,11 +11,12 @@ require 'event_nlp'
|
|
11
11
|
class QuickPep
|
12
12
|
using ColouredText
|
13
13
|
|
14
|
-
attr_reader :to_s
|
14
|
+
attr_reader :to_s, :to_dx
|
15
15
|
|
16
|
-
def initialize(s, balance: 0, currency: '', debug: false)
|
16
|
+
def initialize(s, balance: 0, currency: '', today: Date.today, debug: false)
|
17
17
|
|
18
18
|
@balance, @currency, @debug = balance, currency, debug
|
19
|
+
@today = today
|
19
20
|
@warnings = []
|
20
21
|
@to_s = calc_expenses(s)
|
21
22
|
|
@@ -23,6 +24,42 @@ class QuickPep
|
|
23
24
|
|
24
25
|
end
|
25
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
|
+
|
26
63
|
def warnings()
|
27
64
|
@warnings.each {|warning| puts warning.warn }
|
28
65
|
end
|
@@ -33,9 +70,9 @@ class QuickPep
|
|
33
70
|
|
34
71
|
dx = Dynarex.new(s)
|
35
72
|
|
36
|
-
h = dx.all.map {|x| [x.title, x]}.to_h
|
73
|
+
@h = dx.all.map {|x| [x.title, x]}.to_h
|
37
74
|
|
38
|
-
date_events = dx.all.flat_map do |rx|
|
75
|
+
@date_events = dx.all.flat_map do |rx|
|
39
76
|
|
40
77
|
title = [rx.title, rx.day, rx.recurring].join(' ')
|
41
78
|
puts '1. title: ' + title.inspect if @debug
|
@@ -51,8 +88,9 @@ class QuickPep
|
|
51
88
|
|
52
89
|
# opening balance
|
53
90
|
bal = @balance
|
91
|
+
@warnings = []
|
54
92
|
|
55
|
-
a = date_events.map do |date, title|
|
93
|
+
a = @date_events.map do |date, title|
|
56
94
|
|
57
95
|
if @debug then
|
58
96
|
puts '2. title: ' + title.inspect
|
@@ -60,7 +98,7 @@ class QuickPep
|
|
60
98
|
end
|
61
99
|
|
62
100
|
credit, debit = 0.0, 0.0
|
63
|
-
amount = h[title].amount
|
101
|
+
amount = @h[title].amount
|
64
102
|
|
65
103
|
if amount[0] == '+' then
|
66
104
|
|
@@ -98,7 +136,8 @@ class QuickPep
|
|
98
136
|
|
99
137
|
end
|
100
138
|
|
101
|
-
dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)',
|
139
|
+
dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)',
|
140
|
+
debug: @debug)
|
102
141
|
dx2.default_key = :uid
|
103
142
|
|
104
143
|
a.each do |date, title, debit, credit, balance|
|
@@ -110,12 +149,15 @@ class QuickPep
|
|
110
149
|
title: title,
|
111
150
|
debit: debit > 0 ? (@currency + "%.2f" % debit) : '',
|
112
151
|
credit: credit > 0 ? (@currency + "%.2f" % credit) : '',
|
113
|
-
balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/,
|
152
|
+
balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/,
|
153
|
+
'-' + @currency)
|
114
154
|
}
|
115
155
|
|
116
156
|
dx2.create row
|
117
157
|
end
|
118
158
|
|
159
|
+
@to_dx = dx2
|
160
|
+
|
119
161
|
dx2.to_table #(fields: %i(date title debit: credit: balance:))
|
120
162
|
|
121
163
|
end
|
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.4
|
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-
|
38
|
+
date: 2022-05-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
|