class OFX::Builder
Attributes
acct_id[RW]
acct_type[RW]
bal_amt[RW]
bank_id[RW]
dtasof[RW]
dtend[RW]
dtserver[RW]
dtstart[RW]
fi_fid[RW]
fi_org[RW]
transactions[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/ofx.rb, line 24 def initialize(&block) @headers = [ [ "OFXHEADER", "100" ], [ "DATA", "OFXSGML" ], [ "VERSION", "103" ], [ "SECURITY", "NONE" ], [ "ENCODING", "USASCII" ], [ "CHARSET", "1252" ], [ "COMPRESSION", "NONE" ], [ "OLDFILEUID", "NONE" ], [ "NEWFILEUID", "NONE" ] ] @transactions = [] self.dtserver = Date.today if block_given? yield self end end
Public Instance Methods
bal_amt=(amt)
click to toggle source
# File lib/ofx.rb, line 43 def bal_amt=(amt) @bal_amt = BigDecimal.new(amt) end
format_amount(amount)
click to toggle source
# File lib/ofx.rb, line 136 def format_amount(amount) if amount > 0 "+#{amount.to_s('F')}" else "#{amount.to_s('F')}" end end
format_balance(balance)
click to toggle source
# File lib/ofx.rb, line 152 def format_balance(balance) balance.to_s('F') end
format_date(time)
click to toggle source
# File lib/ofx.rb, line 132 def format_date(time) time.strftime("%Y%m%d") end
format_datetime(time)
click to toggle source
# File lib/ofx.rb, line 128 def format_datetime(time) time.strftime("%Y%m%d000000") end
format_trntype(amount)
click to toggle source
# File lib/ofx.rb, line 144 def format_trntype(amount) if amount > 0 "CREDIT" else "DEBIT" end end
print_body()
click to toggle source
# File lib/ofx.rb, line 62 def print_body builder = Nokogiri::XML::Builder.new do |xml| xml.OFX { xml.SIGNONMSGSRSV1 { xml.SONRS { xml.STATUS { xml.CODE "0" xml.SEVERITY "INFO" } xml.DTSERVER format_datetime(self.dtserver) xml.LANGUAGE "ENG" xml.FI { xml.ORG self.fi_org xml.FID self.fi_fid } xml.send "INTU.BID", self.fi_fid } } xml.BANKMSGSRSV1 { xml.STMTTRNRS { xml.TRNUID "0" xml.STATUS { xml.CODE "0" xml.SEVERITY "INFO" } xml.STMTRS { xml.CURDEF "USD" xml.BANKACCTFROM { xml.BANKID self.bank_id xml.ACCTID self.acct_id xml.ACCTTYPE self.acct_type } xml.BANKTRANLIST { if self.dtstart xml.DTSTART format_date(self.dtstart) end if self.dtend xml.DTEND format_date(self.dtend) end self.transactions.each do |transaction| xml.STMTTRN { xml.TRNTYPE format_trntype(transaction.trnamt) xml.DTPOSTED format_date(transaction.dtposted) xml.TRNAMT format_amount(transaction.trnamt) xml.FITID transaction.fitid xml.NAME transaction.name xml.MEMO transaction.memo } end } xml.LEDGERBAL { if self.bal_amt xml.BALAMT format_balance(self.bal_amt) end if self.dtasof xml.DTASOF format_date(self.dtasof) end } } } } } end builder.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION) end
print_headers()
click to toggle source
# File lib/ofx.rb, line 58 def print_headers @headers.map { |key, value| "#{key}:#{value}" }.join("\n") + "\n\n" end
to_ofx()
click to toggle source
# File lib/ofx.rb, line 53 def to_ofx print_headers + print_body end
transaction() { |transaction| ... }
click to toggle source
# File lib/ofx.rb, line 47 def transaction(&block) transaction = OFX::Transaction.new yield transaction self.transactions.push transaction end