quickpep 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: 3d221c7f20a31b411a07147262470f088abb5f80805a04cbda3f03c07680b2f9
4
- data.tar.gz: cf6608382d9ff856726a0975665cc7164c527338785a557d6534b60e5e7356d0
3
+ metadata.gz: 0de11237c2ae3902d31629219f665928d639fb9cd385ea8e8534e490ec002f5a
4
+ data.tar.gz: b5cf353cee4215b5ed18aeaac198324d2150965fdeec08ab34662917255d12c2
5
5
  SHA512:
6
- metadata.gz: 046bbc33232ec683591919720f587bac94c429fceaadf02a8ddc1f871489cabcc006a6577fa17d0c1f562489f6a4eac304a26dc2d15f88124f01cf5d87292558
7
- data.tar.gz: c24f96ace7b00886716e5e1d2a928331738aef23d8f2a467dddb65d6941dbd4a5d4959aa13febae7cdc52743c59669711c8820bb9929e3493429765c892a664d
6
+ metadata.gz: 44d5eebb58384292c90dc76472974486d9cec5b17427c582a5c4ad309099d8e614f34d174cc753172aafc3729bb3da2c374b1342454b0e4c74f8967a4007580b
7
+ data.tar.gz: a68cabdf29c866f7506dd47b736c1017db128c614677e1563eea4f6d11829747425c73ed49a4e9b54ad6e2777ca157d754c2991f4c28d9d959a6b1a9c09ba62f
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,9 +24,11 @@ class QuickPep
23
24
 
24
25
  end
25
26
 
26
- def annual_costs()
27
+ # options: year, month, weel, day
28
+ #
29
+ def annual_costs(perx=:year, per: perx)
27
30
 
28
- a = @date_events.map do |date, title|
31
+ rows = @date_events.map do |date, title|
29
32
 
30
33
  amount = @h[title].amount
31
34
 
@@ -36,9 +39,59 @@ class QuickPep
36
39
 
37
40
  end
38
41
 
39
- a.group_by {|date,title, amount| title }\
42
+ a = rows.group_by {|date,title, amount| title }\
40
43
  .map {|key, rows| [key, rows.map(&:last).sum]}.sort_by(&:last)
41
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 to_html()
64
+
65
+ t = to_dx().to_table
66
+ t.labels = %w(date title debit: credit: balance: uid:)
67
+ table = t.display markdown: true
68
+ title = "Personal Budget #{Date.today.year}"
69
+
70
+ "<html>
71
+ <head>
72
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
73
+ <title>#{title}</title>
74
+ <style>
75
+ table {border-collapse: collapse; width: 700px}
76
+ tr:nth-child(even) {
77
+ background-color: #aca;
78
+ }
79
+ @media print {
80
+
81
+ tr:nth-child(even) {
82
+ background-color: #ccc;
83
+ }
84
+
85
+ }
86
+ </style>
87
+ </head>
88
+ <body>
89
+ <h1>#{title}</h1>
90
+ #{RDiscount.new(table).to_html}
91
+ <hr/>
92
+ <footer>Generated by QuickPEP</footer>
93
+ </body>
94
+ </html>"
42
95
  end
43
96
 
44
97
  def warnings()
@@ -117,7 +170,8 @@ class QuickPep
117
170
 
118
171
  end
119
172
 
120
- dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)', debug: @debug)
173
+ dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)',
174
+ debug: @debug)
121
175
  dx2.default_key = :uid
122
176
 
123
177
  a.each do |date, title, debit, credit, balance|
@@ -129,12 +183,15 @@ class QuickPep
129
183
  title: title,
130
184
  debit: debit > 0 ? (@currency + "%.2f" % debit) : '',
131
185
  credit: credit > 0 ? (@currency + "%.2f" % credit) : '',
132
- balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/, + '-' + @currency)
186
+ balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/,
187
+ '-' + @currency)
133
188
  }
134
189
 
135
190
  dx2.create row
136
191
  end
137
192
 
193
+ @to_dx = dx2
194
+
138
195
  dx2.to_table #(fields: %i(date title debit: credit: balance:))
139
196
 
140
197
  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.2
4
+ version: 0.2.0
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-03 00:00:00.000000000 Z
38
+ date: 2022-05-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: event_nlp
metadata.gz.sig CHANGED
Binary file