Class: SEPA::Profile

Inherits:
Data
  • Object
show all
Defined in:
lib/sepa_rator/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_transactionObject (readonly)

Returns the value of attribute accept_transaction

Returns:

  • (Object)

    the current value of accept_transaction



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def accept_transaction
  @accept_transaction
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities

Returns:

  • (Object)

    the current value of capabilities



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def capabilities
  @capabilities
end

#familyObject (readonly)

Returns the value of attribute family

Returns:

  • (Object)

    the current value of family



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def family
  @family
end

#featuresObject (readonly)

Returns the value of attribute features

Returns:

  • (Object)

    the current value of features



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def features
  @features
end

#group_header_stagesObject (readonly)

Returns the value of attribute group_header_stages

Returns:

  • (Object)

    the current value of group_header_stages



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def group_header_stages
  @group_header_stages
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def id
  @id
end

#iso_schemaObject (readonly)

Returns the value of attribute iso_schema

Returns:

  • (Object)

    the current value of iso_schema



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def iso_schema
  @iso_schema
end

#namespaceObject (readonly)

Returns the value of attribute namespace

Returns:

  • (Object)

    the current value of namespace



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def namespace
  @namespace
end

#payment_info_stagesObject (readonly)

Returns the value of attribute payment_info_stages

Returns:

  • (Object)

    the current value of payment_info_stages



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def payment_info_stages
  @payment_info_stages
end

#transaction_stagesObject (readonly)

Returns the value of attribute transaction_stages

Returns:

  • (Object)

    the current value of transaction_stages



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def transaction_stages
  @transaction_stages
end

#validatorsObject (readonly)

Returns the value of attribute validators

Returns:

  • (Object)

    the current value of validators



76
77
78
# File 'lib/sepa_rator/profile.rb', line 76

def validators
  @validators
end

#xsd_pathObject (readonly)

Returns the value of attribute xsd_path

Returns:

  • (Object)

    the current value of 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

Returns:

  • (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

Returns:

  • (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