Class: ModernTreasury::Balance

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/modern_treasury/models/balance.rb

Overview

Balance Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, object:, live_mode:, created_at:, updated_at:, amount:, currency:, balance_type:, vendor_code:, vendor_code_type:) ⇒ Balance

Returns a new instance of Balance.



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/modern_treasury/models/balance.rb', line 87

def initialize(id:, object:, live_mode:, created_at:, updated_at:, amount:,
               currency:, balance_type:, vendor_code:, vendor_code_type:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @amount = amount
  @currency = currency
  @balance_type = balance_type
  @vendor_code = vendor_code
  @vendor_code_type = vendor_code_type
end

Instance Attribute Details

#amountInteger

The balance amount.

Returns:

  • (Integer)


38
39
40
# File 'lib/modern_treasury/models/balance.rb', line 38

def amount
  @amount
end

#balance_typeBalanceType

The specific type of balance reported. One of ‘opening_ledger`, `closing_ledger`, `current_ledger`, `opening_available`, `opening_available_next_business_day`, `closing_available`, `current_available`, or `other`.

Returns:



49
50
51
# File 'lib/modern_treasury/models/balance.rb', line 49

def balance_type
  @balance_type
end

#created_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


29
30
31
# File 'lib/modern_treasury/models/balance.rb', line 29

def created_at
  @created_at
end

#currencyCurrency

Three-letter ISO currency code.

Returns:



42
43
44
# File 'lib/modern_treasury/models/balance.rb', line 42

def currency
  @currency
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/modern_treasury/models/balance.rb', line 15

def id
  @id
end

#live_modeTrueClass | FalseClass

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/modern_treasury/models/balance.rb', line 24

def live_mode
  @live_mode
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/balance.rb', line 19

def object
  @object
end

#updated_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


34
35
36
# File 'lib/modern_treasury/models/balance.rb', line 34

def updated_at
  @updated_at
end

#vendor_codeString

The code used by the bank when reporting this specific balance.

Returns:

  • (String)


53
54
55
# File 'lib/modern_treasury/models/balance.rb', line 53

def vendor_code
  @vendor_code
end

#vendor_code_typeVendorCodeType

The code used by the bank when reporting this specific balance.

Returns:



57
58
59
# File 'lib/modern_treasury/models/balance.rb', line 57

def vendor_code_type
  @vendor_code_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/modern_treasury/models/balance.rb', line 102

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  object = hash.key?('object') ? hash['object'] : nil
  live_mode = hash.key?('live_mode') ? hash['live_mode'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  amount = hash.key?('amount') ? hash['amount'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  balance_type = hash.key?('balance_type') ? hash['balance_type'] : nil
  vendor_code = hash.key?('vendor_code') ? hash['vendor_code'] : nil
  vendor_code_type =
    hash.key?('vendor_code_type') ? hash['vendor_code_type'] : nil

  # Create object from extracted values.
  Balance.new(id: id,
              object: object,
              live_mode: live_mode,
              created_at: created_at,
              updated_at: updated_at,
              amount: amount,
              currency: currency,
              balance_type: balance_type,
              vendor_code: vendor_code,
              vendor_code_type: vendor_code_type)
end

.namesObject

A mapping from model property names to API property names.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/modern_treasury/models/balance.rb', line 60

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['object'] = 'object'
  @_hash['live_mode'] = 'live_mode'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['amount'] = 'amount'
  @_hash['currency'] = 'currency'
  @_hash['balance_type'] = 'balance_type'
  @_hash['vendor_code'] = 'vendor_code'
  @_hash['vendor_code_type'] = 'vendor_code_type'
  @_hash
end

.nullablesObject

An array for nullable fields



81
82
83
84
85
# File 'lib/modern_treasury/models/balance.rb', line 81

def self.nullables
  %w[
    vendor_code_type
  ]
end

.optionalsObject

An array for optional fields



76
77
78
# File 'lib/modern_treasury/models/balance.rb', line 76

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



153
154
155
156
157
158
159
160
# File 'lib/modern_treasury/models/balance.rb', line 153

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, object: #{@object.inspect}, live_mode:"\
  " #{@live_mode.inspect}, created_at: #{@created_at.inspect}, updated_at:"\
  " #{@updated_at.inspect}, amount: #{@amount.inspect}, currency: #{@currency.inspect},"\
  " balance_type: #{@balance_type.inspect}, vendor_code: #{@vendor_code.inspect},"\
  " vendor_code_type: #{@vendor_code_type.inspect}>"
end

#to_custom_created_atObject



135
136
137
# File 'lib/modern_treasury/models/balance.rb', line 135

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



139
140
141
# File 'lib/modern_treasury/models/balance.rb', line 139

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



144
145
146
147
148
149
150
# File 'lib/modern_treasury/models/balance.rb', line 144

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, object: #{@object}, live_mode: #{@live_mode}, created_at:"\
  " #{@created_at}, updated_at: #{@updated_at}, amount: #{@amount}, currency: #{@currency},"\
  " balance_type: #{@balance_type}, vendor_code: #{@vendor_code}, vendor_code_type:"\
  " #{@vendor_code_type}>"
end