Class: ModernTreasury::LedgerableEvent

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

Overview

LedgerableEvent 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:, name:, description:, direction:, amount:, currency:, currency_exponent:, custom_data:, ledger_event_handler_id:, metadata:) ⇒ LedgerableEvent

Returns a new instance of LedgerableEvent.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 112

def initialize(id:, object:, live_mode:, created_at:, updated_at:, name:,
               description:, direction:, amount:, currency:,
               currency_exponent:, custom_data:, ledger_event_handler_id:,
               metadata:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @name = name
  @description = description
  @direction = direction
  @amount = amount
  @currency = currency
  @currency_exponent = currency_exponent
  @custom_data = custom_data
  @ledger_event_handler_id = ledger_event_handler_id
  @metadata = 
end

Instance Attribute Details

#amountInteger

Value in specified currency’s smallest unit. e.g. $10 would be represented as 1000.

Returns:

  • (Integer)


51
52
53
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 51

def amount
  @amount
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/ledgerable_event.rb', line 29

def created_at
  @created_at
end

#currencyString

An ISO 4217 conformed currency or a custom currency.

Returns:

  • (String)


55
56
57
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 55

def currency
  @currency
end

#currency_exponentInteger

Must be included if currency is a custom currency. The currency_exponent cannot exceed 30.

Returns:

  • (Integer)


60
61
62
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 60

def currency_exponent
  @currency_exponent
end

#custom_dataObject

Additionally data to be used by the Ledger Event Handler.

Returns:

  • (Object)


64
65
66
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 64

def custom_data
  @custom_data
end

#descriptionString

Description of the ledgerable event.

Returns:

  • (String)


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

def description
  @description
end

#directionString

One of ‘credit`, `debit`.

Returns:

  • (String)


46
47
48
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 46

def direction
  @direction
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


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

def id
  @id
end

#ledger_event_handler_idUUID | String

Id of the ledger event handler that is used to create a ledger transaction.

Returns:

  • (UUID | String)


69
70
71
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 69

def ledger_event_handler_id
  @ledger_event_handler_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/ledgerable_event.rb', line 24

def live_mode
  @live_mode
end

#metadataHash[String, String]

Additional data represented as key-value pairs. Both the key and value must be strings.

Returns:

  • (Hash[String, String])


74
75
76
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 74

def 
  @metadata
end

#nameString

Name of the ledgerable event.

Returns:

  • (String)


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

def name
  @name
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/ledgerable_event.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/ledgerable_event.rb', line 34

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 133

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
  name = hash.key?('name') ? hash['name'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  direction = hash.key?('direction') ? hash['direction'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  currency_exponent =
    hash.key?('currency_exponent') ? hash['currency_exponent'] : nil
  custom_data = hash.key?('custom_data') ? hash['custom_data'] : nil
  ledger_event_handler_id =
    hash.key?('ledger_event_handler_id') ? hash['ledger_event_handler_id'] : nil
   = hash.key?('metadata') ? hash['metadata'] : nil

  # Create object from extracted values.
  LedgerableEvent.new(id: id,
                      object: object,
                      live_mode: live_mode,
                      created_at: created_at,
                      updated_at: updated_at,
                      name: name,
                      description: description,
                      direction: direction,
                      amount: amount,
                      currency: currency,
                      currency_exponent: currency_exponent,
                      custom_data: custom_data,
                      ledger_event_handler_id: ledger_event_handler_id,
                      metadata: )
end

.namesObject

A mapping from model property names to API property names.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 77

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['name'] = 'name'
  @_hash['description'] = 'description'
  @_hash['direction'] = 'direction'
  @_hash['amount'] = 'amount'
  @_hash['currency'] = 'currency'
  @_hash['currency_exponent'] = 'currency_exponent'
  @_hash['custom_data'] = 'custom_data'
  @_hash['ledger_event_handler_id'] = 'ledger_event_handler_id'
  @_hash['metadata'] = 'metadata'
  @_hash
end

.nullablesObject

An array for nullable fields



102
103
104
105
106
107
108
109
110
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 102

def self.nullables
  %w[
    description
    direction
    currency_exponent
    custom_data
    metadata
  ]
end

.optionalsObject

An array for optional fields



97
98
99
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 97

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



194
195
196
197
198
199
200
201
202
203
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 194

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}, name: #{@name.inspect}, description: #{@description.inspect},"\
  " direction: #{@direction.inspect}, amount: #{@amount.inspect}, currency:"\
  " #{@currency.inspect}, currency_exponent: #{@currency_exponent.inspect}, custom_data:"\
  " #{@custom_data.inspect}, ledger_event_handler_id: #{@ledger_event_handler_id.inspect},"\
  " metadata: #{@metadata.inspect}>"
end

#to_custom_created_atObject



175
176
177
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 175

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



179
180
181
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 179

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



184
185
186
187
188
189
190
191
# File 'lib/modern_treasury/models/ledgerable_event.rb', line 184

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}, name: #{@name}, description: #{@description},"\
  " direction: #{@direction}, amount: #{@amount}, currency: #{@currency}, currency_exponent:"\
  " #{@currency_exponent}, custom_data: #{@custom_data}, ledger_event_handler_id:"\
  " #{@ledger_event_handler_id}, metadata: #{@metadata}>"
end