class OFX::Configuration
Manages XML-to-Ruby field mappings used during OFX document parsing.
Mappings are split into two layers:
-
Core (
core_mappings.yml): OFX-standard fields whose Ruby attribute names are referenced by name inside Base::Builder. These cannot be overridden. -
User (
field_mappings.yml): convenience mappings that can be added to or replaced at runtime viaload_mappingsor theOFX.configureblock.
Constants
- CORE_MAPPINGS_PATH
-
Absolute path to the built-in core
OFXfield mappings (read-only). - MAPPINGS_PATH
-
Absolute path to the built-in user-layer field mappings.
- RAILS_MAPPINGS_PATH
-
Conventional path for user mappings in a Rails application. Auto-loaded on boot when present. Ejected via +rails generate ofx_kit:eject+.
Attributes
Controls whether a warning is emitted when OFX::Parser#transactions or OFX::Parser#balances aggregate across multiple statements. Defaults to true.
Public Class Methods
Source
# File lib/ofx_kit/configuration/core.rb, line 43 def initialize(auto_load_path: File.expand_path(RAILS_MAPPINGS_PATH)) @multi_statement_warnings = true core = YAML.safe_load_file(CORE_MAPPINGS_PATH) @sections = core.fetch('SECTIONS', {}) @core_fields = core.fetch('FIELDS', {}) @section_to_tag = @sections.invert user = YAML.safe_load_file(MAPPINGS_PATH) @user_fields = user.fetch('FIELDS', {}) load_mappings(auto_load_path) if File.exist?(auto_load_path) end
Creates a new Configuration instance. auto_load_path is the path to a YAML mappings file loaded automatically on initialization. Defaults to RAILS_MAPPINGS_PATH expanded from the working directory.
Public Instance Methods
Source
# File lib/ofx_kit/configuration/core.rb, line 79 def balance = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:balance))
Returns a SectionProxy for balance field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 71 def bank_account = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:bank_account))
Returns a SectionProxy for bank account field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 59 def bank_statement = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:bank_statement))
Returns a SectionProxy for bank statement field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 75 def credit_card_account = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:credit_card_account))
Returns a SectionProxy for credit card account field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 63 def credit_card_statement = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:credit_card_statement))
Returns a SectionProxy for credit card statement field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 119 def load_mappings(path) raise Errors::ConfigurationError, "Mappings file not found: #{path}" unless File.exist?(path) raw = YAML.safe_load_file(path) raise Errors::ConfigurationError, 'Invalid mappings file: expected a Hash' unless raw.is_a?(Hash) fields = raw.fetch('FIELDS') do raise Errors::ConfigurationError, "Invalid mappings file: missing top-level 'FIELDS' key" end fields.each { |tag, mappings| merge_user_section(tag, mappings) } end
Merges additional field mappings from a YAML file at path (String) into the user-layer configuration. The file must have a top-level FIELDS key. Core OFX fields cannot be overridden.
Raises Errors::ConfigurationError if the file is missing, malformed, references unknown sections, or attempts to override a core field mapping.
Example: Load a custom mappings file
OFX.configure do |config| config.load_mappings 'config/my_ofx_mappings.yml' end
Example: Expected YAML format
# config/my_ofx_mappings.yml
FIELDS:
STMTTRN:
MYFIELD: my_attribute
Source
# File lib/ofx_kit/configuration/core.rb, line 35 def multi_statement_warnings? @multi_statement_warnings end
Returns true if multi-statement aggregation warnings are enabled.
Source
# File lib/ofx_kit/configuration/core.rb, line 67 def transaction = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:transaction))
Returns a SectionProxy for transaction field mappings.
Source
# File lib/ofx_kit/configuration/core.rb, line 92 def xml_mappings_for(section_name) tag = xml_tag_for(section_name) return {} unless tag (@core_fields[tag] || {}).merge(@user_fields[tag] || {}) end
Returns the merged Hash of XML tag to Ruby attribute mappings for the given section_name (String or Symbol). Core mappings take precedence; user mappings extend them.
Source
# File lib/ofx_kit/configuration/core.rb, line 84 def xml_tag_for(section_name) @section_to_tag[section_name.to_s] end
Returns the OFX XML tag name corresponding to the given section_name (String or Symbol), e.g. :transaction. Returns nil if not found.