Method: ACH::Component#initialize

Defined in:
lib/ach/component.rb

#initialize(fields = {}) ⇒ Component

Initialize component with field values. If block is given, it is evaluated in context of component, allowing setting fields via method calls and declarations of nested components.

Parameters:

  • fields (Hash) (defaults to: {})

Raises:



73
74
75
76
77
78
79
80
81
# File 'lib/ach/component.rb', line 73

def initialize(fields = {})
  @attributes = self.class.default_attributes.dup
  fields.each do |name, value|
    raise UnknownAttributeError.new(name, self) unless Formatter.defined?(name)
    @attributes[name] = value
  end
  after_initialize
  instance_eval(&Proc.new) if block_given?
end