hledger-forecast 1.5.0 → 1.5.2

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: 6f0e4168dd9c64b1de4aec0c02fcf1601ef926c0f2f911931052c627df53b922
4
+ data.tar.gz: bf24674eeae1cac5714ddd56a23cdd86059afaba3d376d8538424372f4ae74b0
5
5
  SHA512:
6
- metadata.gz: 2721eb985469db575b66172a94ee670e96711437da7b94f27da53301beed9f385b46c19121c9d365ce01fb0423ea5ea728ce511296c29adc26fc2051ff33e794
7
- data.tar.gz: e41363954be45ca668dd73cc1a816b47a94419be53cde4fccdfc5a88a55601a2166e5f6eeb6532d4673c3bfe204020122165b71fabcca07a9dbf7cf0f1f80271
6
+ metadata.gz: 72666051a083ae0381717c58bcb7c09de8dd250df683d26a16bce25ebf79315323b5bd2d0b9f2a19f553ecf3fe0c0327b5449c7435f5b3a461b121a6ab810537
7
+ data.tar.gz: 83f063a2ca35895d5104b2ff573de4b44e28b731fd8461462e87c9fb0d84ed26b818383bcaaccb4a7f52e784a383af0350eaab3d7d49d1b01930f4eee19a7f4d
@@ -0,0 +1,22 @@
1
+ name: Release
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ release:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: publish gem
14
+ run: |
15
+ mkdir -p $HOME/.gem
16
+ touch $HOME/.gem/credentials
17
+ chmod 0600 $HOME/.gem/credentials
18
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
19
+ gem build *.gemspec
20
+ gem push *.gem
21
+ env:
22
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -1,4 +1,4 @@
1
- name: Tests
1
+ name: Test
2
2
 
3
3
  on:
4
4
  pull_request:
@@ -8,14 +8,13 @@ on:
8
8
 
9
9
  jobs:
10
10
  test:
11
-
12
11
  runs-on: ubuntu-latest
13
12
  strategy:
14
13
  matrix:
15
14
  ruby-version: ['3.0', '3.1', '3.2']
16
15
 
17
16
  steps:
18
- - uses: actions/checkout@v3
17
+ - uses: actions/checkout@v4
19
18
  - name: Update packages
20
19
  run: sudo apt-get update
21
20
  - name: Install packages
@@ -23,7 +22,8 @@ jobs:
23
22
  - name: Set up Ruby
24
23
  uses: ruby/setup-ruby@v1
25
24
  with:
26
- bundler-cache: true # runs 'bundle install' and caches installed gems
25
+ bundler-cache: true
27
26
  ruby-version: ${{ matrix.ruby-version }}
28
27
  - name: Run tests
29
- run: bundle exec rspec
28
+ run: |
29
+ bundle exec rspec
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <a href="https://github.com/olimorris/hledger-forecast/stargazers"><img src="https://img.shields.io/github/stars/olimorris/hledger-forecast?color=c678dd&logoColor=e06c75&style=for-the-badge"></a>
9
9
  <a href="https://github.com/olimorris/hledger-forecast/issues"><img src="https://img.shields.io/github/issues/olimorris/hledger-forecast?color=%23d19a66&style=for-the-badge"></a>
10
10
  <a href="https://github.com/olimorris/hledger-forecast/blob/main/LICENSE"><img src="https://img.shields.io/github/license/olimorris/hledger-forecast?color=%2361afef&style=for-the-badge"></a>
11
- <a href="https://github.com/olimorris/hledger-forecast/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/olimorris/hledger-forecast/ci.yml?branch=main&label=tests&style=for-the-badge"></a>
11
+ <a href="https://github.com/olimorris/hledger-forecast/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/olimorris/hledger-forecast/test.yml?branch=main&label=tests&style=for-the-badge"></a>
12
12
  </p>
13
13
 
14
14
  **"Improved", you say?** Using a _CSV_ (or _YML_) file, forecasts can be quickly generated into a _journal_ file ready to be fed into [hledger](https://github.com/simonmichael/hledger). **A 16 line [CSV file](https://github.com/olimorris/hledger-forecast/blob/main/example.csv) can generate a 46 line hledger [forecast file](https://github.com/olimorris/hledger-forecast/blob/main/example.journal)!**
@@ -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
 
@@ -117,9 +117,18 @@ module HledgerForecast
117
117
  sum + item[row_to_sum]
118
118
  end
119
119
 
120
+ income = data.reduce(0) do |sum, item|
121
+ sum += item[row_to_sum] if item[row_to_sum] < 0
122
+ sum
123
+ end
124
+
125
+ savings = (total / income * 100).to_f.round(2)
126
+
120
127
  @table.add_separator
121
128
  @table.add_row [{ value: "TOTAL".bold, colspan: 2, alignment: :left },
122
129
  { value: format_amount(total).bold, alignment: :right }]
130
+ @table.add_row [{ value: "as a % of income".italic, colspan: 2, alignment: :left },
131
+ { value: "#{savings}%".italic, alignment: :right }]
123
132
  end
124
133
 
125
134
  def format_amount(amount)
@@ -1,3 +1,3 @@
1
1
  module HledgerForecast
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.2".freeze
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oli Morris
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-31 00:00:00.000000000 Z
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -94,15 +94,15 @@ 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
102
101
  extensions: []
103
102
  extra_rdoc_files: []
104
103
  files:
105
- - ".github/workflows/ci.yml"
104
+ - ".github/workflows/release.yml"
105
+ - ".github/workflows/test.yml"
106
106
  - ".gitignore"
107
107
  - ".rubocop.yml"
108
108
  - Gemfile
@@ -155,7 +155,7 @@ homepage: https://github.com/olimorris/hledger-forecast
155
155
  licenses:
156
156
  - MIT
157
157
  metadata: {}
158
- post_install_message:
158
+ post_install_message:
159
159
  rdoc_options: []
160
160
  require_paths:
161
161
  - lib
@@ -170,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubygems_version: 3.4.19
174
- signing_key:
173
+ rubygems_version: 3.3.5
174
+ signing_key:
175
175
  specification_version: 4
176
176
  summary: An extended wrapper around hledger's forecasting functionality
177
177
  test_files: