Skip to content

Commit

Permalink
Better memo (with 200-char limit)
Browse files Browse the repository at this point in the history
Following up on #5, I tried to make the transaction memo better, while
also making sure it won't break YNAB API's current limit of 200
characters. ([Which I think should be
abolished.](ynab/ynab-sdk-ruby#77) 😬)
  • Loading branch information
davidstosik committed Jul 5, 2024
1 parent 3ef9f95 commit 158c86d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/mfynab/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def start
payee_name: row["content"][0, 100],
date: Date.strptime(row["date"], "%Y/%m/%d").strftime("%Y-%m-%d"),
cleared: "cleared",
memo: memo,
memo: generate_memo_for(row),
import_id: import_id,
}
end
Expand All @@ -215,6 +215,26 @@ def start

attr_reader :argv

def generate_memo_for(row)
category = row
.values_at("category", "subcategory")
.delete_if { _1.nil? || _1.empty? || _1 == "未分類" }
.join("/")

memo_parts = [
row["memo"], # prioritize memo if present, since it's user input
row["content"],
category,
]

memo_parts
.delete_if { _1.nil? || _1.empty? }
.join(" - ")
.slice(0, 200) # YNAB's API currently limits memo to 200 characters,
# even though YNAB itself allows longer memos. See:
# https://github.com/ynab/ynab-sdk-ruby/issues/77
end

def config_file
if argv.empty?
raise "You need to pass a config file"
Expand Down

0 comments on commit 158c86d

Please sign in to comment.