Class: Documents::YNAB4Files::YNAB4File

Inherits:
Object
  • Object
show all
Defined in:
lib/ynab_convert/documents/ynab4_files/ynab4_file.rb

Overview

Represents the YNAB4 formatted CSV data for importing into YNAB4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ YNAB4File

Returns a new instance of YNAB4File.



9
10
11
12
13
14
15
16
17
18
# File 'lib/ynab_convert/documents/ynab4_files/ynab4_file.rb', line 9

def initialize(options = {})
  @format = options[:format] || :flows
  @institution_name = options[:institution_name]
  @csv_export_options = {
    converters: %i[numeric date],
    force_quotes: true,
    write_headers: true,
    headers: headers
  }
end

Instance Attribute Details

#csv_export_optionsObject (readonly)

Returns the value of attribute csv_export_options.



7
8
9
# File 'lib/ynab_convert/documents/ynab4_files/ynab4_file.rb', line 7

def csv_export_options
  @csv_export_options
end

Instance Method Details

#filenameObject



31
32
33
34
35
36
# File 'lib/ynab_convert/documents/ynab4_files/ynab4_file.rb', line 31

def filename
  from_date = @start_date.strftime('%Y%m%d')
  to_date = @end_date.strftime('%Y%m%d')

  "#{@institution_name.snake_case}_#{from_date}-#{to_date}_ynab4.csv"
end

#update_dates(row) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/ynab_convert/documents/ynab4_files/ynab4_file.rb', line 20

def update_dates(row)
  date_index = 0
  transaction_date = row[date_index]
  unless transaction_date.is_a?(Date)
    transaction_date = Date.parse(transaction_date)
  end

  update_start_date(transaction_date)
  update_end_date(transaction_date)
end