Class: OFX::Configuration::SectionProxy
- Inherits:
-
Object
- Object
- OFX::Configuration::SectionProxy
- Defined in:
- lib/ofx_kit/configuration/section_proxy.rb
Overview
Proxy object returned by section accessors (e.g. OFX.config.transaction). Provides a fluent interface for adding individual user-layer field mappings.
Instance Method Summary collapse
-
#initialize(user_fields, core_fields, xml_tag) ⇒ SectionProxy
constructor
A new instance of SectionProxy.
-
#map(xml_key, to:) ⇒ Object
Maps
xml_key(the OFX XML element name, String) to a Ruby attribute name via thetokeyword (String or Symbol) for this section.
Constructor Details
#initialize(user_fields, core_fields, xml_tag) ⇒ SectionProxy
Returns a new instance of SectionProxy.
9 10 11 12 13 |
# 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 |
Instance Method Details
#map(xml_key, to:) ⇒ Object
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"
27 28 29 30 31 32 33 34 35 36 |
# 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 |