hledger-forecast 1.5.0 → 1.5.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: 0f769e017bc9ad46ea7d7571f74c64286e9c2415d0696e40f3301438a9038514
4
- data.tar.gz: 52f69b30edfbc0c9d5430b88d25687c9c311d6c6aa4b1e5fd3b2815b3602d240
3
+ metadata.gz: '09b594c8b6cf3c239d070abbb2101cf63a7d2b987f4c2e6680ba02b160c29e24'
4
+ data.tar.gz: 8df343c7d6baa56d46f053d83fb6152c26ef94308c96a493c4995b78ddfccf80
5
5
  SHA512:
6
- metadata.gz: 2721eb985469db575b66172a94ee670e96711437da7b94f27da53301beed9f385b46c19121c9d365ce01fb0423ea5ea728ce511296c29adc26fc2051ff33e794
7
- data.tar.gz: e41363954be45ca668dd73cc1a816b47a94419be53cde4fccdfc5a88a55601a2166e5f6eeb6532d4673c3bfe204020122165b71fabcca07a9dbf7cf0f1f80271
6
+ metadata.gz: d395581b614dd9d9931701964959092a6a897ce16daad53b3f1b7b96583e4905962f09bfe3f0cdac1a2583d0e287bb4f602d53c1dc674cd1ecb1dc421c8cafd1
7
+ data.tar.gz: 241f5d557cc7f777790fe3546a897aa2af73052b35555031bd0d13dcf4d9f65a117002da7c34726334bcec2b76eb3fb6a508dd699dfa7c9306c4980092776a3b
@@ -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 = 'Uses a YAML file to generate forecasts which can be used to extend the default functionality in hledger'
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(cell) - parse_money(csv2[i][j])
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
- # Explicitly check for common currencies first
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
- # Remove currency symbols and parse the result as a float, then convert to cents
68
- cleaned_value = value.gsub(/[^0-9.]/, '').to_f
69
- cleaned_value.to_i
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 = Formatter.format_money(amount, { currency: currency })
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
 
@@ -1,3 +1,3 @@
1
1
  module HledgerForecast
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -49,7 +49,7 @@ RSpec.describe 'command' do
49
49
  +---------+---------+---------+
50
50
  | account | 2023-07 | 2023-08 |
51
51
  +---------+---------+---------+
52
- | total | £-10.00 | 10.00 |
52
+ | total | £10.00 | €-10.00 |
53
53
  +---------+---------+---------+
54
54
 
55
55
  OUTPUT
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","€190.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 | £-10.00 | €10.00 |
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.0
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-08-31 00:00:00.000000000 Z
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: Uses a YAML file to generate forecasts which can be used to extend the
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