Class: Cryptopay::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopay/models/exchange.rb

Overview

Exchange details

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Exchange

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



37
38
39
# File 'lib/cryptopay/models/exchange.rb', line 37

def initialize(attributes = {})
  @attributes = ENCODER.sanitize(attributes)
end

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Exchange

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



30
31
32
33
# File 'lib/cryptopay/models/exchange.rb', line 30

def self.build_from_hash(data)
  attributes = ENCODER.build_from_hash(data)
  new(attributes)
end

Instance Method Details

#feeObject

Exchange fee



52
53
54
# File 'lib/cryptopay/models/exchange.rb', line 52

def fee
  @attributes[:fee]
end

#fee_currencyObject

Exchange fee currency



57
58
59
# File 'lib/cryptopay/models/exchange.rb', line 57

def fee_currency
  @attributes[:fee_currency]
end

#inspectObject



85
86
87
# File 'lib/cryptopay/models/exchange.rb', line 85

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}> JSON: " + JSON.pretty_generate(to_hash)
end

#invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



63
64
65
66
67
68
69
70
71
# File 'lib/cryptopay/models/exchange.rb', line 63

def invalid_properties
  properties = []

  properties.push('invalid value for "pair", pair cannot be nil.') if pair.nil?

  properties.push('invalid value for "rate", rate cannot be nil.') if rate.nil?

  properties
end

#pairObject

Currency pair



42
43
44
# File 'lib/cryptopay/models/exchange.rb', line 42

def pair
  @attributes[:pair]
end

#rateObject

Exchange rate



47
48
49
# File 'lib/cryptopay/models/exchange.rb', line 47

def rate
  @attributes[:rate]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



81
82
83
# File 'lib/cryptopay/models/exchange.rb', line 81

def to_hash
  ENCODER.to_hash(@attributes)
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



75
76
77
# File 'lib/cryptopay/models/exchange.rb', line 75

def valid?
  invalid_properties.empty?
end