Class: AchClient::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/ach_client/providers/abstract/transformer.rb

Overview

Transforms between client class and the strings that the provider expects For example, the TransactionType classes are serialized as ‘C’ or ‘D’ for AchWorks

Class Method Summary collapse

Class Method Details

.deserialize_provider_value(string) ⇒ Class

Convert provider’s string representation to AchClient class

representation

AchClient::AccountTypes::Savings

Parameters:

  • string (String)

    string to turn into class

Returns:

  • (Class)

    for example AchClient::AccountTypes::Checking or



14
15
16
17
18
# File 'lib/ach_client/providers/abstract/transformer.rb', line 14

def self.deserialize_provider_value(string)
  self.transformer[string] or raise(
    "Unknown #{self} string #{string}"
  )
end

.serialize_to_provider_value(type) ⇒ String

Convert client class to string representation used by provider

Parameters:

  • type (Class)

    the type to convert to a string

Returns:

  • (String)

    string serialization of the input class



24
25
26
27
28
29
30
# File 'lib/ach_client/providers/abstract/transformer.rb', line 24

def self.serialize_to_provider_value(type)
  self.transformer.find do |_, v|
    type <= v
  end.try(:first) or raise(
    "type must be one of #{self.transformer.values.join(', ')}"
  )
end

.transformerHash {String => Class}

Mapping of classes to strings, to be overridden

Returns:

  • (Hash {String => Class})

    the mapping

Raises:



34
35
36
# File 'lib/ach_client/providers/abstract/transformer.rb', line 34

def self.transformer
  raise AbstractMethodError
end