Class: BudaApi::Models::Amount

Inherits:
BaseModel show all
Defined in:
lib/buda_api/models.rb

Overview

Amount model for currency amounts

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#raw, #to_h, #to_json

Constructor Details

#initialize(data) ⇒ Amount

Returns a new instance of Amount.



50
51
52
53
54
# File 'lib/buda_api/models.rb', line 50

def initialize(data)
  super(data)
  @amount = data["amount"]&.to_f || 0.0
  @currency = data["currency"]
end

Instance Attribute Details

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



56
57
58
# File 'lib/buda_api/models.rb', line 56

def amount
  @amount
end

#currency ⇒ Object (readonly)

Returns the value of attribute currency.



56
57
58
# File 'lib/buda_api/models.rb', line 56

def currency
  @currency
end

Instance Method Details

#==(other) ⇒ Object



62
63
64
65
66
# File 'lib/buda_api/models.rb', line 62

def ==(other)
  other.is_a?(Amount) && 
  @amount == other.amount && 
  @currency == other.currency
end

#to_s ⇒ Object



58
59
60
# File 'lib/buda_api/models.rb', line 58

def to_s
  "#{@amount} #{@currency}"
end