Class: Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/transaction.rb

Overview

Transaction A single transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debtor, creditor, amount) ⇒ Transaction

Returns a new instance of Transaction.



8
9
10
11
12
# File 'lib/transaction.rb', line 8

def initialize(debtor, creditor, amount)
  @debtor = debtor
  @creditor = creditor
  @amount = amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



6
7
8
# File 'lib/transaction.rb', line 6

def amount
  @amount
end

#creditorObject (readonly)

Returns the value of attribute creditor.



6
7
8
# File 'lib/transaction.rb', line 6

def creditor
  @creditor
end

#debtorObject (readonly)

Returns the value of attribute debtor.



6
7
8
# File 'lib/transaction.rb', line 6

def debtor
  @debtor
end

Instance Method Details

#==(obj) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/transaction.rb', line 19

def ==(obj)
  (
    obj.amount == self.amount && 
    obj.creditor == self.creditor && 
    obj.debtor == self.debtor
  )
end

#reverseObject

Returns a transaction that is the reverse of the current one



15
16
17
# File 'lib/transaction.rb', line 15

def reverse
  Transaction.new(@creditor, @debtor, @amount)
end