Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/quicken_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
require "money"

module QuickenParser
# New API (in version 0.3.0), to allow direct access to the Parser
# object, which (now) has other (potentially) useful methods than just
# #accounts (notably: #metadata):
def self.parser(stream_or_string)
Parser.new(stream_or_string).parse
end

# For backwards compatability, we still provide a version (by the
# original name) that gives #accounts back:
def self.parse(stream_or_string)
Parser.new(stream_or_string).parse.accounts
parser(stream_or_string).accounts
end
end
30 changes: 29 additions & 1 deletion lib/quicken_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
module QuickenParser
class Parser #:nodoc:
def initialize(source)
@input = source.respond_to?(:read) ? source.read : source
@input = source.respond_to?(:read) ? source.read :
File.exists?(source) ? File.open(source).read : source
end

def parse
Expand All @@ -31,6 +32,33 @@ def accounts
@accounts
end

def metadata
# Note: I expect only one of these:
REXML::XPath.each(@doc.root, "//SONRS") do |xml|
@metadata = metadata_from_xml(xml)
end
@metadata
end

def metadata_from_xml(xml)
# https://schemas.liquid-technologies.com/ofx/2.1.1/?page=sonrs.html
{
status: {
code: REXML::XPath.first(xml, ".//STATUS/CODE").text,
severity: REXML::XPath.first(xml, ".//STATUS/SEVERITY").text,
},
server_date: Time.parse(REXML::XPath.first(xml, ".//DTSERVER").text + "Z"),
lang: REXML::XPath.first(xml, ".//LANGUAGE").text,
profile_date: Time.parse(REXML::XPath.first(xml, ".//DTPROFUP").text + "Z"),
financial_institution: {
name: REXML::XPath.first(xml, ".//FI/ORG").text,
id: REXML::XPath.first(xml, ".//FI/FID").text,
},
# Not in the above-linked spec, but seen in a QFX file:
user: REXML::XPath.first(xml, ".//INTU.USERID").text,
}
end

def cc_account_from_xml(xml)
currency = REXML::XPath.first(xml, ".//CURDEF").text
bank_id = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/quicken_parser/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module QuickenParser
VERSION = "0.2.0"
VERSION = "0.3.0"
end
1 change: 0 additions & 1 deletion quicken_parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Gem::Specification.new do |s|
s.email = %q{francois@teksol.info}
s.extra_rdoc_files = ["README", "LICENSE", "TODO"]
s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/quicken_parser", "lib/quicken_parser/account.rb", "lib/quicken_parser/parser.rb", "lib/quicken_parser/transaction.rb", "lib/quicken_parser/transactions.rb", "lib/quicken_parser.rb", "test/account_test.rb", "test/fixtures", "test/fixtures/no_memo.txt", "test/fixtures/one_account.txt", "test/fixtures/one_cc.txt", "test/fixtures/two_accounts.txt", "test/money_test.rb", "test/parser_test.rb", "test/test_helper.rb", "test/transaction_test.rb", "test/transactions_test.rb"]
s.has_rdoc = true
s.homepage = %q{http://github.com/francois/quicken_parser}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.2}
Expand Down