Class: OFX::Base::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ofx_kit/base/document.rb

Overview

Wraps the parsed OFX file, providing access to headers and XML body nodes. Consumers use #bank_statement_nodes and #credit_card_statement_nodes to extract statement data for domain object construction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers:, body:) ⇒ Document

Creates a new document. headers is a Hash of parsed OFX header key/value pairs. body is a Nokogiri::XML::Document of the parsed OFX body.



18
19
20
21
# File 'lib/ofx_kit/base/document.rb', line 18

def initialize(headers:, body:)
  @headers = headers
  @body    = body
end

Instance Attribute Details

#headersObject (readonly)

Parsed OFX header key/value pairs (Hash).



12
13
14
# File 'lib/ofx_kit/base/document.rb', line 12

def headers
  @headers
end

Instance Method Details

#bank_statement_nodesObject

Returns all STMTRS (bank statement) nodes in the document (Nokogiri::XML::NodeSet).



32
33
34
# File 'lib/ofx_kit/base/document.rb', line 32

def bank_statement_nodes
  @body.css('STMTRS')
end

#credit_card_statement_nodesObject

Returns all CCSTMTRS (credit card statement) nodes in the document (Nokogiri::XML::NodeSet).



39
40
41
# File 'lib/ofx_kit/base/document.rb', line 39

def credit_card_statement_nodes
  @body.css('CCSTMTRS')
end

#versionObject

Returns the OFX version declared in the file header (String or nil).



25
26
27
# File 'lib/ofx_kit/base/document.rb', line 25

def version
  @headers['VERSION']
end