Class: Qif::Transaction
- Inherits:
-
Object
- Object
- Qif::Transaction
- Defined in:
- lib/qif/transaction.rb
Overview
The Qif::Transaction class represents transactions in a qif file.
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reference ⇒ Object
Returns the value of attribute reference.
Class Method Summary collapse
-
.read(record) ⇒ Object
::nodoc.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Transaction
constructor
A new instance of Transaction.
-
#to_s(format = 'dd/mm/yyyy') ⇒ Object
Returns a representation of the transaction as it would appear in a qif file.
Constructor Details
#initialize(attributes = {}) ⇒ Transaction
Returns a new instance of Transaction.
20 21 22 23 24 25 26 |
# File 'lib/qif/transaction.rb', line 20 def initialize(attributes = {}) @date = attributes[:date] @amount = attributes[:amount] @name = attributes[:name] @description = attributes[:description] @reference = attributes[:reference] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
6 7 8 |
# File 'lib/qif/transaction.rb', line 6 def amount @amount end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/qif/transaction.rb', line 6 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/qif/transaction.rb', line 6 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/qif/transaction.rb', line 6 def name @name end |
#reference ⇒ Object
Returns the value of attribute reference.
6 7 8 |
# File 'lib/qif/transaction.rb', line 6 def reference @reference end |
Class Method Details
.read(record) ⇒ Object
::nodoc
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/qif/transaction.rb', line 8 def self.read(record) #::nodoc return nil unless record['D'].respond_to?(:strftime) Transaction.new( :date => record['D'], :amount => record['T'].to_f, :name => record['L'], :description => record['M'], :reference => record['P'] ) end |
Instance Method Details
#to_s(format = 'dd/mm/yyyy') ⇒ Object
Returns a representation of the transaction as it would appear in a qif file.
30 31 32 33 34 35 36 37 38 |
# File 'lib/qif/transaction.rb', line 30 def to_s(format = 'dd/mm/yyyy') { 'D' => DateFormat.new(format).format(date), 'T' => '%.2f' % amount, 'L' => name, 'M' => description, 'P' => reference }.map{|k,v| "#{k}#{v}" }.join("\n") end |