quickpep 0.1.0 → 0.1.1

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: b97633e4858dbf3bb2de75706b1d46b21720f03fdae7ae403900cce56fa0db33
4
- data.tar.gz: b54fb051c4849b6dc7b1632e3335db8cb790abbd6041501db1b25793a9a67491
3
+ metadata.gz: ba6bbfc5378de882fbd79dede0771a1642b66f417adecd3fde7857197f519d52
4
+ data.tar.gz: d5a58051fb491a039c2e966de835114e9d90a21dd4d0f3b672f3f5c202b01585
5
5
  SHA512:
6
- metadata.gz: e82606e40d2cca4b1318382afe68a45330f27206c2a4fffc9dbd67a0b6bd3698c4a9673fcee92caacf43be4b4685007b6a66f757975665569afb143f219ec0cc
7
- data.tar.gz: d1d3f7097e8887b68127ba4984aeba58b544c78fa11273fcb9c9286e55ca4408e99853e6b5196020e63e4b449f81131edf98b19ce562bc889cd8b8881b9e900d
6
+ metadata.gz: 84abeb9fab3e92961eedafea2da109ef0259df304b3ce037c7fa897070266f13368cdcdf864de7414d5e5d400ff2fab8f7974d18486588cf776d7dd1b81490cd
7
+ data.tar.gz: e4fab26e76fb49fc7620b0b5a32a6d7593c87a674fbea45dcc858e6799b4070f158682994d9abd52d4b01c24f8713dce8c73ab1d86bb5abc9346e20d4e0fdd00
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/quickpep.rb CHANGED
@@ -6,18 +6,25 @@ 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 finance app
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
16
  def initialize(s, balance: 0, currency: '', debug: false)
16
17
 
17
18
  @balance, @currency, @debug = balance, currency, debug
18
-
19
+ @warnings = []
19
20
  @to_s = calc_expenses(s)
20
21
 
22
+ warnings() if @warnings.any?
23
+
24
+ end
25
+
26
+ def warnings()
27
+ @warnings.each {|warning| puts warning.warn }
21
28
  end
22
29
 
23
30
  private
@@ -47,23 +54,52 @@ class QuickPep
47
54
 
48
55
  a = date_events.map do |date, title|
49
56
 
50
- puts '2. title: ' + title.inspect if @debug
57
+ if @debug then
58
+ puts '2. title: ' + title.inspect
59
+ puts 'date: ' + date.inspect
60
+ end
61
+
51
62
  credit, debit = 0.0, 0.0
52
63
  amount = h[title].amount
53
64
 
54
65
  if amount[0] == '+' then
66
+
55
67
  credit = amount.gsub(/\D/,'').to_f
68
+
69
+ if @debug then
70
+ puts 'credit: ' + credit.inspect
71
+ puts 'balance: ' + bal.inspect
72
+ end
73
+
56
74
  bal +=credit
75
+ puts 'after credit, balance: ' + bal.inspect if @debug
76
+
57
77
  else
78
+
58
79
  debit = amount.gsub(/\D/,'').to_f
80
+
81
+ if @debug then
82
+ puts 'debit: ' + debit.inspect
83
+ puts 'balance: ' + bal.inspect
84
+ end
85
+
59
86
  bal -= debit
87
+
88
+ puts 'after debug, balance: ' + bal.inspect if @debug
89
+
90
+ if bal < 0 then
91
+ @warnings << "date: %s, balance is below zero at %s" % [date,
92
+ bal.to_s.sub(/-/,'-' + @currency)]
93
+ end
94
+
60
95
  end
61
96
 
62
97
  [date, title, debit, credit, bal]
63
98
 
64
99
  end
65
100
 
66
- dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)')
101
+ dx2 = Dynarex.new('items/item(date, title, debit, credit, balance)', debug: @debug)
102
+ dx2.default_key = :uid
67
103
 
68
104
  a.each do |date, title, debit, credit, balance|
69
105
 
@@ -74,14 +110,14 @@ class QuickPep
74
110
  title: title,
75
111
  debit: debit > 0 ? (@currency + "%.2f" % debit) : '',
76
112
  credit: credit > 0 ? (@currency + "%.2f" % credit) : '',
77
- balance: @currency + "%.2f" % balance
113
+ balance: (@currency + "%.2f" % balance).sub(/#{@currency}-/, + '-' + @currency)
78
114
  }
79
115
 
80
116
  dx2.create row
81
117
  end
82
118
 
83
- dx2.to_table
119
+ dx2.to_table #(fields: %i(date title debit: credit: balance:))
120
+
84
121
  end
85
122
 
86
123
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file