Class: OFX::Parser::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ofx/parser.rb', line 9

def initialize(resource)
  resource = open_resource(resource)
  resource.rewind
  @content = convert_to_utf8(resource.read)

  begin
    @headers, @body = prepare(content)
  rescue Exception
    raise OFX::UnsupportedFileError
  end

  case headers["VERSION"]
  when /102|103/ then
    @parser = OFX102.new(:headers => headers, :body => body)
  when /200|211/ then
    @parser = OFX211.new(:headers => headers, :body => body)
  else
    raise OFX::UnsupportedFileError
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/ofx/parser.rb', line 5

def body
  @body
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/ofx/parser.rb', line 4

def headers
  @headers
end

#parserObject (readonly)

Returns the value of attribute parser.



7
8
9
# File 'lib/ofx/parser.rb', line 7

def parser
  @parser
end

Instance Method Details

#open_resource(resource) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/ofx/parser.rb', line 30

def open_resource(resource)
  if resource.respond_to?(:read)
    resource
  else
    open(resource)
  end
rescue Exception
  StringIO.new(resource)
end