Class: Revolut::Api::Response::Quote

Inherits:
Object
  • Object
show all
Defined in:
lib/revolut/api/response/quote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Quote

Returns a new instance of Quote.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/revolut/api/response/quote.rb', line 10

def initialize(hash = {})
  if hash.has_key?("message")
    self.message                  =   hash.fetch("message")
    self.success                  =   false

  else
    self.from                     =   {}
    self.to                       =   {}
    self.fee                      =   {}

    set_amount_hash("from", hash)
    set_amount_hash("to", hash)
    set_amount_hash("fee", hash)

    self.rate                     =   hash.fetch("rate", nil)
    self.markup                   =   hash.fetch("markup", nil)

    self.epoch                    =   hash.fetch("timestamp", nil)
    self.timestamp                =   ::Revolut::Api::Utilities.epoch_to_utc(self.epoch)
  
    self.success                  =   true
  end
end

Instance Attribute Details

#epochObject

Returns the value of attribute epoch.



7
8
9
# File 'lib/revolut/api/response/quote.rb', line 7

def epoch
  @epoch
end

#feeObject

Returns the value of attribute fee.



6
7
8
# File 'lib/revolut/api/response/quote.rb', line 6

def fee
  @fee
end

#fromObject

Returns the value of attribute from.



5
6
7
# File 'lib/revolut/api/response/quote.rb', line 5

def from
  @from
end

#markupObject

Returns the value of attribute markup.



6
7
8
# File 'lib/revolut/api/response/quote.rb', line 6

def markup
  @markup
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/revolut/api/response/quote.rb', line 8

def message
  @message
end

#rateObject

Returns the value of attribute rate.



6
7
8
# File 'lib/revolut/api/response/quote.rb', line 6

def rate
  @rate
end

#successObject

Returns the value of attribute success.



8
9
10
# File 'lib/revolut/api/response/quote.rb', line 8

def success
  @success
end

#timestampObject

Returns the value of attribute timestamp.



7
8
9
# File 'lib/revolut/api/response/quote.rb', line 7

def timestamp
  @timestamp
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/revolut/api/response/quote.rb', line 5

def to
  @to
end

Instance Method Details

#set_amount_hash(key, hash) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/revolut/api/response/quote.rb', line 34

def set_amount_hash(key, hash)
  if hash.has_key?(key)
    sub_item                      =   hash.fetch(key, {})
  
    if sub_item.is_a?(Hash)
      self.send(key)[:currency]     =   sub_item.fetch("currency", nil)
      self.send(key)[:base_amount]  =   sub_item.fetch("amount", nil)
      self.send(key)[:amount]       =   ::Revolut::Api::Utilities.convert_from_integer_amount(self.send(key)[:currency], self.send(key)[:base_amount]) if !self.send(key)[:currency].to_s.empty? && !self.send(key)[:base_amount].nil?
  
    elsif sub_item.is_a?(String)
      self.send("#{key}=", sub_item)
    end
  end
end