total_recall 0.6.0 → 0.7.0.rc2

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
- SHA1:
3
- metadata.gz: 4eeb842cfe9ee4786bc22a2727a1020e8cdb3fff
4
- data.tar.gz: 46034a06760f81a905ffd0b384ebf2f4ac9f5751
2
+ SHA256:
3
+ metadata.gz: 8257618ff2bc8498f080cf1da28ee81b372e2f430aa0a8d5e9a51de4462bb673
4
+ data.tar.gz: 032a8bb34e14ca8a08b3e1e21e30b4c3c6ccf0a2d909036928c062758e44d4e2
5
5
  SHA512:
6
- metadata.gz: f97bacdd8edd27e009edc074681213d1c00eedbb2981a7c4da89e605966376b5c9c8a9d1024017d0cec90a2ad04858c3c0fa30c0aacc240a8427a2a944d2087a
7
- data.tar.gz: d746904a4b9f9f5a16eda0a7917d876e11749c2f0aa5dddbccd30fc4e36bfec242c0e4f7e2e54b775b0021d6dbfedea311c340a94fa6a76391bcd998cc72ddf1
6
+ metadata.gz: b87059bde6346cea3934f0cbc1684a516f678292263a1c9bd25780906bfd002b0973ab11509b6fbc7ffaa615f666a624e4083b773ca5e5f5dde6ca207edbb06c
7
+ data.tar.gz: 981a98cd6828ada1f6e2e531e51d4648538af59e0c3b995b075b6ad088f9b0a0fe21fd3360e012a87eed90d080868499332f3f30573a273e78842fff15f32210
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # 0.7.0 / unreleased
2
+
3
+ * modernize for Ruby 3.3+
4
+
5
+ - target Ruby >= 3.3.0, test on 3.3 and 3.4
6
+ - update all dependencies (thor 1.x, terminal-table 3.x, highline 3.x)
7
+ - use `YAML.unsafe_load_file` (required since Ruby 3.1 for custom YAML types)
8
+ - add frozen_string_literal to all Ruby files
9
+
10
+ * switch to GitHub Actions CI with release workflow
11
+
12
+ - add `.github/workflows/main.yml` for CI
13
+ - add `.github/workflows/release.yml` for automated gem publishing on tag push
14
+ - remove `.gitlab-ci.yml`
15
+
16
+ * add mise.toml for Ruby version management
17
+
18
+ * '--version' and '-v' handled by version-subcommand
19
+
20
+ * pass csv-file to ledger-subcommand:
21
+
22
+ ```bash
23
+ $ total_recall ledger -c bank.yml --csv ~/Downloads/bank.csv
24
+ ```
25
+
26
+ * init-subcommand skips yml-extension if provided
27
+
28
+ * remove duplicate `exe/total_recall.rb`
29
+
30
+
1
31
  # 0.6.0 / 2017-03-08
2
32
 
3
33
  * move repository to GitLab
@@ -59,4 +89,3 @@
59
89
  # 0.4.0 / 2014-06-04
60
90
 
61
91
  * Add yaml-config.
62
-
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Gert Goet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,63 +1,106 @@
1
1
  # TotalRecall [![build status](https://gitlab.com/eval/total_recall/badges/master/build.svg)](https://gitlab.com/eval/total_recall/commits/master)
2
2
 
