Module: ACH::Formatter

Extended by:
Formatter
Included in:
Formatter
Defined in:
lib/ach/formatter.rb

Constant Summary collapse

RULES =
{
  :customer_name          => '<-22',
  :customer_acct          => '<-15',
  :amount                 => '->10',
  :bank_2                 => '<-2',
  :transaction_type       => '<-2',
  :bank_15                => '<-15',
  :addenda                => '<-1',
  :trace_num              => '<-15',
  :transaction_code       => '<-2',
  :record_type            => '<-1',
  :bank_account           => '<-17',
  :routing_number         => '->9',
  :priority_code          => '->2',
  :immediate_dest         => '->10-',
  :immediate_origin       => '->10-',
  :date                   => '<-6',
  :time                   => '<-4',
  :file_id_modifier       => '<-1|upcase',
  :record_size            => '->3',
  :blocking_factor        => '->2',
  :format_code            => '<-1',
  :immediate_dest_name    => '<-23',
  :immediate_origin_name  => '<-23',
  :reference_code         => '<-8',
  :service_class_code     => '<-3',
  :company_name           => '<-16',
  :company_note_data      => '<-20',
  :company_id             => '<-10',
  :entry_class_code       => '<-3',
  :company_entry_descr    => '<-10',
  :effective_date         => '<-6',
  :settlement_date        => '<-3',
  :origin_status_code     => '<-1',
  :origin_dfi_id          => '<-8',
  :batch_number           => '->7',
  :entry_count            => '->6',
  :entry_hash             => '->10',
  :total_debit_amount     => '->12',
  :total_credit_amount    => '->12',
  :authen_code            => '<-19',
  :bank_6                 => '<-6',
  :batch_count            => '->6',
  :block_count            => '->6',
  :file_entry_count       => '->8',
  :bank_39                => '<-39',
  :nines                  => '<-94'
}.freeze
RULE_PARSER_REGEX =
/^(<-|->)(\d+)(-)?(\|\w+)?$/
@@compiled_rules =
{}

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/ach/formatter.rb', line 63

def method_missing meth, *args
  if RULES.key? meth
    format meth, *args
  else
    super
  end
end

Instance Method Details

#format(field_name, value) ⇒ Object



58
59
60
61
# File 'lib/ach/formatter.rb', line 58

def format field_name, value
  compile_rule(field_name) unless @@compiled_rules.key?(field_name)
  @@compiled_rules[field_name].call(value)
end