Class: OFX::OFX200::XMLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ofx/2.0.0/xml_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ XMLParser

Returns a new instance of XMLParser.



10
11
12
# File 'lib/ofx/2.0.0/xml_parser.rb', line 10

def initialize(body)
    @body = body.to_s.lstrip
end

Class Method Details

.xml_ofx?(body) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/ofx/2.0.0/xml_parser.rb', line 6

def self.xml_ofx?(body)
    body.to_s.lstrip =~ /\A(?:<\?xml\b[^?]*\?>\s*)?<\?OFX\b/i ? true : false
end

Instance Method Details

#headerObject



14
15
16
17
18
19
20
21
# File 'lib/ofx/2.0.0/xml_parser.rb', line 14

def header
    header = OFX::Header.new
    processing_instruction_attributes.each do |key, value|
        header[key] = value
    end
    header['DATA'] ||= 'OFXXML'
    header
end

#to_documentObject



23
24
25
26
27
# File 'lib/ofx/2.0.0/xml_parser.rb', line 23

def to_document
    document = OFX::Document.from_ofx_hash(to_ofx_hash)
    document.header = header
    document
end

#to_ofx_hashObject



29
30
31
# File 'lib/ofx/2.0.0/xml_parser.rb', line 29

def to_ofx_hash
    { document.root.name => element_to_hash_value(document.root) }
end