Class: Rippler::Transaction

Inherits:
Object
  • Object
show all
Includes:
Comparable, Utils
Defined in:
lib/rippler/transaction.rb

Overview

Represents a single Ripple transaction

Constant Summary

Constants included from Utils

Utils::RIPPLE_TIME_OFFSET

Instance Method Summary collapse

Methods included from Utils

#Account, #Money, #Offer, #Time

Constructor Details

#initialize(data) ⇒ Transaction

data Hash



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

def initialize data # data Hash
  @data = data
end

Instance Method Details

#amountObject



20
21
22
# File 'lib/rippler/transaction.rb', line 20

def amount
  Money(self.tx['Amount'])
end

#dateObject



36
37
38
# File 'lib/rippler/transaction.rb', line 36

def date
  Time(tx['date'])
end

#dtObject



32
33
34
# File 'lib/rippler/transaction.rb', line 32

def dt
  self.tx['DestinationTag']
end

#fromObject



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

def from
  self.tx['Account']
end

#timestringObject



40
41
42
43
44
# File 'lib/rippler/transaction.rb', line 40

def timestring
  if tx
    "#{self.date.strftime("%Y-%m-%d %H:%M:%S")} "
  end
end

#toObject



28
29
30
# File 'lib/rippler/transaction.rb', line 28

def to
  self.tx['Destination']
end

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rippler/transaction.rb', line 46

def to_s
  if tx
    timestring +
    case tx["TransactionType"]
    when "Payment"
      "PAY #{Money(tx['Amount'])} #{Account(tx['Account'])} > #{Account(tx['Destination'])}"
    when "OfferCancel"
      "CAN #{Account(tx['Account'])} ##{tx['Sequence']}"
    when "OfferCreate"
      Offer(tx).to_s
    when "TrustSet"
      "TRS #{Money(tx['LimitAmount'])} #{Account(tx['Account'])}"
    else
      tx
    end
  else
    @data
  end
end

#txObject

Pure transaction data, without metadata



12
13
14
# File 'lib/rippler/transaction.rb', line 12

def tx
  @data['tx'] || @data['transaction']
end

#typeObject



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

def type
  self.tx['TransactionType']
end