Sha256: 829cf055159db1408c5d957cee33b71865bf6aec0d843277e01461b5b030d715

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Documents
  module Statements
    # The base Statement class from which other Statements inherit.
    # Represents a CSV statement from a financial institution, typically from
    # its online banking portal.
    class Statement
      attr_reader :csv_import_options, :filepath

      # @param filepath [String] path to the CSV file
      # @param csv_import_options [CSV::DEFAULT_OPTIONS] options describing
      #   the particular CSV flavour (column separator, etc). Any
      #   CSV::DEFAULT_OPTIONS is valid.
      def initialize(filepath:, csv_import_options: CSV::DEFAULT_OPTIONS)
        validate(filepath)

        default_options = CSV::DEFAULT_OPTIONS.merge(converters: %i[numeric
                                                                    date])
        @filepath = filepath
        @csv_import_options = default_options.merge(csv_import_options)
      end

      def institution_name
        self.class.name.split('::').last
      end

      private

      # Verifies that the file exists at path, raises an error if not.
      # @param path [String] path to the file
      def validate(path)
        return if ::File.exist?(path)

        raise Errno::ENOENT, "file not found #{path}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ynab_convert-2.0.6 lib/ynab_convert/documents/statements/statement.rb
ynab_convert-2.0.5 lib/ynab_convert/documents/statements/statement.rb
ynab_convert-2.0.4 lib/ynab_convert/documents/statements/statement.rb
ynab_convert-2.0.3 lib/ynab_convert/documents/statements/statement.rb
ynab_convert-2.0.1 lib/ynab_convert/documents/statements/statement.rb
ynab_convert-2.0.0 lib/ynab_convert/documents/statements/statement.rb