Class: Cryptopay::Beneficiary

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

Overview

Beneficiary information.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Beneficiary

Initializes the object

Parameters:

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

    Model attributes in the form of hash



35
36
37
# File 'lib/cryptopay/models/beneficiary.rb', line 35

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

Class Method Details

.build_from_hash(data) ⇒ Cryptopay::Beneficiary

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:



28
29
30
31
# File 'lib/cryptopay/models/beneficiary.rb', line 28

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

Instance Method Details

#addressObject



48
49
50
# File 'lib/cryptopay/models/beneficiary.rb', line 48

def address
  @attributes[:address]
end

#inspectObject



88
89
90
# File 'lib/cryptopay/models/beneficiary.rb', line 88

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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cryptopay/models/beneficiary.rb', line 54

def invalid_properties
  properties = []

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

  if !type.nil? && !%w[natural_person legal_person].include?(type)
    properties.push('invalid value for type, must be one of "natural_person", "legal_person"')
  end

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

  if name.to_s.length > 100
    properties.push('invalid value for "name", the character length must be smaller than or equal to 100.')
  end

  address&.invalid_properties&.each do |prop|
    properties.push("invalid value for \"address\": #{prop}")
  end

  properties
end

#nameObject

The registered name of the company for a ‘legal_person` or the full name for a `natural_person`. Note that only following symbols will be stored, regardless of the input value: letters of any language, digits `0-9`, symbols `&` `!` `,` `.` `-` and single spaces. Symbols `\`, `/`, newlines and tabs will be replaced with spaces. Everything else will be removed, including double spaces and spaces in the end.



44
45
46
# File 'lib/cryptopay/models/beneficiary.rb', line 44

def name
  @attributes[:name]
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



84
85
86
# File 'lib/cryptopay/models/beneficiary.rb', line 84

def to_hash
  ENCODER.to_hash(@attributes)
end

#typeObject



39
40
41
# File 'lib/cryptopay/models/beneficiary.rb', line 39

def type
  @attributes[:type]
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



78
79
80
# File 'lib/cryptopay/models/beneficiary.rb', line 78

def valid?
  invalid_properties.empty?
end