ledger_tiller_export 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +91 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +162 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/ledger_tiller_export.gemspec +32 -0
  14. data/lib/ledger_tiller_export.rb +180 -0
  15. data/lib/ledger_tiller_export/version.rb +4 -0
  16. data/sorbet/config +2 -0
  17. data/sorbet/rbi/gems/addressable.rbi +199 -0
  18. data/sorbet/rbi/gems/declarative-option.rbi +24 -0
  19. data/sorbet/rbi/gems/declarative.rbi +75 -0
  20. data/sorbet/rbi/gems/faraday.rbi +316 -0
  21. data/sorbet/rbi/gems/google-api-client.rbi +4822 -0
  22. data/sorbet/rbi/gems/google_drive.rbi +360 -0
  23. data/sorbet/rbi/gems/googleauth.rbi +172 -0
  24. data/sorbet/rbi/gems/httpclient.rbi +810 -0
  25. data/sorbet/rbi/gems/jwt.rbi +68 -0
  26. data/sorbet/rbi/gems/ledger_gen.rbi +39 -0
  27. data/sorbet/rbi/gems/memoist.rbi +42 -0
  28. data/sorbet/rbi/gems/mini_mime.rbi +52 -0
  29. data/sorbet/rbi/gems/multi_json.rbi +62 -0
  30. data/sorbet/rbi/gems/multipart-post.rbi +53 -0
  31. data/sorbet/rbi/gems/nokogiri.rbi +1007 -0
  32. data/sorbet/rbi/gems/os.rbi +46 -0
  33. data/sorbet/rbi/gems/public_suffix.rbi +18 -0
  34. data/sorbet/rbi/gems/rake.rbi +636 -0
  35. data/sorbet/rbi/gems/representable.rbi +276 -0
  36. data/sorbet/rbi/gems/retriable.rbi +21 -0
  37. data/sorbet/rbi/gems/rspec-core.rbi +194 -0
  38. data/sorbet/rbi/gems/rspec-expectations.rbi +859 -0
  39. data/sorbet/rbi/gems/rspec-mocks.rbi +192 -0
  40. data/sorbet/rbi/gems/rspec-support.rbi +38 -0
  41. data/sorbet/rbi/gems/rspec.rbi +15 -0
  42. data/sorbet/rbi/gems/signet.rbi +121 -0
  43. data/sorbet/rbi/gems/uber.rbi +26 -0
  44. data/sorbet/rbi/hidden-definitions/errors.txt +6574 -0
  45. data/sorbet/rbi/hidden-definitions/hidden.rbi +11607 -0
  46. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +8684 -0
  47. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +4222 -0
  48. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +111 -0
  49. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +543 -0
  50. metadata +190 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 307135e8c2caf98e4b2958efc90c4acfa8944ecd
