Class: ModernTreasury::LineItemRequest

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

Overview

LineItemRequest 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(amount:, metadata: SKIP, description: SKIP, accounting_category_id: SKIP, additional_properties: nil) ⇒ LineItemRequest

Returns a new instance of LineItemRequest.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/modern_treasury/models/line_item_request.rb', line 58

def initialize(amount:, metadata: SKIP, description: SKIP,
               accounting_category_id: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @amount = amount
  @metadata =  unless  == SKIP
  @description = description unless description == SKIP
  @accounting_category_id = accounting_category_id unless accounting_category_id == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#accounting_category_idString

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

Returns:

  • (String)


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

def accounting_category_id
  @accounting_category_id
end

#amountInteger

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

Returns:

  • (Integer)


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

def amount
  @amount
end

#descriptionString

A free-form description of the line item.

Returns:

  • (String)


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

def description
  @description
end

#metadataHash[String, String]

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

Returns:

  • (Hash[String, String])


20
21
22
# File 'lib/modern_treasury/models/line_item_request.rb', line 20

def 
  @metadata
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/modern_treasury/models/line_item_request.rb', line 71

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
   = hash.key?('metadata') ? hash['metadata'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  accounting_category_id =
    hash.key?('accounting_category_id') ? hash['accounting_category_id'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  LineItemRequest.new(amount: amount,
                      metadata: ,
                      description: description,
                      accounting_category_id: accounting_category_id,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



32
33
34
35
36
37
38
39
# File 'lib/modern_treasury/models/line_item_request.rb', line 32

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['metadata'] = 'metadata'
  @_hash['description'] = 'description'
  @_hash['accounting_category_id'] = 'accounting_category_id'
  @_hash
end

.nullablesObject

An array for nullable fields



51
52
53
54
55
56
# File 'lib/modern_treasury/models/line_item_request.rb', line 51

def self.nullables
  %w[
    description
    accounting_category_id
  ]
end

.optionalsObject

An array for optional fields



42
43
44
45
46
47
48
# File 'lib/modern_treasury/models/line_item_request.rb', line 42

def self.optionals
  %w[
    metadata
    description
    accounting_category_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



105
106
107
108
109
110
# File 'lib/modern_treasury/models/line_item_request.rb', line 105

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount.inspect}, metadata: #{@metadata.inspect}, description:"\
  " #{@description.inspect}, accounting_category_id: #{@accounting_category_id.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



97
98
99
100
101
102
# File 'lib/modern_treasury/models/line_item_request.rb', line 97

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount}, metadata: #{@metadata}, description: #{@description},"\
  " accounting_category_id: #{@accounting_category_id}, additional_properties:"\
  " #{@additional_properties}>"
end