Class: OFX::Parser::OFX102

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

Direct Known Subclasses

OFX211

Constant Summary collapse

VERSION =
'1.0.2'
ACCOUNT_TYPES =
{
  'CHECKING' => :checking,
  'SAVINGS' => :savings,
  'CREDITLINE' => :creditline,
  'MONEYMRKT' => :moneymrkt
}.freeze
TRANSACTION_TYPES =
%w[
  ATM CASH CHECK CREDIT DEBIT DEP DIRECTDEBIT DIRECTDEP DIV
  FEE INT OTHER PAYMENT POS REPEATPMT SRVCHG XFER IN OUT
].each_with_object({}) do |tran_type, hash|
  hash[tran_type] = tran_type.downcase.to_sym
end
SEVERITY =
{
  'INFO' => :info,
  'WARN' => :warn,
  'ERROR' => :error
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OFX102

Returns a new instance of OFX102.



30
31
32
33
34
# File 'lib/ofx/parser/ofx102.rb', line 30

def initialize(options = {})
  @headers = options[:headers]
  @body = options[:body]
  @html = Nokogiri::HTML.parse(body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



28
29
30
# File 'lib/ofx/parser/ofx102.rb', line 28

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



28
29
30
# File 'lib/ofx/parser/ofx102.rb', line 28

def headers
  @headers
end

#htmlObject (readonly)

Returns the value of attribute html.



28
29
30
# File 'lib/ofx/parser/ofx102.rb', line 28

def html
  @html
end

Class Method Details

.parse_headers(header_text) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ofx/parser/ofx102.rb', line 53

def self.parse_headers(header_text)
  # 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).each_with_object({}) do |line, memo|
    _, key, value = *line.match(/^(.*?):(.*?)\s*(\r?\n)*$/)

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

  return headers unless headers.empty?
end

Instance Method Details

#accountObject

DEPRECATED: kept for legacy support



45
46
47
# File 'lib/ofx/parser/ofx102.rb', line 45

def 
  @account ||= (html.search('stmttrnrs, ccstmttrnrs').first)
end

#accountsObject



40
41
42
# File 'lib/ofx/parser/ofx102.rb', line 40

def accounts
  @accounts ||= html.search('stmttrnrs, ccstmttrnrs').collect { |node| (node) }
end

#sign_onObject



49
50
51
# File 'lib/ofx/parser/ofx102.rb', line 49

def sign_on
  @sign_on ||= build_sign_on
end

#statementsObject



36
37
38
# File 'lib/ofx/parser/ofx102.rb', line 36

def statements
  @statements ||= html.search('stmttrnrs, ccstmttrnrs').collect { |node| build_statement(node) }
end