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



93
94
95
# File 'lib/cryptopay/models/beneficiary.rb', line 93

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
75
76
77
78
79
# 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

  pattern = Regexp.new(/^[a-zA-Z0-9\s-]+$/)
  properties.push("invalid value for \"name\", must conform to the pattern #{pattern}.") if name !~ pattern

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

  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`.



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



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

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



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

def valid?
  invalid_properties.empty?
end