Class: Cryptopay::Rate

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Rate

Initializes the object

Parameters:

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

    Model attributes in the form of hash



32
33
34
# File 'lib/cryptopay/models/rate.rb', line 32

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

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Rate

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



25
26
27
28
# File 'lib/cryptopay/models/rate.rb', line 25

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

Instance Method Details

#buy_rateObject

Buy rate



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

def buy_rate
  @attributes[:buy_rate]
end

#inspectObject



70
71
72
# File 'lib/cryptopay/models/rate.rb', line 70

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



48
49
50
51
52
53
54
55
56
# File 'lib/cryptopay/models/rate.rb', line 48

def invalid_properties
  properties = []

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

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

  properties
end

#sell_rateObject

Buy rate



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

def sell_rate
  @attributes[:sell_rate]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



66
67
68
# File 'lib/cryptopay/models/rate.rb', line 66

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



60
61
62
# File 'lib/cryptopay/models/rate.rb', line 60

def valid?
  invalid_properties.empty?
end