Class: MFYNAB::MoneyForwardData
- Inherits:
-
Object
- Object
- MFYNAB::MoneyForwardData
- Defined in:
- lib/mfynab/money_forward_data.rb
Constant Summary collapse
- HEADERS =
{ include: "計算対象", date: "日付", content: "内容", amount: "金額(円)", account: "保有金融機関", category: "大項目", subcategory: "中項目", memo: "メモ", transfer: "振替", id: "ID", }.freeze
Instance Method Summary collapse
-
#initialize(logger:) ⇒ MoneyForwardData
constructor
A new instance of MoneyForwardData.
- #read_all_csv(path) ⇒ Object
- #read_csv(csv_file) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(logger:) ⇒ MoneyForwardData
Returns a new instance of MoneyForwardData.
20 21 22 23 |
# File 'lib/mfynab/money_forward_data.rb', line 20 def initialize(logger:) @transactions = {} @logger = logger end |
Instance Method Details
#read_all_csv(path) ⇒ Object
25 26 27 28 29 |
# File 'lib/mfynab/money_forward_data.rb', line 25 def read_all_csv(path) Dir[File.join(path, "*.csv")].each do |file| read_csv(file) end end |
#read_csv(csv_file) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mfynab/money_forward_data.rb', line 31 def read_csv(csv_file) logger.info("Reading #{csv_file}") CSV.foreach( csv_file, headers: true, converters: :all, header_converters: csv_header_converters, ) do |row| transactions[row["account"]] ||= [] transactions[row["account"]] << row.to_h end end |
#to_h ⇒ Object
44 45 46 |
# File 'lib/mfynab/money_forward_data.rb', line 44 def to_h transactions end |