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
# File 'lib/ofx/parser.rb', line 9

def initialize(resource)
  @content = open_resource(resource).read
  @headers, @body = prepare(content)

  case @headers["VERSION"]
  when "102" then
    @parser = OFX::Parser::OFX102.new(:headers => headers, :body => body)
  else
    raise OFX::UnsupportedVersionError
  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



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ofx/parser.rb', line 21

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