class OFX::Configuration::SectionProxy
Proxy object returned by section accessors (e.g. OFX.config.transaction). Provides a fluent interface for adding individual user-layer field mappings.
Public Class Methods
Source
# File lib/ofx_kit/configuration/section_proxy.rb, line 9 def initialize(user_fields, core_fields, xml_tag) @user_fields = user_fields @core_fields = core_fields @xml_tag = xml_tag end
Public Instance Methods
Source
# File lib/ofx_kit/configuration/section_proxy.rb, line 27 def map(xml_key, to:) core_attr = @core_fields.dig(@xml_tag.to_s, xml_key.to_s) if core_attr raise OFX::Errors::ConfigurationError, "Cannot override core mapping '#{@xml_tag}.#{xml_key}' (reserved as '#{core_attr}')" end @user_fields[@xml_tag] ||= {} @user_fields[@xml_tag][xml_key] = to end
Maps xml_key (the OFX XML element name, String) to a Ruby attribute name via the to keyword (String or Symbol) for this section.
Raises Errors::ConfigurationError if xml_key is a core-protected field.
Example: Map a custom bank-specific field
OFX.configure do |config| config.transaction.map 'MYFIELD', to: :my_attribute end OFX.new("statement.ofx").transactions.first.my_attribute #=> "custom value"