Class: SaltParser::Swift::TransactionInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/swift/transaction_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TransactionInfo

Returns a new instance of TransactionInfo.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/swift/transaction_info.rb', line 8

def initialize(options)
  match_data = options[:content].match(/^(?<code>\d{3})(?<sub_fields>(?<seperator>.).*)$/)
  if match_data
    @code = match_data[:code].to_i
    details,  = [], []

    if seperator = match_data[:seperator]
      sub_fields = match_data[:sub_fields].scan(/#{Regexp.escape(seperator)}(\d{2})([^#{Regexp.escape(seperator)}]*)/)

      sub_fields.each do |(code, content)|
        case code.to_i
          when 0
            @transaction_description = content
          when 10
            @prima_nota = content
          when 20..29, 60..63
            details << content
          when 30
            @bank_code = content
          when 31
            @account_number = content
          when 32..33
             << content
          when 34
            @text_key_extension = content
        else
          @not_implemented_fields ||= []
          @not_implemented_fields << [code, content]
        end
      end
    end

    @details        = details.join("\n")
    @account_holder = .join("\n")
  else
    @details = options[:content]
  end
end

Instance Attribute Details

#account_holderObject (readonly)

Returns the value of attribute account_holder.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def 
  @account_holder
end

#account_numberObject (readonly)

Returns the value of attribute account_number.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def 
  @account_number
end

#bank_codeObject (readonly)

Returns the value of attribute bank_code.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def bank_code
  @bank_code
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def code
  @code
end

#detailsObject (readonly)

Returns the value of attribute details.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def details
  @details
end

#not_implemented_fieldsObject (readonly)

Returns the value of attribute not_implemented_fields.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def not_implemented_fields
  @not_implemented_fields
end

#prima_notaObject (readonly)

Returns the value of attribute prima_nota.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def prima_nota
  @prima_nota
end

#text_key_extensionObject (readonly)

Returns the value of attribute text_key_extension.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def text_key_extension
  @text_key_extension
end

#transaction_descriptionObject (readonly)

Returns the value of attribute transaction_description.



4
5
6
# File 'lib/swift/transaction_info.rb', line 4

def transaction_description
  @transaction_description
end

Instance Method Details

#to_hashObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/swift/transaction_info.rb', line 47

def to_hash
  {
    :code                     => code,
    :transaction_description  => transaction_description,
    :prima_nota               => prima_nota,
    :details                  => details,
    :bank_code                => bank_code,
    :account_number           => ,
    :account_holder           => ,
    :text_key_extension       => text_key_extension,
    :not_implemented_fields   => not_implemented_fields
  }
end