Class: ModernTreasury::Document

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

Overview

Document 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:, discarded_at:, document_type:, source:, documentable_id:, documentable_type:, document_details:, file:) ⇒ Document

Returns a new instance of Document.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/modern_treasury/models/document.rb', line 106

def initialize(id:, object:, live_mode:, created_at:, updated_at:,
               discarded_at:, document_type:, source:, documentable_id:,
               documentable_type:, document_details:, file:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @discarded_at = discarded_at
  @document_type = document_type
  @source = source
  @documentable_id = documentable_id
  @documentable_type = documentable_type
  @document_details = document_details
  @file = file
end

Instance Attribute Details

#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/document.rb', line 29

def created_at
  @created_at
end

#discarded_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)


39
40
41
# File 'lib/modern_treasury/models/document.rb', line 39

def discarded_at
  @discarded_at
end

#document_detailsArray[DocumentDetail]

The type of the associated object. Currently can be one of ‘payment_order`, `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`, `case`, `internal_account`, `decision`, or `external_account`.

Returns:



66
67
68
# File 'lib/modern_treasury/models/document.rb', line 66

def document_details
  @document_details
end

#document_typeString

A category given to the document, can be ‘null`.

Returns:

  • (String)


43
44
45
# File 'lib/modern_treasury/models/document.rb', line 43

def document_type
  @document_type
end

#documentable_idUUID | String

The unique identifier for the associated object.

Returns:

  • (UUID | String)


52
53
54
# File 'lib/modern_treasury/models/document.rb', line 52

def documentable_id
  @documentable_id
end

#documentable_typeDocumentableType

The type of the associated object. Currently can be one of ‘payment_order`, `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`, `case`, `internal_account`, `decision`, or `external_account`.

Returns:



59
60
61
# File 'lib/modern_treasury/models/document.rb', line 59

def documentable_type
  @documentable_type
end

#fileFile

The type of the associated object. Currently can be one of ‘payment_order`, `transaction`, `paper_item`, `expected_payment`, `counterparty`, `organization`, `case`, `internal_account`, `decision`, or `external_account`.

Returns:



73
74
75
# File 'lib/modern_treasury/models/document.rb', line 73

def file
  @file
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/modern_treasury/models/document.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/document.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/document.rb', line 19

def object
  @object
end

#sourceString

The source of the document. Can be ‘vendor`, `customer`, or `modern_treasury`.

Returns:

  • (String)


48
49
50
# File 'lib/modern_treasury/models/document.rb', line 48

def source
  @source
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/document.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.



124
125
126
127
128
129
130
131
132
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
# File 'lib/modern_treasury/models/document.rb', line 124

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
  discarded_at = if hash.key?('discarded_at')
                   (DateTimeHelper.from_rfc3339(hash['discarded_at']) if hash['discarded_at'])
                 end
  document_type = hash.key?('document_type') ? hash['document_type'] : nil
  source = hash.key?('source') ? hash['source'] : nil
  documentable_id =
    hash.key?('documentable_id') ? hash['documentable_id'] : nil
  documentable_type =
    hash.key?('documentable_type') ? hash['documentable_type'] : nil
  # Parameter is an array, so we need to iterate through it
  document_details = nil
  unless hash['document_details'].nil?
    document_details = []
    hash['document_details'].each do |structure|
      document_details << (DocumentDetail.from_hash(structure) if structure)
    end
  end

  document_details = nil unless hash.key?('document_details')
  file = File.from_hash(hash['file']) if hash['file']

  # Create object from extracted values.
  Document.new(id: id,
               object: object,
               live_mode: live_mode,
               created_at: created_at,
               updated_at: updated_at,
               discarded_at: discarded_at,
               document_type: document_type,
               source: source,
               documentable_id: documentable_id,
               documentable_type: documentable_type,
               document_details: document_details,
               file: file)
end

.namesObject

A mapping from model property names to API property names.



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

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['discarded_at'] = 'discarded_at'
  @_hash['document_type'] = 'document_type'
  @_hash['source'] = 'source'
  @_hash['documentable_id'] = 'documentable_id'
  @_hash['documentable_type'] = 'documentable_type'
  @_hash['document_details'] = 'document_details'
  @_hash['file'] = 'file'
  @_hash
end

.nullablesObject

An array for nullable fields



99
100
101
102
103
104
# File 'lib/modern_treasury/models/document.rb', line 99

def self.nullables
  %w[
    discarded_at
    document_type
  ]
end

.optionalsObject

An array for optional fields



94
95
96
# File 'lib/modern_treasury/models/document.rb', line 94

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



196
197
198
199
200
201
202
203
204
# File 'lib/modern_treasury/models/document.rb', line 196

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}, discarded_at: #{@discarded_at.inspect}, document_type:"\
  " #{@document_type.inspect}, source: #{@source.inspect}, documentable_id:"\
  " #{@documentable_id.inspect}, documentable_type: #{@documentable_type.inspect},"\
  " document_details: #{@document_details.inspect}, file: #{@file.inspect}>"
end

#to_custom_created_atObject



173
174
175
# File 'lib/modern_treasury/models/document.rb', line 173

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_discarded_atObject



181
182
183
# File 'lib/modern_treasury/models/document.rb', line 181

def to_custom_discarded_at
  DateTimeHelper.to_rfc3339(discarded_at)
end

#to_custom_updated_atObject



177
178
179
# File 'lib/modern_treasury/models/document.rb', line 177

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



186
187
188
189
190
191
192
193
# File 'lib/modern_treasury/models/document.rb', line 186

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}, discarded_at: #{@discarded_at}, document_type:"\
  " #{@document_type}, source: #{@source}, documentable_id: #{@documentable_id},"\
  " documentable_type: #{@documentable_type}, document_details: #{@document_details}, file:"\
  " #{@file}>"
end