Class: Rledger::TransactionBase
- Inherits:
-
Object
- Object
- Rledger::TransactionBase
- Defined in:
- lib/rledger/ledger/transaction.rb
Overview
Transaction base contains the basic elements of any transaction
Direct Known Subclasses
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payee ⇒ Object
Returns the value of attribute payee.
-
#reconciliation ⇒ Object
Returns the value of attribute reconciliation.
Instance Method Summary collapse
-
#initialize ⇒ TransactionBase
constructor
initialize variables with the correct types.
- #parse(s) ⇒ Object
- #to_qif(account) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ TransactionBase
initialize variables with the correct types
13 14 15 16 17 18 |
# File 'lib/rledger/ledger/transaction.rb', line 13 def initialize @date = Date.new @id = "" @reconciliation = Reconciliation.new @payee = "" end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
10 11 12 |
# File 'lib/rledger/ledger/transaction.rb', line 10 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/rledger/ledger/transaction.rb', line 10 def id @id end |
#payee ⇒ Object
Returns the value of attribute payee.
10 11 12 |
# File 'lib/rledger/ledger/transaction.rb', line 10 def payee @payee end |
#reconciliation ⇒ Object
Returns the value of attribute reconciliation.
10 11 12 |
# File 'lib/rledger/ledger/transaction.rb', line 10 def reconciliation @reconciliation end |
Instance Method Details
#parse(s) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rledger/ledger/transaction.rb', line 30 def parse(s) # regular expressions of various components of a transaction base date = "([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9])" ob = "[\t ]*" rec = "([!?*]|)" id = "(\\([^)]+\\)|)" payee = "(.*)" match = Regexp.new(date + ob + rec + ob + id + ob + payee).match(s) if match @date = s_to_date(match[1]) # TODO: replace with Chronic o Date.parse @reconciliation.parse(match[2]) @id = match[3] == "" ? "" : match[3][1..-2] # so that id is always a string @payee = match[4] true else false end end |
#to_qif(account) ⇒ Object
24 25 26 27 28 |
# File 'lib/rledger/ledger/transaction.rb', line 24 def to_qif(account) "D#{@date}\n" + (@payee != "" ? "P#{@payee}\n" : "") + (@id != "" ? "N#{@id}\n" : "") end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/rledger/ledger/transaction.rb', line 20 def to_s "#{@date.strftime("%d/%m/%Y")}#{rec_to_s}#{id_to_s}#{payee_to_s}\n" end |