Class: SaltParser::Ofx::Parser::OFX102

Inherits:
Base
  • Object
show all
Defined in:
lib/ofx/parser/ofx102.rb

Constant Summary collapse

VERSION =
"1.0.2"

Constants inherited from Base

Base::ACCOUNT_TYPES, Base::TRANSACTION_TYPES

Instance Attribute Summary

Attributes inherited from Base

#accounts, #body, #errors, #headers, #html, #sign_on

Class Method Summary collapse

Methods inherited from Base

#build_accounts, #initialize, #to_hash

Constructor Details

This class inherits a constructor from SaltParser::Ofx::Parser::Base

Class Method Details

.parse_headers(header_text) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ofx/parser/ofx102.rb', line 7

def self.parse_headers(header_text)
  # TODO: refactor
  # Change single CR's to LF's to avoid issues with some banks
  header_text.gsub!(/\r(?!\n)/, "\n")

  # Parse headers. When value is NONE, convert it to nil.
  headers = header_text.to_enum(:each_line).inject({}) do |memo, line|
    _, key, value = *line.match(/^(.*?):(.*?)\s*(\r?\n)*$/)

    unless key.nil?
      memo[key] = value == "NONE" ? nil : value
    end

    memo
  end

  return headers unless headers.empty?
end