Class: SEPA::Profile
- Inherits:
-
Data
- Object
- Data
- SEPA::Profile
- Defined in:
- lib/sepa_rator/profile.rb
Instance Attribute Summary collapse
-
#accept_transaction ⇒ Object
readonly
Returns the value of attribute accept_transaction.
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#group_header_stages ⇒ Object
readonly
Returns the value of attribute group_header_stages.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#iso_schema ⇒ Object
readonly
Returns the value of attribute iso_schema.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#payment_info_stages ⇒ Object
readonly
Returns the value of attribute payment_info_stages.
-
#transaction_stages ⇒ Object
readonly
Returns the value of attribute transaction_stages.
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
-
#xsd_path ⇒ Object
readonly
Returns the value of attribute xsd_path.
Instance Method Summary collapse
- #accepts?(transaction) ⇒ Boolean
-
#initialize(**attrs) ⇒ Profile
constructor
A new instance of Profile.
- #supports?(capability) ⇒ Boolean
- #with(**overrides) ⇒ Object
Constructor Details
#initialize(**attrs) ⇒ Profile
Returns a new instance of Profile.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sepa_rator/profile.rb', line 90 def initialize(**attrs) unless PROFILE_FAMILIES.include?(attrs[:family]) raise ArgumentError, "Profile #{attrs[:id].inspect} has invalid family #{attrs[:family].inspect}; " \ "expected one of #{PROFILE_FAMILIES.inspect}" end # Freeze collection fields so a caller cannot mutate a registered # profile's arrays under our feet. Individual stages/validators are # classes (already immutable by reference). %i[validators capabilities transaction_stages payment_info_stages group_header_stages] .each { |key| attrs[key] = attrs[key].dup.freeze unless attrs[key].frozen? } # Catch "forgot to point at a stage class" coquilles at registration # time instead of at XML build time. %i[transaction_stages payment_info_stages group_header_stages].each do |key| attrs[key].each do |stage| raise ArgumentError, "Profile #{attrs[:id].inspect} #{key} contains #{stage.inspect} which does not respond to .call" unless stage.respond_to?(:call) end end super end |
Instance Attribute Details
#accept_transaction ⇒ Object (readonly)
Returns the value of attribute accept_transaction
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def accept_transaction @accept_transaction end |
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def capabilities @capabilities end |
#family ⇒ Object (readonly)
Returns the value of attribute family
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def family @family end |
#features ⇒ Object (readonly)
Returns the value of attribute features
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def features @features end |
#group_header_stages ⇒ Object (readonly)
Returns the value of attribute group_header_stages
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def group_header_stages @group_header_stages end |
#id ⇒ Object (readonly)
Returns the value of attribute id
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def id @id end |
#iso_schema ⇒ Object (readonly)
Returns the value of attribute iso_schema
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def iso_schema @iso_schema end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def namespace @namespace end |
#payment_info_stages ⇒ Object (readonly)
Returns the value of attribute payment_info_stages
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def payment_info_stages @payment_info_stages end |
#transaction_stages ⇒ Object (readonly)
Returns the value of attribute transaction_stages
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def transaction_stages @transaction_stages end |
#validators ⇒ Object (readonly)
Returns the value of attribute validators
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def validators @validators end |
#xsd_path ⇒ Object (readonly)
Returns the value of attribute xsd_path
76 77 78 |
# File 'lib/sepa_rator/profile.rb', line 76 def xsd_path @xsd_path end |
Instance Method Details
#accepts?(transaction) ⇒ Boolean
118 119 120 |
# File 'lib/sepa_rator/profile.rb', line 118 def accepts?(transaction) accept_transaction.nil? || accept_transaction.call(transaction, self) end |
#supports?(capability) ⇒ Boolean
114 115 116 |
# File 'lib/sepa_rator/profile.rb', line 114 def supports?(capability) capabilities.include?(capability) end |
#with(**overrides) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/sepa_rator/profile.rb', line 122 def with(**overrides) merged = overrides.each_with_object(to_h.dup) do |(key, value), acc| acc[key] = merge_field(key, acc[key], value) end self.class.new(**merged) end |