Class: Transaction

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, amount, id = SecureRandom.uuid) ⇒ Transaction

Returns a new instance of Transaction.



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

def initialize( from, to, amount, id=SecureRandom.uuid )
  @from   = from
  @to     = to
  @amount = amount
  @id     = id
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



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

def amount
  @amount
end

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#toObject (readonly)

Returns the value of attribute to.



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

def to
  @to
end

Class Method Details

.from_h(hash) ⇒ Object



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

def self.from_h( hash )
  self.new *hash.values_at( 'from', 'to', 'amount', 'id' )
end

Instance Method Details

#to_hObject



18
19
20
# File 'lib/centralbank/transaction.rb', line 18

def to_h
  { from: @from, to: @to, amount: @amount, id: @id }
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/centralbank/transaction.rb', line 23

def valid?
  ## check signature in the future; for now always true
  true
end