Class: OFX::Configuration
- Inherits:
-
Object
- Object
- OFX::Configuration
- Defined in:
- lib/ofx_kit/configuration/core.rb,
lib/ofx_kit/configuration/date_parser.rb,
lib/ofx_kit/configuration/section_proxy.rb,
lib/ofx_kit/configuration/mapping_applicator.rb
Overview
Manages XML-to-Ruby field mappings used during OFX document parsing.
Mappings are resolved in three layers (last wins):
-
Core (
core_mappings.yml): OFX-standard fields referenced by name inside Base::Builder. These cannot be overridden. -
Default (
field_mappings.yml): built-in convenience mappings (e.g. FITID → fit_id). They can be renamed via the OFX.configure block. -
User: explicit mappings added at runtime via the OFX.configure block.
Defined Under Namespace
Modules: DateParser, MappingApplicator Classes: SectionProxy
Constant Summary collapse
- CORE_MAPPINGS_PATH =
Absolute path to the built-in core OFX field mappings (read-only).
File.join(__dir__, '..', 'mappings', 'core_mappings.yml')
- MAPPINGS_PATH =
Absolute path to the built-in default field mappings.
File.join(__dir__, '..', 'mappings', 'field_mappings.yml')
Instance Attribute Summary collapse
-
#multi_statement_warnings ⇒ Object
writeonly
Controls whether a warning is emitted when OFX::Parser#transactions or OFX::Parser#balances aggregate across multiple statements.
Instance Method Summary collapse
-
#balance ⇒ Object
Returns a SectionProxy for balance field mappings.
-
#bank_account ⇒ Object
Returns a SectionProxy for bank account field mappings.
-
#bank_statement ⇒ Object
Returns a SectionProxy for bank statement field mappings.
-
#credit_card_account ⇒ Object
Returns a SectionProxy for credit card account field mappings.
-
#credit_card_statement ⇒ Object
Returns a SectionProxy for credit card statement field mappings.
-
#initialize ⇒ Configuration
constructor
Creates a new Configuration instance with the built-in field mappings loaded.
-
#multi_statement_warnings? ⇒ Boolean
Returns
trueif multi-statement aggregation warnings are enabled. -
#transaction ⇒ Object
Returns a SectionProxy for transaction field mappings.
-
#xml_mappings_for(section_name) ⇒ Object
Returns the merged Hash of XML tag to Ruby attribute mappings for the given
section_name(String or Symbol). -
#xml_tag_for(section_name) ⇒ Object
Returns the OFX XML tag name corresponding to the given
section_name(String or Symbol), e.g.
Constructor Details
#initialize ⇒ Configuration
Creates a new Configuration instance with the built-in field mappings loaded.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ofx_kit/configuration/core.rb', line 38 def initialize @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 defaults = YAML.safe_load_file(MAPPINGS_PATH) @default_fields = defaults.fetch('FIELDS', {}) @user_fields = {} end |
Instance Attribute Details
#multi_statement_warnings=(value) ⇒ Object (writeonly)
Controls whether a warning is emitted when OFX::Parser#transactions or OFX::Parser#balances aggregate across multiple statements. Defaults to true.
28 29 30 |
# File 'lib/ofx_kit/configuration/core.rb', line 28 def multi_statement_warnings=(value) @multi_statement_warnings = value end |
Instance Method Details
#balance ⇒ Object
Returns a SectionProxy for balance field mappings.
74 |
# File 'lib/ofx_kit/configuration/core.rb', line 74 def balance = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:balance)) |
#bank_account ⇒ Object
Returns a SectionProxy for bank account field mappings.
66 |
# File 'lib/ofx_kit/configuration/core.rb', line 66 def bank_account = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:bank_account)) |
#bank_statement ⇒ Object
Returns a SectionProxy for bank statement field mappings.
54 |
# File 'lib/ofx_kit/configuration/core.rb', line 54 def bank_statement = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:bank_statement)) |
#credit_card_account ⇒ Object
Returns a SectionProxy for credit card account field mappings.
70 |
# File 'lib/ofx_kit/configuration/core.rb', line 70 def credit_card_account = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:credit_card_account)) |
#credit_card_statement ⇒ Object
Returns a SectionProxy for credit card statement field mappings.
58 |
# File 'lib/ofx_kit/configuration/core.rb', line 58 def credit_card_statement = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:credit_card_statement)) |
#multi_statement_warnings? ⇒ Boolean
Returns true if multi-statement aggregation warnings are enabled.
32 33 34 |
# File 'lib/ofx_kit/configuration/core.rb', line 32 def multi_statement_warnings? @multi_statement_warnings end |
#transaction ⇒ Object
Returns a SectionProxy for transaction field mappings.
62 |
# File 'lib/ofx_kit/configuration/core.rb', line 62 def transaction = SectionProxy.new(@user_fields, @core_fields, xml_tag_for(:transaction)) |
#xml_mappings_for(section_name) ⇒ Object
Returns the merged Hash of XML tag to Ruby attribute mappings for the given section_name (String or Symbol). Resolution order: core → default → user (user wins).
87 88 89 90 91 92 93 94 |
# File 'lib/ofx_kit/configuration/core.rb', line 87 def xml_mappings_for(section_name) tag = xml_tag_for(section_name) return {} unless tag (@core_fields[tag] || {}) .merge(@default_fields[tag] || {}) .merge(@user_fields[tag] || {}) end |
#xml_tag_for(section_name) ⇒ Object
Returns the OFX XML tag name corresponding to the given section_name (String or Symbol), e.g. :transaction. Returns nil if not found.
79 80 81 |
# File 'lib/ofx_kit/configuration/core.rb', line 79 def xml_tag_for(section_name) @section_to_tag[section_name.to_s] end |