hledger-forecast 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hledger-forecast.gemspec +1 -1
- data/lib/hledger_forecast/comparator.rb +12 -6
- data/lib/hledger_forecast/version.rb +1 -1
- data/spec/cli_spec.rb +1 -1
- data/spec/compare_spec.rb +9 -9
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09b594c8b6cf3c239d070abbb2101cf63a7d2b987f4c2e6680ba02b160c29e24'
|
4
|
+
data.tar.gz: 8df343c7d6baa56d46f053d83fb6152c26ef94308c96a493c4995b78ddfccf80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d395581b614dd9d9931701964959092a6a897ce16daad53b3f1b7b96583e4905962f09bfe3f0cdac1a2583d0e287bb4f602d53c1dc674cd1ecb1dc421c8cafd1
|
7
|
+
data.tar.gz: 241f5d557cc7f777790fe3546a897aa2af73052b35555031bd0d13dcf4d9f65a117002da7c34726334bcec2b76eb3fb6a508dd699dfa7c9306c4980092776a3b
|
data/hledger-forecast.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.version = HledgerForecast::VERSION
|
10
10
|
s.authors = ['Oli Morris']
|
11
11
|
s.summary = "An extended wrapper around hledger's forecasting functionality"
|
12
|
-
s.description = '
|
12
|
+
s.description = 'Use a CSV or YAML file for improved forecasting with hledger'
|
13
13
|
s.email = 'olimorris@users.noreply.github.com'
|
14
14
|
s.homepage = 'https://github.com/olimorris/hledger-forecast'
|
15
15
|
s.license = 'MIT'
|
@@ -43,7 +43,7 @@ module HledgerForecast
|
|
43
43
|
if header?(i) || j == 0 # Checking for the first column here
|
44
44
|
csv2[i][j]
|
45
45
|
else
|
46
|
-
difference = parse_money(
|
46
|
+
difference = parse_money(csv2[i][j]) - parse_money(cell)
|
47
47
|
format_difference(difference, detect_currency(cell))
|
48
48
|
end
|
49
49
|
end
|
@@ -51,7 +51,9 @@ module HledgerForecast
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def detect_currency(str)
|
54
|
-
|
54
|
+
return nil if str == "0"
|
55
|
+
|
56
|
+
# Explicitly check for common currencies
|
55
57
|
return "GBP" if str.include?("£")
|
56
58
|
return "EUR" if str.include?("€")
|
57
59
|
return "USD" if str.include?("$")
|
@@ -64,13 +66,17 @@ module HledgerForecast
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def parse_money(value)
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
return 0.0 if value.strip == '0'
|
70
|
+
|
71
|
+
value.gsub(/[^0-9.-]/, '').to_f
|
70
72
|
end
|
71
73
|
|
72
74
|
def format_difference(amount, currency)
|
73
|
-
formatted_amount =
|
75
|
+
formatted_amount = if currency.nil?
|
76
|
+
format("%.2f", amount)
|
77
|
+
else
|
78
|
+
Formatter.format_money(amount, { currency: currency })
|
79
|
+
end
|
74
80
|
|
75
81
|
return formatted_amount if amount == 0
|
76
82
|
|
data/spec/cli_spec.rb
CHANGED
data/spec/compare_spec.rb
CHANGED
@@ -17,15 +17,15 @@ end
|
|
17
17
|
RSpec.describe HledgerForecast::Comparator do
|
18
18
|
let(:file1_content) do
|
19
19
|
<<~CSV
|
20
|
-
"account","2023-07","2023-08"
|
21
|
-
"total","£100.00","€200.00"
|
20
|
+
"account","2023-07","2023-08","2023-09"
|
21
|
+
"total","£100.00","€200.00",0
|
22
22
|
CSV
|
23
23
|
end
|
24
24
|
|
25
25
|
let(:file2_content) do
|
26
26
|
<<~CSV
|
27
|
-
"account","2023-07","2023-08"
|
28
|
-
"total","£110.00","
|
27
|
+
"account","2023-07","2023-08","2023-09"
|
28
|
+
"total","£110.00","-€200.00",£1144.00
|
29
29
|
CSV
|
30
30
|
end
|
31
31
|
|
@@ -41,11 +41,11 @@ RSpec.describe HledgerForecast::Comparator do
|
|
41
41
|
comparator = described_class.new
|
42
42
|
|
43
43
|
expected_output = strip_ansi_codes(<<~OUTPUT)
|
44
|
-
|
45
|
-
| account | 2023-07 | 2023-08 |
|
46
|
-
|
47
|
-
| total |
|
48
|
-
|
44
|
+
+---------+---------+----------+---------+
|
45
|
+
| account | 2023-07 | 2023-08 | 2023-09 |
|
46
|
+
+---------+---------+----------+---------+
|
47
|
+
| total | £10.00 | €-400.00 | 1144.00 |
|
48
|
+
+---------+---------+----------+---------+
|
49
49
|
OUTPUT
|
50
50
|
|
51
51
|
actual_output = capture_stdout { comparator.compare('file1.csv', 'file2.csv') }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hledger-forecast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oli Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -94,8 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.12'
|
97
|
-
description:
|
98
|
-
default functionality in hledger
|
97
|
+
description: Use a CSV or YAML file for improved forecasting with hledger
|
99
98
|
email: olimorris@users.noreply.github.com
|
100
99
|
executables:
|
101
100
|
- hledger-forecast
|