Class: ThePlaidApi::Paystub

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/the_plaid_api/models/paystub.rb

Overview

An object representing data extracted from the end user’s paystub.

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(deductions:, doc_id:, earnings:, employee:, employer:, net_pay:, pay_period_details:, employment_details: SKIP, paystub_details: SKIP, income_breakdown: SKIP, ytd_earnings: SKIP, additional_properties: nil) ⇒ Paystub

Returns a new instance of Paystub.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/the_plaid_api/models/paystub.rb', line 90

def initialize(deductions:, doc_id:, earnings:, employee:, employer:,
               net_pay:, pay_period_details:, employment_details: SKIP,
               paystub_details: SKIP, income_breakdown: SKIP,
               ytd_earnings: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @deductions = deductions
  @doc_id = doc_id
  @earnings = earnings
  @employee = employee
  @employer = employer
  @employment_details = employment_details unless employment_details == SKIP
  @net_pay = net_pay
  @pay_period_details = pay_period_details
  @paystub_details = paystub_details unless paystub_details == SKIP
  @income_breakdown = income_breakdown unless income_breakdown == SKIP
  @ytd_earnings = ytd_earnings unless ytd_earnings == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#deductionsDeductions

An object with the deduction information found on a paystub.

Returns:



14
15
16
# File 'lib/the_plaid_api/models/paystub.rb', line 14

def deductions
  @deductions
end

#doc_idString

An identifier of the document referenced by the document metadata.

Returns:

  • (String)


18
19
20
# File 'lib/the_plaid_api/models/paystub.rb', line 18

def doc_id
  @doc_id
end

#earningsEarnings

An object representing both a breakdown of earnings on a paystub and the total earnings.

Returns:



23
24
25
# File 'lib/the_plaid_api/models/paystub.rb', line 23

def earnings
  @earnings
end

#employeeEmployee

Data about the employee.

Returns:



27
28
29
# File 'lib/the_plaid_api/models/paystub.rb', line 27

def employee
  @employee
end

#employerEmployer1

Information about the employer on the paystub

Returns:



31
32
33
# File 'lib/the_plaid_api/models/paystub.rb', line 31

def employer
  @employer
end

#employment_detailsEmploymentDetails

An object representing employment details found on a paystub.

Returns:



35
36
37
# File 'lib/the_plaid_api/models/paystub.rb', line 35

def employment_details
  @employment_details
end

#income_breakdownArray[IncomeBreakdown]

An object representing details that can be found on the paystub.

Returns:



52
53
54
# File 'lib/the_plaid_api/models/paystub.rb', line 52

def income_breakdown
  @income_breakdown
end

#net_payNetPay

An object representing information about the net pay amount on the paystub.

Returns:



40
41
42
# File 'lib/the_plaid_api/models/paystub.rb', line 40

def net_pay
  @net_pay
end

#pay_period_detailsPayPeriodDetails

Details about the pay period.

Returns:



44
45
46
# File 'lib/the_plaid_api/models/paystub.rb', line 44

def pay_period_details
  @pay_period_details
end

#paystub_detailsPaystubDetails

An object representing details that can be found on the paystub.

Returns:



48
49
50
# File 'lib/the_plaid_api/models/paystub.rb', line 48

def paystub_details
  @paystub_details
end

#ytd_earningsPaystubYtdDetails

The amount of income earned year to date, as based on paystub data.

Returns:



56
57
58
# File 'lib/the_plaid_api/models/paystub.rb', line 56

def ytd_earnings
  @ytd_earnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



112
113
114
115
116
117
118
119
120
121
122
123
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
# File 'lib/the_plaid_api/models/paystub.rb', line 112

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  deductions = Deductions.from_hash(hash['deductions']) if hash['deductions']
  doc_id = hash.key?('doc_id') ? hash['doc_id'] : nil
  earnings = Earnings.from_hash(hash['earnings']) if hash['earnings']
  employee = Employee.from_hash(hash['employee']) if hash['employee']
  employer = Employer1.from_hash(hash['employer']) if hash['employer']
  net_pay = NetPay.from_hash(hash['net_pay']) if hash['net_pay']
  pay_period_details = PayPeriodDetails.from_hash(hash['pay_period_details']) if
    hash['pay_period_details']
  employment_details = EmploymentDetails.from_hash(hash['employment_details']) if
    hash['employment_details']
  paystub_details = PaystubDetails.from_hash(hash['paystub_details']) if
    hash['paystub_details']
  # Parameter is an array, so we need to iterate through it
  income_breakdown = nil
  unless hash['income_breakdown'].nil?
    income_breakdown = []
    hash['income_breakdown'].each do |structure|
      income_breakdown << (IncomeBreakdown.from_hash(structure) if structure)
    end
  end

  income_breakdown = SKIP unless hash.key?('income_breakdown')
  ytd_earnings = PaystubYtdDetails.from_hash(hash['ytd_earnings']) if hash['ytd_earnings']

  # 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.
  Paystub.new(deductions: deductions,
              doc_id: doc_id,
              earnings: earnings,
              employee: employee,
              employer: employer,
              net_pay: net_pay,
              pay_period_details: pay_period_details,
              employment_details: employment_details,
              paystub_details: paystub_details,
              income_breakdown: income_breakdown,
              ytd_earnings: ytd_earnings,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['deductions'] = 'deductions'
  @_hash['doc_id'] = 'doc_id'
  @_hash['earnings'] = 'earnings'
  @_hash['employee'] = 'employee'
  @_hash['employer'] = 'employer'
  @_hash['employment_details'] = 'employment_details'
  @_hash['net_pay'] = 'net_pay'
  @_hash['pay_period_details'] = 'pay_period_details'
  @_hash['paystub_details'] = 'paystub_details'
  @_hash['income_breakdown'] = 'income_breakdown'
  @_hash['ytd_earnings'] = 'ytd_earnings'
  @_hash
end

.nullablesObject

An array for nullable fields



86
87
88
# File 'lib/the_plaid_api/models/paystub.rb', line 86

def self.nullables
  []
end

.optionalsObject

An array for optional fields



76
77
78
79
80
81
82
83
# File 'lib/the_plaid_api/models/paystub.rb', line 76

def self.optionals
  %w[
    employment_details
    paystub_details
    income_breakdown
    ytd_earnings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



173
174
175
176
177
178
179
180
181
# File 'lib/the_plaid_api/models/paystub.rb', line 173

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} deductions: #{@deductions.inspect}, doc_id: #{@doc_id.inspect}, earnings:"\
  " #{@earnings.inspect}, employee: #{@employee.inspect}, employer: #{@employer.inspect},"\
  " employment_details: #{@employment_details.inspect}, net_pay: #{@net_pay.inspect},"\
  " pay_period_details: #{@pay_period_details.inspect}, paystub_details:"\
  " #{@paystub_details.inspect}, income_breakdown: #{@income_breakdown.inspect}, ytd_earnings:"\
  " #{@ytd_earnings.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



163
164
165
166
167
168
169
170
# File 'lib/the_plaid_api/models/paystub.rb', line 163

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} deductions: #{@deductions}, doc_id: #{@doc_id}, earnings: #{@earnings},"\
  " employee: #{@employee}, employer: #{@employer}, employment_details:"\
  " #{@employment_details}, net_pay: #{@net_pay}, pay_period_details: #{@pay_period_details},"\
  " paystub_details: #{@paystub_details}, income_breakdown: #{@income_breakdown},"\
  " ytd_earnings: #{@ytd_earnings}, additional_properties: #{@additional_properties}>"
end