Class: ModernTreasury::LineItem

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

Overview

LineItem 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:, itemizable_id:, itemizable_type:, amount:, description:, metadata:, accounting:, accounting_category_id:, accounting_ledger_class_id:) ⇒ LineItem

Returns a new instance of LineItem.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/modern_treasury/models/line_item.rb', line 108

def initialize(id:, object:, live_mode:, created_at:, updated_at:,
               itemizable_id:, itemizable_type:, amount:, description:,
               metadata:, accounting:, accounting_category_id:,
               accounting_ledger_class_id:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @itemizable_id = itemizable_id
  @itemizable_type = itemizable_type
  @amount = amount
  @description = description
  @metadata = 
  @accounting = accounting
  @accounting_category_id = accounting_category_id
  @accounting_ledger_class_id = accounting_ledger_class_id
end

Instance Attribute Details

#accountingAccounting

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

Returns:



61
62
63
# File 'lib/modern_treasury/models/line_item.rb', line 61

def accounting
  @accounting
end

#accounting_category_idUUID | String

The ID of one of your accounting categories. Note that these will only be accessible if your accounting system has been connected.

Returns:

  • (UUID | String)


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

def accounting_category_id
  @accounting_category_id
end

#accounting_ledger_class_idUUID | String

The ID of one of the class objects in your accounting system. Class objects track segments of your business independent of client or project. Note that these will only be accessible if your accounting system has been connected.

Returns:

  • (UUID | String)


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

def accounting_ledger_class_id
  @accounting_ledger_class_id
end

#amountInteger

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

Returns:

  • (Integer)


47
48
49
# File 'lib/modern_treasury/models/line_item.rb', line 47

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

def created_at
  @created_at
end

#descriptionString

A free-form description of the line item.

Returns:

  • (String)


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

def description
  @description
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


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

def id
  @id
end

#itemizable_idUUID | String

The ID of the payment order or expected payment.

Returns:

  • (UUID | String)


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

def itemizable_id
  @itemizable_id
end

#itemizable_typeItemizableType

One of ‘payment_orders` or `expected_payments`.

Returns:



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

def itemizable_type
  @itemizable_type
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/line_item.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])


56
57
58
# File 'lib/modern_treasury/models/line_item.rb', line 56

def 
  @metadata
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/line_item.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/line_item.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.



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
# File 'lib/modern_treasury/models/line_item.rb', line 128

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
  itemizable_id = hash.key?('itemizable_id') ? hash['itemizable_id'] : nil
  itemizable_type =
    hash.key?('itemizable_type') ? hash['itemizable_type'] : nil
  amount = hash.key?('amount') ? hash['amount'] : nil
  description = hash.key?('description') ? hash['description'] : nil
   = hash.key?('metadata') ? hash['metadata'] : nil
  accounting = Accounting.from_hash(hash['accounting']) if hash['accounting']
  accounting_category_id =
    hash.key?('accounting_category_id') ? hash['accounting_category_id'] : nil
  accounting_ledger_class_id =
    hash.key?('accounting_ledger_class_id') ? hash['accounting_ledger_class_id'] : nil

  # Create object from extracted values.
  LineItem.new(id: id,
               object: object,
               live_mode: live_mode,
               created_at: created_at,
               updated_at: updated_at,
               itemizable_id: itemizable_id,
               itemizable_type: itemizable_type,
               amount: amount,
               description: description,
               metadata: ,
               accounting: accounting,
               accounting_category_id: accounting_category_id,
               accounting_ledger_class_id: accounting_ledger_class_id)
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
92
# File 'lib/modern_treasury/models/line_item.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['itemizable_id'] = 'itemizable_id'
  @_hash['itemizable_type'] = 'itemizable_type'
  @_hash['amount'] = 'amount'
  @_hash['description'] = 'description'
  @_hash['metadata'] = 'metadata'
  @_hash['accounting'] = 'accounting'
  @_hash['accounting_category_id'] = 'accounting_category_id'
  @_hash['accounting_ledger_class_id'] = 'accounting_ledger_class_id'
  @_hash
end

.nullablesObject

An array for nullable fields



100
101
102
103
104
105
106
# File 'lib/modern_treasury/models/line_item.rb', line 100

def self.nullables
  %w[
    description
    accounting_category_id
    accounting_ledger_class_id
  ]
end

.optionalsObject

An array for optional fields



95
96
97
# File 'lib/modern_treasury/models/line_item.rb', line 95

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



188
189
190
191
192
193
194
195
196
197
# File 'lib/modern_treasury/models/line_item.rb', line 188

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}, itemizable_id: #{@itemizable_id.inspect}, itemizable_type:"\
  " #{@itemizable_type.inspect}, amount: #{@amount.inspect}, description:"\
  " #{@description.inspect}, metadata: #{@metadata.inspect}, accounting:"\
  " #{@accounting.inspect}, accounting_category_id: #{@accounting_category_id.inspect},"\
  " accounting_ledger_class_id: #{@accounting_ledger_class_id.inspect}>"
end

#to_custom_created_atObject



169
170
171
# File 'lib/modern_treasury/models/line_item.rb', line 169

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



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

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



178
179
180
181
182
183
184
185
# File 'lib/modern_treasury/models/line_item.rb', line 178

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}, itemizable_id: #{@itemizable_id},"\
  " itemizable_type: #{@itemizable_type}, amount: #{@amount}, description: #{@description},"\
  " metadata: #{@metadata}, accounting: #{@accounting}, accounting_category_id:"\
  " #{@accounting_category_id}, accounting_ledger_class_id: #{@accounting_ledger_class_id}>"
end