bdgtr-cli 0.2 → 0.3
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 +4 -4
- data/README.md +1 -1
- data/bin/bdgtr +26 -5
- data/lib/bdgtr/cli/config.rb +188 -0
- data/lib/bdgtr/cli/config.sample.yml +15 -0
- data/lib/bdgtr/cli/help.rb +168 -0
- data/lib/bdgtr/cli/ledger_sync.rb +102 -0
- data/lib/bdgtr/cli/prompt.rb +47 -0
- data/lib/bdgtr/cli/psd2.rb +530 -0
- data/lib/bdgtr/cli/rows.rb +38 -0
- data/lib/bdgtr/cli/runtime.rb +88 -0
- data/lib/bdgtr/cli/table.rb +458 -0
- data/lib/bdgtr/cli.rb +126 -0
- data/lib/bdgtr/core/binder.rb +79 -0
- data/lib/bdgtr/core/exchange.rb +66 -0
- data/lib/bdgtr/core/models/account.rb +177 -0
- data/lib/bdgtr/core/models/account_requisition.rb +12 -0
- data/lib/bdgtr/core/models/account_sync.rb +12 -0
- data/lib/bdgtr/core/models/import.rb +12 -0
- data/lib/bdgtr/core/models/ledger.rb +10 -0
- data/lib/bdgtr/core/models/requisition.rb +27 -0
- data/lib/bdgtr/core/models/transaction.rb +98 -0
- data/lib/bdgtr/core/models/transaction_category.rb +12 -0
- data/lib/bdgtr/core/record.rb +11 -0
- data/lib/bdgtr/core/schema.rb +290 -0
- data/lib/bdgtr/core/session.rb +76 -0
- data/lib/bdgtr/core/syncable.rb +272 -0
- data/lib/bdgtr/core/transfer.rb +90 -0
- data/lib/bdgtr/core.rb +18 -0
- data/lib/bdgtr/portfolio/Rakefile +20 -0
- data/lib/bdgtr/portfolio/cli/LICENSE +21 -0
- data/lib/bdgtr/portfolio/cli/lib/portfolio_performance_api/cli/app.rb +77 -0
- data/lib/bdgtr/portfolio/cli/lib/portfolio_performance_api/cli/import.rb +30 -0
- data/lib/bdgtr/portfolio/cli/lib/portfolio_performance_api/cli/spreadsheet.rb +25 -0
- data/lib/bdgtr/portfolio/cli/lib/portfolio_performance_api/cli.rb +52 -0
- data/lib/bdgtr/portfolio/exe/bdgtr +7 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/accounts_csv.rb +67 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/app.rb +104 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/auth.rb +52 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/balances.rb +157 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/cache.rb +46 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/checkbox_menu.rb +90 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/checkbox_selection.rb +68 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/config.rb +138 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/decryptor.rb +70 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/drive_client.rb +182 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/errors.rb +10 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/file_reader.rb +80 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/fineco_import.rb +609 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/fineco_xls.rb +235 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/import/fineco.rb +243 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/import.rb +85 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/parser.rb +254 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/portfolio_source.rb +30 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/portfolio_store.rb +124 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/preview_window.rb +98 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/proto/client_pb.rb +29 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/row_preview.rb +174 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/sheets_client.rb +272 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/snapshot.rb +27 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/sync.rb +247 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/sync_preview.rb +63 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/transaction_identity.rb +49 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/transaction_sync.rb +948 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/transaction_types.rb +142 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api/version.rb +5 -0
- data/lib/bdgtr/portfolio/lib/portfolio_performance_api.rb +42 -0
- data/lib/bdgtr/portfolio/proto/client.proto +114 -0
- data/lib/bdgtr/psd2/account.rb +24 -0
- data/lib/bdgtr/psd2/account_snapshot.rb +96 -0
- data/lib/bdgtr/psd2/callback.rb +49 -0
- data/lib/bdgtr/psd2/connect.rb +75 -0
- data/lib/bdgtr/psd2/enable_banking.rb +250 -0
- data/lib/bdgtr/psd2/go_cardless.rb +133 -0
- data/lib/bdgtr/psd2/institution.rb +17 -0
- data/lib/bdgtr/psd2/platform.rb +37 -0
- data/lib/bdgtr/psd2/requisition.rb +21 -0
- data/lib/bdgtr/psd2/transaction.rb +29 -0
- data/lib/bdgtr/psd2.rb +25 -0
- data/lib/bdgtr/sync/importer.rb +125 -0
- data/lib/bdgtr/sync/library.rb +18 -0
- data/lib/bdgtr/sync/portfolio.rb +14 -0
- data/lib/bdgtr/sync/projection.rb +38 -0
- data/lib/bdgtr/sync/spreadsheet.rb +23 -0
- data/lib/bdgtr/sync.rb +25 -0
- data/lib/bdgtr/version.rb +1 -1
- metadata +353 -30
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "errors"
|
|
4
|
+
require_relative "decryptor"
|
|
5
|
+
require_relative "file_reader"
|
|
6
|
+
require_relative "proto/client_pb"
|
|
7
|
+
require_relative "config"
|
|
8
|
+
require_relative "drive_client"
|
|
9
|
+
require_relative "portfolio_store"
|
|
10
|
+
require_relative "sheets_client"
|
|
11
|
+
require_relative "transaction_sync"
|
|
12
|
+
require_relative "sync_preview"
|
|
13
|
+
|
|
14
|
+
module PortfolioPerformanceApi
|
|
15
|
+
class Sync
|
|
16
|
+
def self.run(argv = [])
|
|
17
|
+
command = Array(argv)[0].to_s
|
|
18
|
+
case command
|
|
19
|
+
when "", "sync" then new.run
|
|
20
|
+
when "cleanup" then new.cleanup
|
|
21
|
+
else abort "Usage: bdgtr spreadsheet:dump | bdgtr spreadsheet:cleanup"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def run
|
|
26
|
+
portfolio_id = Config.drive_file_id
|
|
27
|
+
spreadsheet_id = Config.sync_drive_file_id
|
|
28
|
+
password = Config.portfolio_password
|
|
29
|
+
abort "missing PORTFOLIO_GOOGLE_DRIVE_FILE_ID" if portfolio_id.to_s.empty?
|
|
30
|
+
abort "missing SYNC_GOOGLE_DRIVE_FILE_ID" if spreadsheet_id.to_s.empty?
|
|
31
|
+
abort "missing GOOGLE_SERVICE_ACCOUNT_JSON" if Config.service_account_json.to_s.empty?
|
|
32
|
+
|
|
33
|
+
session = DriveClient.new(file_id: portfolio_id, scope: DriveClient::SYNC_SCOPE)
|
|
34
|
+
sheets = SheetsClient.new(session: session, spreadsheet_id: spreadsheet_id)
|
|
35
|
+
|
|
36
|
+
downloaded = session.download
|
|
37
|
+
loaded = PortfolioStore.load_bytes(
|
|
38
|
+
downloaded.fetch(:bytes),
|
|
39
|
+
password: password,
|
|
40
|
+
path: downloaded.dig(:meta, :name)
|
|
41
|
+
)
|
|
42
|
+
skip_rows = Config.sync_skip_rows
|
|
43
|
+
chunk_size = Config.sync_rows_chunk
|
|
44
|
+
preview_rows = Config.sync_preview_rows
|
|
45
|
+
names = TransactionSync.uuid_names(loaded.client)
|
|
46
|
+
gids = sheets.sheet_gids
|
|
47
|
+
known_sheets = gids.keys
|
|
48
|
+
portfolio_changed = false
|
|
49
|
+
|
|
50
|
+
unique_titles(TransactionSync.vehicles(loaded.client)).each do |title, vehicle|
|
|
51
|
+
raw_rows = known_sheets.include?(title) ? sheets.read_rows(title) : []
|
|
52
|
+
sheet_plan, portfolio_plan = account_plans(
|
|
53
|
+
loaded.client, vehicle, raw_rows, names, skip_rows
|
|
54
|
+
)
|
|
55
|
+
puts "#{sheet_link(vehicle.name, spreadsheet_id, gids[title])}: " \
|
|
56
|
+
"spreadsheet +#{sheet_plan.create_sheet.size}/~#{sheet_plan.update_sheet.size} " \
|
|
57
|
+
"portfolio +#{portfolio_plan.create_portfolio.size}/~#{portfolio_plan.update_portfolio.size}"
|
|
58
|
+
|
|
59
|
+
if empty_plan?(sheet_plan) && empty_plan?(portfolio_plan)
|
|
60
|
+
puts "#{vehicle.name}: already in sync"
|
|
61
|
+
next
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
choice = preview_account(vehicle.name, sheet_plan, portfolio_plan, preview_rows)
|
|
65
|
+
if choice == "N"
|
|
66
|
+
puts "#{vehicle.name}: skipped"
|
|
67
|
+
next
|
|
68
|
+
end
|
|
69
|
+
if %w[S B].include?(choice)
|
|
70
|
+
unless sheet_plan.create_sheet.empty? && sheet_plan.update_sheet.empty?
|
|
71
|
+
unless known_sheets.include?(title)
|
|
72
|
+
sheets.ensure_sheet(title, known_titles: known_sheets)
|
|
73
|
+
known_sheets << title
|
|
74
|
+
end
|
|
75
|
+
TransactionSync.apply_sheet(
|
|
76
|
+
sheets, title, sheet_plan,
|
|
77
|
+
skip_rows: skip_rows, chunk_size: chunk_size, raw_rows: raw_rows, kind: vehicle.kind
|
|
78
|
+
)
|
|
79
|
+
puts "#{vehicle.name}: spreadsheet written"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
if %w[P B].include?(choice)
|
|
83
|
+
records = portfolio_plan.create_portfolio + portfolio_plan.update_portfolio
|
|
84
|
+
unless records.empty?
|
|
85
|
+
applied = TransactionSync.apply_portfolio!(
|
|
86
|
+
loaded.client,
|
|
87
|
+
vehicle,
|
|
88
|
+
records
|
|
89
|
+
)
|
|
90
|
+
if applied.positive?
|
|
91
|
+
portfolio_changed = true
|
|
92
|
+
names = TransactionSync.uuid_names(loaded.client)
|
|
93
|
+
puts "#{vehicle.name}: portfolio updated"
|
|
94
|
+
else
|
|
95
|
+
puts "#{vehicle.name}: portfolio unchanged"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
if portfolio_changed
|
|
102
|
+
session.upload(PortfolioStore.dump(loaded))
|
|
103
|
+
puts "Uploaded portfolio #{downloaded.dig(:meta, :name)}"
|
|
104
|
+
else
|
|
105
|
+
puts "Portfolio file unchanged"
|
|
106
|
+
end
|
|
107
|
+
rescue Error, ArgumentError => error
|
|
108
|
+
abort error.message
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def cleanup(sheets: nil, spreadsheet_id: nil, skip_rows: nil, titles: nil)
|
|
112
|
+
spreadsheet_id = spreadsheet_id.to_s.empty? ? Config.sync_drive_file_id : spreadsheet_id
|
|
113
|
+
skip_rows = skip_rows.nil? ? Config.sync_skip_rows : skip_rows
|
|
114
|
+
if sheets.nil?
|
|
115
|
+
abort "missing SYNC_GOOGLE_DRIVE_FILE_ID" if spreadsheet_id.to_s.empty?
|
|
116
|
+
abort "missing GOOGLE_SERVICE_ACCOUNT_JSON" if Config.service_account_json.to_s.empty?
|
|
117
|
+
abort "missing PORTFOLIO_GOOGLE_DRIVE_FILE_ID" if Config.drive_file_id.to_s.empty?
|
|
118
|
+
|
|
119
|
+
session = DriveClient.new(file_id: Config.drive_file_id, scope: DriveClient::SYNC_SCOPE)
|
|
120
|
+
sheets = SheetsClient.new(session: session, spreadsheet_id: spreadsheet_id)
|
|
121
|
+
downloaded = session.download
|
|
122
|
+
loaded = PortfolioStore.load_bytes(
|
|
123
|
+
downloaded.fetch(:bytes),
|
|
124
|
+
password: Config.portfolio_password,
|
|
125
|
+
path: downloaded.dig(:meta, :name)
|
|
126
|
+
)
|
|
127
|
+
titles ||= unique_titles(TransactionSync.vehicles(loaded.client)).keys
|
|
128
|
+
end
|
|
129
|
+
gids = sheets.respond_to?(:sheet_gids) ? sheets.sheet_gids : {}
|
|
130
|
+
titles ||= gids.keys
|
|
131
|
+
known_sheets = gids.keys
|
|
132
|
+
known_sheets = sheets.sheet_titles if known_sheets.empty?
|
|
133
|
+
|
|
134
|
+
clear_rest = false
|
|
135
|
+
titles.each do |title|
|
|
136
|
+
unless known_sheets.include?(title)
|
|
137
|
+
puts "#{title}: no sheet, skipped"
|
|
138
|
+
next
|
|
139
|
+
end
|
|
140
|
+
raw_rows = sheets.read_rows(title)
|
|
141
|
+
unless data_rows?(raw_rows, skip_rows)
|
|
142
|
+
puts "#{title}: already empty"
|
|
143
|
+
next
|
|
144
|
+
end
|
|
145
|
+
unless clear_rest
|
|
146
|
+
choice = confirm_cleanup(spreadsheet_id, title, gid: gids[title])
|
|
147
|
+
if choice == :no
|
|
148
|
+
puts "#{title}: skipped"
|
|
149
|
+
next
|
|
150
|
+
end
|
|
151
|
+
clear_rest = true if choice == :all
|
|
152
|
+
end
|
|
153
|
+
sheets.clear_data_rows(title, skip_rows: skip_rows)
|
|
154
|
+
puts "#{title}: spreadsheet rows cleared"
|
|
155
|
+
end
|
|
156
|
+
rescue Error, ArgumentError => error
|
|
157
|
+
abort error.message
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def self.confirm_choice(answer)
|
|
161
|
+
text = answer.to_s
|
|
162
|
+
return :no if text.empty? || text == "\e" || text.start_with?("\e")
|
|
163
|
+
|
|
164
|
+
case text.strip.upcase
|
|
165
|
+
when "Y", "YES" then :yes
|
|
166
|
+
when "A", "ALL" then :all
|
|
167
|
+
else :no
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
private
|
|
172
|
+
|
|
173
|
+
def account_plans(client, vehicle, raw_rows, names, skip_rows)
|
|
174
|
+
plan = TransactionSync.account_plan(
|
|
175
|
+
client, vehicle, raw_rows, names: names, skip_rows: skip_rows
|
|
176
|
+
)
|
|
177
|
+
TransactionSync.split_plan(plan)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def empty_plan?(plan)
|
|
181
|
+
plan.create_sheet.empty? && plan.update_sheet.empty? &&
|
|
182
|
+
plan.create_portfolio.empty? && plan.update_portfolio.empty?
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def preview_account(account_name, sheet_plan, portfolio_plan, page_size)
|
|
186
|
+
portfolio_lines, sheet_lines = SyncPreview.lines_for(
|
|
187
|
+
TransactionSync::Plan.new(
|
|
188
|
+
create_sheet: sheet_plan.create_sheet,
|
|
189
|
+
update_sheet: sheet_plan.update_sheet,
|
|
190
|
+
create_portfolio: portfolio_plan.create_portfolio,
|
|
191
|
+
update_portfolio: portfolio_plan.update_portfolio
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
SyncPreview.new(
|
|
195
|
+
account_name,
|
|
196
|
+
portfolio_lines,
|
|
197
|
+
sheet_lines,
|
|
198
|
+
page_size: page_size,
|
|
199
|
+
portfolio_counts: {
|
|
200
|
+
create: portfolio_plan.create_portfolio.size,
|
|
201
|
+
update: portfolio_plan.update_portfolio.size
|
|
202
|
+
},
|
|
203
|
+
sheet_counts: {
|
|
204
|
+
create: sheet_plan.create_sheet.size,
|
|
205
|
+
update: sheet_plan.update_sheet.size
|
|
206
|
+
}
|
|
207
|
+
).run
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def unique_titles(accounts)
|
|
211
|
+
titles = SheetsClient.unique_titles(accounts)
|
|
212
|
+
titles.zip(accounts).to_h
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def data_rows?(raw_rows, skip_rows)
|
|
216
|
+
Array(raw_rows)[(Integer(skip_rows) + 1)..]&.any? { |row| Array(row).any? { |cell| !cell.to_s.strip.empty? } }
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def sheet_link(label, spreadsheet_id, gid = nil)
|
|
220
|
+
SheetsClient.terminal_link(label, SheetsClient.spreadsheet_url(spreadsheet_id, gid: gid))
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def confirm_cleanup(spreadsheet_id, title, gid: nil)
|
|
224
|
+
linked_id = sheet_link(spreadsheet_id, spreadsheet_id)
|
|
225
|
+
linked_sheet = sheet_link(title, spreadsheet_id, gid)
|
|
226
|
+
prompt = "All rows > headers in #{linked_id}, sheet #{linked_sheet} will be deleted: are you sure? y/n/a "
|
|
227
|
+
$stderr.print prompt
|
|
228
|
+
$stderr.flush
|
|
229
|
+
choice = $stdin.tty? ? read_cleanup_key : self.class.confirm_choice($stdin.gets.to_s)
|
|
230
|
+
$stderr.puts({ yes: "y", no: "n", all: "a" }.fetch(choice))
|
|
231
|
+
choice
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def read_cleanup_key
|
|
235
|
+
reader = TTY::Reader.new(interrupt: :exit)
|
|
236
|
+
choice = nil
|
|
237
|
+
reader.on(:keyescape) { choice = :no }
|
|
238
|
+
reader.on(:keypress) do |event|
|
|
239
|
+
choice = :yes if %w[y Y].include?(event.value)
|
|
240
|
+
choice = :no if %w[n N].include?(event.value) || event.value == "\e"
|
|
241
|
+
choice = :all if %w[a A].include?(event.value)
|
|
242
|
+
end
|
|
243
|
+
reader.read_keypress until choice
|
|
244
|
+
choice
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tty-screen"
|
|
4
|
+
|
|
5
|
+
require_relative "row_preview"
|
|
6
|
+
|
|
7
|
+
module PortfolioPerformanceApi
|
|
8
|
+
class SyncPreview
|
|
9
|
+
ROW_INDENT = 2
|
|
10
|
+
ELLIPSIS = "..."
|
|
11
|
+
|
|
12
|
+
def self.format_record(record, action, width: TTY::Screen.width)
|
|
13
|
+
amount = format("%.2f", (record.signed_cents / 100.0).round(2))
|
|
14
|
+
prefix = "#{action} #{record.date} #{record.type.to_s.ljust(16)} #{amount.rjust(10)} #{record.currency} "
|
|
15
|
+
dest = record.destination.to_s.empty? ? "" : " → #{record.destination}"
|
|
16
|
+
available = [Integer(width) - ROW_INDENT - prefix.size, 0].max
|
|
17
|
+
"#{prefix}#{fit_note(record.description.to_s, dest, available)}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.lines_for(plan, width: TTY::Screen.width)
|
|
21
|
+
portfolio = Array(plan.update_portfolio).map { |record| format_record(record, "~", width: width) } +
|
|
22
|
+
Array(plan.create_portfolio).map { |record| format_record(record, "+", width: width) }
|
|
23
|
+
spreadsheet = Array(plan.update_sheet).map { |record| format_record(record, "~", width: width) } +
|
|
24
|
+
Array(plan.create_sheet).map { |record| format_record(record, "+", width: width) }
|
|
25
|
+
[portfolio, spreadsheet]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.fit_note(note, dest, available)
|
|
29
|
+
if dest.size >= available
|
|
30
|
+
truncate(dest, available)
|
|
31
|
+
else
|
|
32
|
+
"#{truncate(note, available - dest.size)}#{dest}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.truncate(text, max)
|
|
37
|
+
return "" if max <= 0
|
|
38
|
+
return text if text.length <= max
|
|
39
|
+
return ELLIPSIS[0, max] if max <= ELLIPSIS.size
|
|
40
|
+
|
|
41
|
+
"#{text[0, max - ELLIPSIS.size]}#{ELLIPSIS}"
|
|
42
|
+
end
|
|
43
|
+
private_class_method :fit_note, :truncate
|
|
44
|
+
|
|
45
|
+
def initialize(account_name, portfolio_lines, spreadsheet_lines, page_size:,
|
|
46
|
+
portfolio_counts:, sheet_counts:)
|
|
47
|
+
@preview = RowPreview.new(
|
|
48
|
+
account_name,
|
|
49
|
+
[
|
|
50
|
+
RowPreview::Section.new(title: "PORTFOLIO", lines: portfolio_lines, counts: portfolio_counts),
|
|
51
|
+
RowPreview::Section.new(title: "SPREADSHEET", lines: spreadsheet_lines, counts: sheet_counts)
|
|
52
|
+
],
|
|
53
|
+
page_size: page_size,
|
|
54
|
+
prompt: "[#{account_name}] write (S)spreadsheet, (P)ortfolio or (B)oth?",
|
|
55
|
+
choices: %w[S P B]
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def run
|
|
60
|
+
@preview.run
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
|
|
5
|
+
module PortfolioPerformanceApi
|
|
6
|
+
class TransactionIdentity
|
|
7
|
+
SEPARATOR = "\u001f"
|
|
8
|
+
|
|
9
|
+
attr_reader :account_name, :date, :signed_cents, :description, :destination, :security
|
|
10
|
+
|
|
11
|
+
def initialize(account_name:, date:, signed_cents:, description:, destination: "", security: "")
|
|
12
|
+
@account_name = account_name.to_s.strip
|
|
13
|
+
@date = date
|
|
14
|
+
@signed_cents = Integer(signed_cents)
|
|
15
|
+
@description = self.class.normalize_description(description)
|
|
16
|
+
@destination = destination.to_s.strip
|
|
17
|
+
@security = security.to_s.strip
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def id
|
|
21
|
+
Digest::SHA256.hexdigest(
|
|
22
|
+
[
|
|
23
|
+
@account_name,
|
|
24
|
+
@date.strftime("%Y-%m-%d"),
|
|
25
|
+
@signed_cents.to_s,
|
|
26
|
+
@description,
|
|
27
|
+
@destination,
|
|
28
|
+
@security
|
|
29
|
+
].join(SEPARATOR)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
alias to_s id
|
|
33
|
+
|
|
34
|
+
def self.id(account_name, date, signed_cents, description, destination = "", security = "")
|
|
35
|
+
new(
|
|
36
|
+
account_name: account_name,
|
|
37
|
+
date: date,
|
|
38
|
+
signed_cents: signed_cents,
|
|
39
|
+
description: description,
|
|
40
|
+
destination: destination,
|
|
41
|
+
security: security
|
|
42
|
+
).id
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.normalize_description(value)
|
|
46
|
+
value.to_s.strip.gsub(/\s+/, " ")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|