3
-
4
3
  Turn **any** csv-file into a [Ledger](http://ledger-cli.org/) journal.
5
4
 
6
- ## Install
7
-
8
- ```bash
9
- gem install total_recall
5
+ ## Introduction
6
+
7
+ `total_recall` assumes nothing about the structure of your csv, nor of the ledger-file you want to create.
8
+ Instead, one creates a yaml-config consisting of:
9
+ * a [mustache-template](https://github.com/defunkt/mustache) of the ledger-file
10
+ * the source (and parse-options) of the csv
11
+ * the value of every template-variable via Ruby lambdas
12
+
13
+ ## Example
14
+
15
+ After installation you run `total_recall init bank` to generate the following file:
16
+ ```yaml
17
+ # file: bank.yml
18
+ :total_recall:
19
+ :version: 0.6.0
20
+ :template:
21
+ :raw: |-
22
+ ; -*- ledger -*-¬
23
+
24
+ {{# transactions}}
25
+ {{date}} {{{description}}}
26
+ {{to}} EUR {{amount}}
27
+ {{from}}
28
+
29
+ {{/ transactions}}
30
+
31
+ :csv:
32
+ #:file: total_recall.csv
33
+ :raw: |-
34
+ "2013-11-01","Foo","2013-11-02","1.638,00"
35
+ "2013-11-02","Bar","2013-11-03","-492,93"
36
+ :options:
37
+ #:col_sep: ";"
38
+ #:headers: false
39
+
40
+ :context:
41
+ :transactions:
42
+ :__defaults__:
43
+ :from: !!proc |
44
+ ask_account("What account provides these transactions?", default: 'Assets:Checking')
45
+ :date: !!proc row[0]
46
+ :description: !!proc row[1]
47
+ :amount: !!proc row[3]
48
+ :to: !!proc |
49
+ render_row(columns: [0, 1, 3])
50
+ ask_account("To what account did the money go?")
10
51
  ```
11
52
 
12
- ## Quickstart
53
+ The `template`-section is pretty straightforward: you can add any variable you need using the [mustache-syntax](http://mustache.github.io/mustache.5.html).
54
+ The `csv`-section defines where csv comes from and what parse-options should be used. It's best to start with a csv-snippet in `raw` (and leave `file` commented) in order to test-run the config.
13
55
 
14
- ### Generate a sample config
56
+ In the `context`-section the actual mapping is done: in this section your should define a key for every variable in the template.
57
+ A key's value is derived from the csv via Ruby. This can be done via a simple mapping: `:date: !!proc row[0]`, via some specific operation: `:data: !!proc Date.parse(row[0]).iso8601` or via one of the [interactive helpers](https://gitlab.com/eval/total_recall/blob/v0.6.0/lib/total_recall.rb#L27-50) as you can see for the `to`-field above.
58
+ Fields can also have default-values: the `from`-field for example is the same for all rows.
15
59
 
16
- ```bash
17
- total_recall sample
18
- # An annotated config 'sample.yml' will be written to the current directory.
60
+ As it's all Ruby, you can make the mapping as smart as you like:
61
+ ```
62
+ :context:
63
+ :transactions:
64
+ :description: !!proc row[3]
65
+ :to: !!proc |
66
+ guess = begin
67
+ case self.description # the description-field is defined above
68
+ when /CREDITCARD/ then "Liabilities:MasterCard"
69
+ when /INTERNET/i then "Expenses:Communication"
70
+ end
71
+ end
72
+ ask_account("To what account did the money go?", default: guess)
73
+ ...
19
74
  ```
20
75
 
21
- ### Generate a ledger
22
-
23
- The sample config contains 2 transactions.
24
- Let's get 'em in a journal:
76
+ See [Extensibility](#extensibility) below for providing your own Ruby module with helpers (i.e. your own self-learning account-guesser!).
25
77
 
78
+ Once your config is done, you can give it a spin:
26
79
  ```bash
27
- total_recall ledger -c sample.yml > sample.dat
28
- # What account provides these transactions? |Assets:Checking|
29
- #
30
- # +------------+-----+----------+
31
- # | 03.11.2013 | Foo | 1.638,00 |
32
- # +------------+-----+----------+
33
- # To what account did the money go?
34
- # Expenses:Foo
35
- # +------------+-----+---------+
36
- # | 03.11.2013 | Bar | -492,93 |
37
- # +------------+-----+---------+
38
- # To what account did the money go?
39
- # Expenses:Bar
80
+ # the result will be echoed:
81
+ $ total_recall ledger -c bank.yml
82
+
83
+ # to quickly see if the output is actually valid ledger:
84
+ $ total_recall ledger -c bank.yml | ledger -f - reg
40
85
  ```
41
- Now verify the ledger file:
42
86
 
87
+ When the output looks good and doesn't make Ledger choke, you can uncomment the file-key in the csv-section and run it against the real csv-data:
43
88
  ```bash
44
- ledger -f sample.dat balance
45
-
46
- # $ -1.145,07 Assets:Checking
47
- # $ 1.145,07 Expenses
48
- # $ -492,93 Bar
49
- # $ 1.638,00 Foo
50
- #--------------------
51
- # 0
89
+ $ total_recall ledger -c bank.yml > bank.dat
52
90
  ```
53
91
 
54
- ### Now what?
92
+ That's it!
93
+
94
+ To see an extensive annotated config-file do:
95
+ ```bash
96
+ $ total_recall sample
97
+ ```
55
98
 
56
- May I suggest:
57
- * read `sample.yml`
99
+ ## Install
58
100
 
59
- It explains what options are available.
60
- * put your own csv in `sample.yml` and adjust the context
101
+ ```bash
102
+ gem install total_recall
103
+ ```
61
104
 
62
105
  ## Usage
63
106
 
@@ -118,7 +161,7 @@ TotalRecall::SessionHelper.include MyExtension
118
161
  ## Develop
119
162
 
120
163
  ```bash
121
- git clone git://github.com/eval/total_recall.git
164
+ git clone https://gitlab.com/eval/total_recall.git
122
165
  cd total_recall
123
166
  bundle
124
167
  bundle exec rake spec
data/Rakefile CHANGED
@@ -1,6 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
9
+
10
+ if ENV["CI"]
11
+ # version.rb is written at CI which prevents guard_clean from passing.
12
+ # Redefine guard_clean to make it a noop.
13
+ Rake::Task["release:guard_clean"].clear
14
+ task "release:guard_clean"
15
+
16
+ # As a release is triggered by a tag, nothing should be pushed.
17
+ Rake::Task["release:source_control_push"].clear
18
+ task "release:source_control_push"
19
+ end
@@ -34,7 +34,7 @@
34
34
  # The location of :file: is relative to this file.
35
35
  # :file: takes precedence over :raw:
36
36
  #
37
- #:file: sample.csv
37
+ #:file: sample.csv # also overwritable via ledger-subcommand. See `total_recall help ledger`.
38
38
  :raw: |-
39
39
  "date";"description";"effective_data";"amount"
40
40
  "2013-11-01";"Foo";"2013-11-02";"1.638,00"
@@ -58,15 +58,15 @@
58
58
  default: 'Assets:Checking')
59
59
  :currency: $
60
60
  # ...and fields that vary per transaction.
61
- # Helper method exist such as `row`, `ask_account` (see `TotalRecall::SessionHelper` for more).
61
+ # Helper method exist such as `row`, `ask_account` (see https://gitlab.com/eval/total_recall/blob/v0.6.0/lib/total_recall.rb#L7 for more).
62
62
  :date: !!proc row[:date]
63
63
  :description: !!proc row[:description]
64
64
  :amount: !!proc row[:amount]
65
65
  :currency: !!proc |
66
- case row[:description]
66
+ case row[:description] # `this.description` can also be used: this would be the 'processed' description.
67
67
  when /some regex to detect non-dollar/ then '€'
68
68
  else
69
- default
69
+ default # the value for this field in __defaults__
70
70
  end
71
71
  :to: !!proc |
72
72
  # show the row and let the user decide
@@ -13,13 +13,14 @@
13
13
  {{/ transactions}}
14
14
 
15
15
  :csv:
16
- #:file: <%= @name %>.csv
16
+ #:file: <%= @name %>.csv # also overwritable via ledger-subcommand. See `total_recall help ledger`.
17
17
  :raw: |-
18
18
  "2013-11-01","Foo","2013-11-02","1.638,00"
19
19
  "2013-11-02","Bar","2013-11-03","-492,93"
20
20
  :options:
21
21
  #:col_sep: ";"
22
22
  #:headers: false
23
+ #:header_converters: :symbol # row[:date] rather than row[0]. Requires headers.
23
24
 
24
25
  :context:
25
26
  :transactions:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TotalRecall
2
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0.rc2"
3
5
  end
data/lib/total_recall.rb CHANGED
@@ -1,11 +1,13 @@
1
- require 'yaml'
2
- require 'thor'
3
- require 'mustache'
4
- require 'csv'
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "thor"
5
+ require "mustache"
6
+ require "csv"
5
7
 
6
8
  module TotalRecall
7
9
  module DefaultHelper
8
- require 'highline/import'
10
+ require "highline"
9
11
  require "terminal-table"
10
12
 
11
13
  def transaction
@@ -43,21 +45,21 @@ module TotalRecall
43
45
  #
44
46
  # @return [String] the account-name
45
47
  def ask_account(question, options = {})
46
- options = { default: nil }.merge(options)
48
+ options = {default: nil}.merge(options)
47
49
  highline.ask(question) do |q|
48
50
  q.default = options[:default] if options[:default]
49
51
  end
50
52
  end
51
53
 
52
54
  def render_row(options = {})
53
- options = { columns: [] }.merge(options)
54
- _row = options[:columns].map {|i| row[i] }
55
- $stderr.puts Terminal::Table.new(rows: [ _row ])
55
+ options = {columns: []}.merge(options)
56
+ _row = options[:columns].map { |i| row[i] }
57
+ $stderr.puts Terminal::Table.new(rows: [_row])
56
58
  end
57
59
 
58
60
  def extract_transaction(row)
59
61
  @row = row
60
- transactions_config.each do |k,v|
62
+ transactions_config.each do |k, v|
61
63
  next if k[/^__/]
62
64
  self[k] = value_for(k, v)
63
65
  end
@@ -65,6 +67,7 @@ module TotalRecall
65
67
  end
66
68
 
67
69
  protected
70
+
68
71
  def value_for(key, v)
69
72
  if v.respond_to?(:call)
70
73
  @default = self[key.to_sym]
@@ -102,27 +105,30 @@ module TotalRecall
102
105
  end
103
106
 
104
107
  class Config
105
- YAML::add_builtin_type('proc') {|_, val| eval("proc { #{val} }") }
108
+ YAML.add_builtin_type("proc") { |_, val| eval("proc { #{val} }") }
106
109
 
107
110
  def initialize(options = {})
108
- options = { file: 'total_recall.yml' }.merge(options)
111
+ options = {file: "total_recall.yml", csv_file: nil}.merge(options)
112
+ @csv_file = File.expand_path(options[:csv_file]) if options[:csv_file]
109
113
  @config_file = File.expand_path(options[:file])
110
114
  @transactions_only = !!options[:transactions_only]
111
115
  end
112
116
 
113
117
  def config
114
- @config ||= YAML.load_file(@config_file)
118
+ @config ||= YAML.unsafe_load_file(@config_file)
115
119
  end
116
120
 
117
121
  def csv_file
118
- config[:csv][:file] &&
119
- File.expand_path(config[:csv][:file], File.dirname(@config_file))
122
+ @csv_file ||= begin
123
+ config[:csv][:file] &&
124
+ File.expand_path(config[:csv][:file], File.dirname(@config_file))
125
+ end
120
126
  end
121
127
 
122
128
  def csv
123
129
  @csv ||= begin
124
130
  csv_raw = csv_file ? File.read(csv_file) : config[:csv][:raw]
125
- CSV.parse(csv_raw, config[:csv][:options] || {})
131
+ CSV.parse(csv_raw, **(config[:csv][:options] || {}))
126
132
  end
127
133
  end
128
134
 
@@ -162,12 +168,12 @@ module TotalRecall
162
168
  end
163
169
 
164
170
  def session
165
- @session ||= session_class.new(transactions_config_defaults, :config => config)
171
+ @session ||= session_class.new(transactions_config_defaults, config: config)
166
172
  end
167
173
 
168
174
  def transaction_attributes
169
175
  @transaction_attributes ||= begin
170
- transactions_config.dup.delete_if{|k,_| k[/__/]}.keys |
176
+ transactions_config.dup.delete_if { |k, _| k[/__/] }.keys |
171
177
  transactions_config_defaults.keys
172
178
  end
173
179
  end
@@ -179,7 +185,7 @@ module TotalRecall
179
185
 
180
186
  def initialize(values = {}, options = {})
181
187
  @config = options[:config]
182
- values.each do |k,v|
188
+ values.each do |k, v|
183
189
  self[k] = value_for(k, v)
184
190
  end
185
191
  end
@@ -213,21 +219,23 @@ module TotalRecall
213
219
  end
214
220
 
215
221
  class Cli < Thor
216
- require 'total_recall/version'
222
+ require "total_recall/version"
217
223
 
218
224
  include Thor::Actions
219
- source_root File.expand_path('../total_recall/templates', __FILE__)
225
+ source_root File.expand_path("../total_recall/templates", __FILE__)
220
226
 
221
227
  desc "ledger", "Convert CONFIG to a ledger"
222
- method_option :config, :aliases => "-c", :desc => "Config file", :required => true
223
- method_option :require, :aliases => "-r", :desc => "File to load"
224
- method_option :transactions_only, :type => :boolean
228
+ method_option :config, aliases: "-c", desc: "Config file", required: true
229
+ method_option :require, aliases: "-r", desc: "File to load"
230
+ method_option :csv, aliases: "-f", desc: "csv file"
231
+ method_option :transactions_only, type: :boolean
225
232
  def ledger
226
233
  load(options[:require]) if options[:require]
227
234
 
228
235
  config_path = File.expand_path(options[:config])
229
236
  puts TotalRecall::Config.new(file: config_path,
230
- :transactions_only => options[:transactions_only]).ledger
237
+ csv_file: options[:csv],
238
+ transactions_only: options[:transactions_only]).ledger
231
239
  end
232
240
 
233
241
  desc "sample", "Generate an annotated config"
@@ -240,16 +248,17 @@ module TotalRecall
240
248
 
241
249
  desc "init NAME", "Generate a minimal config NAME.yml"
242
250
  def init(name = "total_recall")
243
- destination = name + ".yml"
251
+ destination = name[/\.yml$/] ? name : (name + ".yml")
244
252
 
245
253
  @version = TotalRecall::VERSION
246
- @name = name
254
+ @name = destination.split(/\.yml$/).first
247
255
  template("simple.yml.tt", destination)
248
256
  end
249
257
 
250
- desc "version", "Show total_recall version"
258
+ desc "version, --version, -v", "Show total_recall version"
251
259
  def version
252
260
  puts TotalRecall::VERSION
253
261
  end
262
+ map %w[-v --version] => :version
254
263
  end
255
264
  end
data/mise.toml ADDED
@@ -0,0 +1,6 @@
1
+ [tools]
2
+ ruby = "3.4"
3
+
4
+ [env]
5
+ _.path = ["bin"]
6
+ PROJECT_ROOT = "{{config_root}}"
data/rakelib/gem.rake ADDED
@@ -0,0 +1,15 @@
1
+ namespace :gem do
2
+ task "write_version", [:version] do |_task, args|
3
+ if args[:version]
4
+ version = args[:version].split("=").last
5
+ version_file = File.expand_path("../../lib/total_recall/version.rb", __FILE__)
6
+
7
+ system(<<~CMD, exception: true)
8
+ ruby -pi -e 'gsub(/VERSION = ".*"/, %{VERSION = "#{version}"})' #{version_file}
9
+ CMD
10
+ Bundler.ui.confirm "Version #{version} written to #{version_file}."
11
+ else
12
+ Bundler.ui.warn "No version provided, keeping version.rb as is."
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,59 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: total_recall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
8
- autorequire:
9
- bindir: bin
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: thor
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.19'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.19'
27
- - !ruby/object:Gem::Dependency
28
- name: terminal-table
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.7'
41
- - !ruby/object:Gem::Dependency
42
- name: highline
13
+ name: csv
43
14
  requirement: !ruby/object:Gem::Requirement
44
15
  requirements:
45
- - - "~>"
16
+ - - ">="
46
17
  - !ruby/object:Gem::Version
47
- version: '1.7'
18
+ version: '0'
48
19
  type: :runtime
49
20
  prerelease: false
50
21
  version_requirements: !ruby/object:Gem::Requirement
51
22
  requirements:
52
- - - "~>"
23
+ - - ">="
53
24
  - !ruby/object:Gem::Version
54
- version: '1.7'
25
+ version: '0'
55
26
  - !ruby/object:Gem::Dependency
56
- name: mustache
27
+ name: thor
57
28
  requirement: !ruby/object:Gem::Requirement
58
29
  requirements:
59
30
  - - "~>"
@@ -67,90 +38,74 @@ dependencies:
67
38
  - !ruby/object:Gem::Version
68
39
  version: '1.0'
69
40
  - !ruby/object:Gem::Dependency
70
- name: bundler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.11'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.11'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
41
+ name: terminal-table
85
42
  requirement: !ruby/object:Gem::Requirement
86
43
  requirements:
87
44
  - - "~>"
88
45
  - !ruby/object:Gem::Version
89
- version: '12.0'
90
- type: :development
46
+ version: '3.0'
47
+ type: :runtime
91
48
  prerelease: false
92
49
  version_requirements: !ruby/object:Gem::Requirement
93
50
  requirements:
94
51
  - - "~>"
95
52
  - !ruby/object:Gem::Version
96
- version: '12.0'
53
+ version: '3.0'
97
54
  - !ruby/object:Gem::Dependency
98
- name: rspec
55
+ name: highline
99
56
  requirement: !ruby/object:Gem::Requirement
100
57
  requirements:
101
58
  - - "~>"
102
59
  - !ruby/object:Gem::Version
103
- version: '3.4'
104
- type: :development
60
+ version: '3.0'
61
+ type: :runtime
105
62
  prerelease: false
106
63
  version_requirements: !ruby/object:Gem::Requirement
107
64
  requirements:
108
65
  - - "~>"
109
66
  - !ruby/object:Gem::Version
110
- version: '3.4'
67
+ version: '3.0'
111
68
  - !ruby/object:Gem::Dependency
112
- name: fakefs
69
+ name: mustache
113
70
  requirement: !ruby/object:Gem::Requirement
114
71
  requirements:
115
72
  - - "~>"
116
73
  - !ruby/object:Gem::Version
117
- version: '0.10'
118
- type: :development
74
+ version: '1.0'
75
+ type: :runtime
119
76
  prerelease: false
120
77
  version_requirements: !ruby/object:Gem::Requirement
121
78
  requirements:
122
79
  - - "~>"
123
80
  - !ruby/object:Gem::Version
124
- version: '0.10'
81
+ version: '1.0'
125
82
  description: Turn any csv into a Ledger journal
126
83
  email:
127
84
  - gert@thinkcreate.nl
128
85
  executables:
129
86
  - total_recall
130
- - total_recall.rb
131
87
  extensions: []
132
88
  extra_rdoc_files: []
133
89
  files:
134
- - ".gitignore"
135
- - ".gitlab-ci.yml"
90
+ - ".rspec"
136
91
  - CHANGELOG.md
137
- - Gemfile
92
+ - LICENSE
138
93
  - README.md
139
94
  - Rakefile
140
- - bin/total_recall
141
- - bin/total_recall.rb
95
+ - exe/total_recall
142
96
  - lib/total_recall.rb
143
97
  - lib/total_recall/templates/sample.yml.tt
144
98
  - lib/total_recall/templates/simple.yml.tt
145
99
  - lib/total_recall/version.rb
146
- - spec/spec_helper.rb
147
- - spec/total_recall/total_recall_spec.rb
148
- - total_recall.gemspec
149
- homepage: https://gitlab.com/eval/total_recall/tree/master#totalrecall-
100
+ - mise.toml
101
+ - rakelib/gem.rake
102
+ homepage: https://github.com/eval/total_recall
150
103
  licenses:
151
104
  - MIT
152
- metadata: {}
153
- post_install_message:
105
+ metadata:
106
+ homepage_uri: https://github.com/eval/total_recall
107
+ source_code_uri: https://github.com/eval/total_recall
108
+ changelog_uri: https://github.com/eval/total_recall/blob/main/CHANGELOG.md
154
109
  rdoc_options: []
155
110
  require_paths:
156
111
  - lib
@@ -158,18 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
113
  requirements:
159
114
  - - ">="
160
115
  - !ruby/object:Gem::Version
161
- version: '0'
116
+ version: 3.3.0
162
117
  required_rubygems_version: !ruby/object:Gem::Requirement
163
118
  requirements:
164
119
  - - ">="
165
120
  - !ruby/object:Gem::Version
166
121
  version: '0'
167
122
  requirements: []
168
- rubyforge_project:
169
- rubygems_version: 2.5.2
170
- signing_key:
123
+ rubygems_version: 3.6.7
171
124
  specification_version: 4
172
125
  summary: Turn any csv into a Ledger journal
173
- test_files:
174
- - spec/spec_helper.rb
175
- - spec/total_recall/total_recall_spec.rb
126
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.own
data/.gitlab-ci.yml DELETED
@@ -1,18 +0,0 @@
1
- .spec: &spec
2
- tags:
3
- - docker
4
- script:
5
- - bundle install --binstubs --path vendor --without production --jobs $(nproc) > /dev/null
6
- - bin/rspec
7
-
8
- spec2.1:
9
- image: ruby:2.1
10
- <<: *spec
11
-
12
- spec2.3:
13
- image: ruby:2.3
14
- <<: *spec
15
-
16
- spec2.4:
17
- image: ruby:2.4
18
- <<: *spec
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- # Specify your gem's dependencies in total_recall.gemspec
4
- gemspec
data/bin/total_recall.rb DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'total_recall'
3
-
4
- TotalRecall::Cli.start
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'total_recall'
3
- require 'fakefs/spec_helpers'
4
-
5
- RSpec.configure do |config|
6
- config.color = true
7
- config.tty = true
8
- end
@@ -1,251 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe TotalRecall::Config do
4
- include FakeFS::SpecHelpers
5
-
6
- def stubbed_file(path, content)
7
- # SOURCE http://edgeapi.rubyonrails.org/classes/String.html#method-i-strip_heredoc
8
- indent = content.scan(/^[ \t]*(?=\S)/).min.size rescue 0
9
- content = content.gsub(/^[ \t]{#{indent}}/, '')
10
-
11
- FakeFS do
12
- File.open(path, 'w'){|f| f.print content }
13
- end
14
- end
15
-
16
- def instance_with_config(config, options = {})
17
- options = {file: 'config.yml'}.merge(options)
18
- stubbed_file(options[:file], config)
19
- described_class.new(options)
20
- end
21
-
22
- describe '#config' do
23
- it 'yields the config as hash' do
24
- instance = instance_with_config(<<-CONFIG)
25
- :csv:
26
- :raw: Some csv
27
- :a: 1
28
- CONFIG
29
-
30
- expect(instance.config).to eql({csv: { raw: 'Some csv'}, a: 1})
31
- end
32
- end
33
-
34
- describe '#csv' do
35
- it 'yields csv assigned to :raw' do
36
- instance = instance_with_config(<<-CONFIG)
37
- :csv:
38
- :raw: Some csv
39
- CONFIG
40
-
41
- expect(instance.csv).to eql(CSV.parse('Some csv'))
42
- end
43
-
44
- it 'yields csv from file :file' do
45
- csv_file = stubbed_file('some.csv', 'Some csv')
46
- instance = instance_with_config(<<-CONFIG)
47
- :csv:
48
- :file: some.csv
49
- CONFIG
50
-
51
- expect(instance.csv).to eql(CSV.parse('Some csv'))
52
- end
53
-
54
- it 'yields csv from :file when both :raw and :file are configured' do
55
- csv_file = stubbed_file('some.csv', 'Some csv')
56
- instance = instance_with_config(<<-CONFIG)
57
- :csv:
58
- :file: some.csv
59
- :raw: Some raw csv
60
- CONFIG
61
-
62
- expect(instance.csv).to eql(CSV.parse('Some csv'))
63
- end
64
-
65
- specify 'csv-options are passed on to CSV#read' do
66
- instance = instance_with_config(<<-CONFIG)
67
- :csv:
68
- :options:
69
- :option1: true
70
- CONFIG
71
-
72
- expect(CSV).to receive(:parse).with(anything(), { option1: true })
73
- instance.csv
74
- end
75
- end
76
-
77
- describe '#template' do
78
- it 'yields template assigned to :raw' do
79
- instance = instance_with_config(<<-CONFIG)
80
- :template:
81
- :raw: |-
82
- Raw template
83
- here
84
- CONFIG
85
-
86
- expect(instance.template).to eql("Raw template\nhere")
87
- end
88
-
89
- it 'yields template from file :file' do
90
- template_file = stubbed_file('template.mustache', 'File template')
91
- instance = instance_with_config(<<-CONFIG)
92
- :template:
93
- :file: template.mustache
94
- CONFIG
95
-
96
- expect(instance.template).to eql('File template')
97
- end
98
-
99
- it 'yields template from :file when both :raw and :file are configured' do
100
- template_file = stubbed_file('template.mustache', 'File template')
101
- instance = instance_with_config(<<-CONFIG)
102
- :template:
103
- :file: template.mustache
104
- :raw: Raw template
105
- CONFIG
106
-
107
- expect(instance.template).to eql('File template')
108
- end
109
-
110
- context 'transactions only' do
111
- it 'takes only the transactions-section of the template into account' do
112
- instance = instance_with_config(<<-CONFIG, :transactions_only => true)
113
- :csv:
114
- :raw: |-
115
- row1
116
- :context:
117
- :a: 1
118
- :transactions:
119
- :b: !!proc row[0]
120
- :template:
121
- :raw: |-
122
- {{a}}
123
- {{# transactions}}
124
- {{b}}
125
- {{/ transactions}}
126
- CONFIG
127
-
128
- expect(instance.ledger).to eql("row1\n")
129
- end
130
- end
131
- end
132
-
133
- describe 'YAML types' do
134
- it 'allows proc-types' do
135
- instance = instance_with_config(<<-CONFIG)
136
- :a: !!proc 1 + 1
137
- :b: !!proc |
138
- 1 + 1
139
- CONFIG
140
-
141
- expect(instance.config[:a].call).to eq 2
142
- expect(instance.config[:b].call).to eq 2
143
- end
144
- end
145
-
146
- describe '#context' do
147
- it 'has a transaction per line of csv' do
148
- instance = instance_with_config(<<-CONFIG)
149
- :csv:
150
- :raw: |-
151
- 1
152
- 1
153
- :context:
154
- :transactions:
155
- :from: From
156
- :to: !!proc 1 + 1
157
- :amount: !!proc row[0]
158
- CONFIG
159
-
160
- transactions = instance.context[:transactions]
161
- expect(transactions.size).to eq 2
162
-
163
- transaction = transactions.first
164
- expect(transaction).to match({from: 'From', to: 2, amount: "1"})
165
- end
166
-
167
- it 'adds defaults to every transaction' do
168
- instance = instance_with_config(<<-CONFIG)
169
- :csv:
170
- :raw: |-
171
- line 1
172
- line 2
173
- :context:
174
- :transactions:
175
- :__defaults__:
176
- :default: !!proc 1
177
- :from: From
178
- CONFIG
179
-
180
- transaction = instance.context[:transactions].first
181
-
182
- expect(transaction).to match({from: 'From', default: 1})
183
- end
184
-
185
- it 'may contain any other settings' do
186
- instance = instance_with_config(<<-CONFIG)
187
- :csv:
188
- :raw: some csv
189
- :context:
190
- :transactions:
191
- :from: From
192
- :a: 1
193
- CONFIG
194
-
195
- expect(instance.context).to match(transactions: [{from: 'From'}], a: 1)
196
- end
197
- end
198
-
199
- describe 'helper methods' do
200
- describe '#transaction' do
201
- it 'gives access to the existing attributes' do
202
- instance = instance_with_config(<<-CONFIG)
203
- :csv:
204
- :raw: some csv
205
- :context:
206
- :transactions:
207
- :a: attribute a
208
- :b: !!proc |
209
- %|not %s| % transaction.a
210
- CONFIG
211
-
212
- expect(instance.transactions.first).to match({a: 'attribute a', b: 'not attribute a'})
213
- end
214
- end
215
-
216
- describe '#config' do
217
- it 'gives access to the full config' do
218
- instance = instance_with_config(<<-CONFIG)
219
- :csv:
220
- :raw: some csv
221
- :context:
222
- :transactions:
223
- :a: !!proc |
224
- config[:a]
225
- :a: 1
226
- CONFIG
227
-
228
- expect(instance.transactions.first).to match({a: 1})
229
- end
230
- end
231
-
232
- describe '#default' do
233
- it 'gives access to the default' do
234
- instance = instance_with_config(<<-CONFIG)
235
- :csv:
236
- :raw: some csv
237
- :context:
238
- :transactions:
239
- :__defaults__:
240
- :a: !!proc 2
241
- :b?: true
242
- :a: !!proc |
243
- default.succ
244
- :b?: true
245
- CONFIG
246
-
247
- expect(instance.transactions.first).to match({a: 3, b?: true})
248
- end
249
- end
250
- end
251
- end
data/total_recall.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'total_recall/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "total_recall"
8
- gem.version = TotalRecall::VERSION
9
- gem.authors = ["Gert Goet"]
10
- gem.email = ["gert@thinkcreate.nl"]
11
- gem.description = %q{Turn any csv into a Ledger journal}
12
- gem.summary = %q{Turn any csv into a Ledger journal}
13
- gem.homepage = "https://gitlab.com/eval/total_recall/tree/master#totalrecall-"
14
- gem.license = "MIT"
15
-
16
- gem.files = `git ls-files -z`.split("\x0")
17
- gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
20
-
21
- gem.add_dependency 'thor', '~> 0.19'
22
- gem.add_dependency 'terminal-table', '~> 1.7'
23
- gem.add_dependency 'highline', '~> 1.7'
24
- gem.add_dependency 'mustache', '~> 1.0'
25
- gem.add_development_dependency 'bundler', '~> 1.11'
26
- gem.add_development_dependency 'rake', '~> 12.0'
27
- gem.add_development_dependency 'rspec', '~> 3.4'
28
- gem.add_development_dependency 'fakefs', '~> 0.10'
29
- end
File without changes