Class: Rippler::Offer
- Inherits:
-
Object
show all
- Includes:
- Utils
- Defined in:
- lib/rippler/offer.rb
Constant Summary
Constants included
from Utils
Utils::RIPPLE_TIME_OFFSET
Instance Method Summary
collapse
-
#account ⇒ Object
-
#funded ⇒ Object
-
#gets ⇒ Object
-
#initialize(data) ⇒ Offer
constructor
Hash: “BookDirectory”=> “4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5E03DACD3F94D000”, “BookNode”=>“0000000000000000”, “Flags”=>0, “LedgerEntryType”=>“Offer”, “OwnerNode”=>“0000000000000000”, “PreviousTxnID”=> “704A6FCC2DD0AEE9B5F420C3641FB86FFE73F4D233E4B9F6A10E5DE79F7DAACF”, “PreviousTxnLgrSeq”=>432517, “Sequence”=>191, “TakerGets”=> {“currency”=>“USD”, “issuer”=>“rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B”, “value”=>“150”, “TakerPays”=>“449850000000”, “index”=> “D34C841609A12DAF9DF1B59CA7CB930091A1A16C4A400D8AFDF73311CBB2A2C5”, “taker_gets_funded”=> “issuer”=>“rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B”, “value”=>“51.73532238374231”, “taker_pays_funded”=>“155154231828”},.
-
#pays ⇒ Object
-
#to_s ⇒ Object
Methods included from Utils
#Account, #Money, #Offer, #Time
Constructor Details
#initialize(data) ⇒ Offer
Hash:
"BookDirectory"=> "4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5E03DACD3F94D000",
"BookNode"=>"0000000000000000",
"Flags"=>0,
"LedgerEntryType"=>"Offer",
"OwnerNode"=>"0000000000000000",
"PreviousTxnID"=> "704A6FCC2DD0AEE9B5F420C3641FB86FFE73F4D233E4B9F6A10E5DE79F7DAACF",
"PreviousTxnLgrSeq"=>432517,
"Sequence"=>191,
“TakerGets”=>
{"currency"=>"USD", "issuer"=>"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", "value"=>"150",
"TakerPays"=>"449850000000",
"index"=> "D34C841609A12DAF9DF1B59CA7CB930091A1A16C4A400D8AFDF73311CBB2A2C5",
"taker_gets_funded"=>
"issuer"=>"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", "value"=>"51.73532238374231",
"taker_pays_funded"=>"155154231828"},
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/rippler/offer.rb', line 24
def initialize data
@data = data
@take
case data
when String
@address = Rippler::Contacts[data] || data
@name = Rippler::Addresses[@address]
when Hash
@address = data["Account"]
@name = Rippler::Addresses[@address]
@balance = Money(data["Balance"])
@flags = data["Flags"]
end
end
|
Instance Method Details
#account ⇒ Object
47
48
49
|
# File 'lib/rippler/offer.rb', line 47
def account
@account ||= Account(@data['Account'])
end
|
#funded ⇒ Object
51
52
53
54
55
56
|
# File 'lib/rippler/offer.rb', line 51
def funded
if @data['taker_gets_funded'] || @data['taker_pays_funded']
funds = Money(@data['taker_gets_funded'])
" (#{(funds.value/gets.value*100).round(4)}% funded)"
end
end
|
#gets ⇒ Object
39
40
41
|
# File 'lib/rippler/offer.rb', line 39
def gets
@get ||= Money(@data['TakerGets'])
end
|
#pays ⇒ Object
43
44
45
|
# File 'lib/rippler/offer.rb', line 43
def pays
@pay = Money(@data['TakerPays'])
end
|
#to_s ⇒ Object
58
59
60
61
|
# File 'lib/rippler/offer.rb', line 58
def to_s
"OFR at #{gets.rate(pays)}, #{gets.value.round(4)} for #{pays.value.round(4)}" +
"#{funded} by #{account} ##{@data['Sequence']}"
end
|