4
+ data.tar.gz: 0ad4cbab8a0bc01f6174887393b897c830be8276
5
+ SHA512:
6
+ metadata.gz: 5694e282fa1fa7a298d34fbfb2ef8a7bd635c5a2ac2b22121fefd758ab2ec16ae81a5246be8a4032673eaae9ed599a2ba0d554d3ff6ecc0a9b722260ad1100e5
7
+ data.tar.gz: 52e45c2a10d3f04de595f2533d414b9373d57643aa23d5dd31beae75d6323dfc0b3699e2f28a8a50e5bc04d2d8e6e060a8f096d133eaaac44df8938abdf3ee1f
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pete@petekeen.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ledger_tiller_export.gemspec
6
+ gemspec
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ledger_tiller_export (0.1.0)
5
+ google_drive
6
+ ledger_gen
7
+ sorbet-runtime
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ declarative (0.0.10)
15
+ declarative-option (0.1.0)
16
+ diff-lcs (1.3)
17
+ faraday (1.0.1)
18
+ multipart-post (>= 1.2, < 3)
19
+ google-api-client (0.36.4)
20
+ addressable (~> 2.5, >= 2.5.1)
21
+ googleauth (~> 0.9)
22
+ httpclient (>= 2.8.1, < 3.0)
23
+ mini_mime (~> 1.0)
24
+ representable (~> 3.0)
25
+ retriable (>= 2.0, < 4.0)
26
+ signet (~> 0.12)
27
+ google_drive (3.0.4)
28
+ google-api-client (>= 0.11.0, < 0.37.0)
29
+ googleauth (>= 0.5.0, < 1.0.0)
30
+ nokogiri (>= 1.5.3, < 2.0.0)
31
+ googleauth (0.12.0)
32
+ faraday (>= 0.17.3, < 2.0)
33
+ jwt (>= 1.4, < 3.0)
34
+ memoist (~> 0.16)
35
+ multi_json (~> 1.11)
36
+ os (>= 0.9, < 2.0)
37
+ signet (~> 0.14)
38
+ httpclient (2.8.3)
39
+ jwt (2.2.1)
40
+ ledger_gen (0.2.0)
41
+ memoist (0.16.2)
42
+ mini_mime (1.0.2)
43
+ mini_portile2 (2.4.0)
44
+ multi_json (1.14.1)
45
+ multipart-post (2.1.1)
46
+ nokogiri (1.10.9)
47
+ mini_portile2 (~> 2.4.0)
48
+ os (1.1.0)
49
+ public_suffix (4.0.5)
50
+ rake (13.0.1)
51
+ representable (3.0.4)
52
+ declarative (< 0.1.0)
53
+ declarative-option (< 0.2.0)
54
+ uber (< 0.2.0)
55
+ retriable (3.1.2)
56
+ rspec (3.9.0)
57
+ rspec-core (~> 3.9.0)
58
+ rspec-expectations (~> 3.9.0)
59
+ rspec-mocks (~> 3.9.0)
60
+ rspec-core (3.9.2)
61
+ rspec-support (~> 3.9.3)
62
+ rspec-expectations (3.9.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.9.0)
65
+ rspec-mocks (3.9.1)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.9.0)
68
+ rspec-support (3.9.3)
69
+ signet (0.14.0)
70
+ addressable (~> 2.3)
71
+ faraday (>= 0.17.3, < 2.0)
72
+ jwt (>= 1.5, < 3.0)
73
+ multi_json (~> 1.10)
74
+ sorbet (0.5.5648)
75
+ sorbet-static (= 0.5.5648)
76
+ sorbet-runtime (0.5.5648)
77
+ sorbet-static (0.5.5648-universal-darwin-14)
78
+ uber (0.1.0)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ bundler (~> 1.16)
85
+ ledger_tiller_export!
86
+ rake (~> 13.0)
87
+ rspec (~> 3.0)
88
+ sorbet
89
+
90
+ BUNDLED WITH
91
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Pete Keen
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,162 @@
1
+ # LedgerTillerExport
2
+
3
+ `LedgerTillerExport` is a tool to help export transactions from [Tiller](https://www.tillerhq/) into [Ledger](https://www.ledger-cli.org).
4
+ It reads the Google spreadsheet that Tiller maintains and follows rules that you define to create Ledger transactions.
5
+ It will read your Ledger file to dedupe transactions using Tiller's guids.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ledger_tiller_export'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ledger_tiller_export
22
+
23
+ ## Usage
24
+
25
+ Here's a simple example script:
26
+
27
+ ```ruby
28
+ require 'ledger_tiller_export'
29
+
30
+ RULES = [
31
+ LedgerTillerExport::RegexpRule.new(match: 'McDonalds', account: 'Expenses:Food'),
32
+ LedgerTillerExport::RegexpRule.new(match: 'DTE', account: 'Expenses:Utils:Energy'),
33
+ ]
34
+
35
+ if __FILE__ == $PROGRAM_NAME
36
+ LedgerTillerExport::Exporter.new(
37
+ rules: RULES,
38
+ spreadsheet: 'YourGoogleSheetId',
39
+ ).run
40
+ end
41
+ ```
42
+
43
+ If you already have existing Ledger transactions you may want to pick a start date and only export transactions that happen after that date.
44
+ You can subclass `LedgerTillerExport::Exporter` and override the `skip_row?` method:
45
+
46
+ ```ruby
47
+ class MyTillerExporter < LedgerTillerExport::Exporter
48
+ def skip_row?(row)
49
+ return true if row.txn_date < Date.new(2020, 5, 1)
50
+
51
+ super
52
+ end
53
+ end
54
+ ```
55
+
56
+ `LedgerTillerExport` comes with one rule type, `RegexpRule`, which simply matches on the payee of each transaction and returns the given account.
57
+ You can define your own rule types if you want to implement more interesting behavior. For example, I track checks that I've written using transactions like this:
58
+
59
+ ```
60
+ 2020/05/05 * Lawn Guy
61
+ Expenses:Lawn $35.00
62
+ Liabilities:Checks:SomeBank:1025
63
+ ```
64
+
65
+ When the check gets cashed I write another transaction like this:
66
+
67
+ ```
68
+ 2020/05/10 * Check paid
69
+ Liabilities:Checks:SomeBank:1025 $35.00
70
+ Assets:SomeBank::Checking
71
+ ```
72
+
73
+ To automatically reconcile these I have a rule in my exporter script that looks like this:
74
+
75
+ ```ruby
76
+ require 'sorbet-runtime'
77
+
78
+ class CheckingAccountRule
79
+ extend T::Sig
80
+
81
+ include LedgerTillerExport::RuleInterface
82
+
83
+ class CheckingAccount < T::Struct
84
+ const :account, String
85
+ const :check_account_prefix, String
86
+ end
87
+
88
+ class Check < T::Struct
89
+ const :amount, Float
90
+ const :check, String
91
+ end
92
+
93
+ CHECKING_ACCOUNTS = T.let([
94
+ CheckingAccount.new(account: 'Assets:SomeBank:Checking', check_account_prefix: 'Liabilities:Checks:SomeBank),
95
+ CheckingAccount.new(account: 'Assets:OtherBank:Checking', check_account_prefix: 'Liabilities:Checks:OtherBank'),
96
+ ], T::Array[CheckingAccount])
97
+
98
+ sig {void}
99
+ def initialize
100
+ @outstanding_checks = fetch_outstanding_checks
101
+ end
102
+
103
+ sig {override.params(row: LedgerTillerExport::Row).returns(T.nilable(String))}
104
+ def account_for_row(row)
105
+ if row.description =~ /Check|Bill pay/i
106
+ @outstanding_checks.each do |check|
107
+ if row.amount.to_f.round(2) == check.amount.round(2)
108
+ CHECKING_ACCOUNTS.each do |acct|
109
+ if acct.account == row.account && check.check.start_with?(acct.check_account_prefix)
110
+ return check.check
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ # fetch all of the outstanding checks using a Ledger balance query with a custom format
119
+ sig {returns(T::Array[Check])}
120
+ def fetch_outstanding_checks
121
+ cmd = [
122
+ 'ledger',
123
+ %q{--balance-format=%(quantity(scrub(display_total))),%(account)\n},
124
+ 'bal',
125
+ 'checks',
126
+ ]
127
+
128
+ raw_checks, _, _ = Open3.capture3(*cmd)
129
+
130
+ raw_checks.strip.split(/\n/).map do |raw|
131
+ row = raw.split(/,/, 2)
132
+ Check.new(amount: T.must(row.first).to_f, check: T.must(row.last))
133
+ end
134
+ end
135
+ end
136
+ ```
137
+
138
+ The only required method is `account_for_row`, which either returns a `String` account name or `nil` if the rule didn't match.
139
+
140
+ This example rule will read all of the outstanding checks from Ledger using a custom balance query.
141
+ It then will match against a specific payee (`/Check|Bill pay/`) and scan across all of the outstanding checks.
142
+ If it finds one, it outputs the check account.
143
+
144
+ (Note that this uses [Sorbet](https://sorbet.org) but you don't have to do that if you don't want to.)
145
+
146
+ ## Development
147
+
148
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
149
+
150
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
151
+
152
+ ## Contributing
153
+
154
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ledger_tiller_export. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
155
+
156
+ ## License
157
+
158
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
159
+
160
+ ## Code of Conduct
161
+
162
+ Everyone interacting in the LedgerTillerExport project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ledger_tiller_export/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ledger_tiller_export"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ledger_tiller_export/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ledger_tiller_export"
8
+ spec.version = LedgerTillerExport::VERSION
9
+ spec.authors = ["Pete Keen"]
10
+ spec.email = ["pete@petekeen.net"]
11
+
12
+ spec.summary = %q{Generate ledger transactions from Tiller}
13
+ spec.description = %q{Generate ledger transactions from Tiller}
14
+ spec.homepage = "https://github.com/peterkeen/ledger_tiller_export"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "sorbet-runtime"
25
+ spec.add_dependency "ledger_gen"
26
+ spec.add_dependency "google_drive"
27
+
28
+ spec.add_development_dependency "sorbet"
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end