Class: FindSubscriptions::UserSchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/find_subscriptions/user_schema_builder.rb

Overview

Builds a CsvSchema from a user-provided YAML configuration hash.

Supported direction strategies:

positive_debit   — positive amounts are outgoing (e.g. AmEx)
negative_debit   — negative amounts are outgoing (e.g. generic bank export)
indicator_column — a separate column holds "Debit"/"Credit" labels

Constant Summary collapse

BASE_REQUIRED_KEYS =
%w[required_headers amount_key direction date_column date_format payee_column].freeze
DIRECTION_STRATEGIES =

Simple direction lambdas: amount sign alone determines debit/credit. indicator_column is handled separately since it needs config context.

{
  'positive_debit' => ->(_row, amount) { amount.positive? ? :debit : :credit },
  'negative_debit' => ->(_row, amount) { amount.negative? ? :debit : :credit }
}.freeze

Class Method Summary collapse

Class Method Details

.build(name, config) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/find_subscriptions/user_schema_builder.rb', line 24

def self.build(name, config)
  validate_base!(name, config)
  CsvSchema.new(
    required_headers: config.fetch('required_headers'),
    amount_key: config.fetch('amount_key'),
    direction: build_direction(name, config),
    mapping: build_mapping(config)
  )
end