Class: ThePlaidApi::Earnings

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

Overview

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

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(subtotals: SKIP, totals: SKIP, breakdown: SKIP, total: SKIP, additional_properties: nil) ⇒ Earnings

Returns a new instance of Earnings.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/the_plaid_api/models/earnings.rb', line 55

def initialize(subtotals: SKIP, totals: SKIP, breakdown: SKIP, total: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @subtotals = subtotals unless subtotals == SKIP
  @totals = totals unless totals == SKIP
  @breakdown = breakdown unless breakdown == SKIP
  @total = total unless total == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#breakdownArray[EarningsBreakdown]

TODO: Write general description for this method

Returns:



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

def breakdown
  @breakdown
end

#subtotalsArray[EarningsTotal]

TODO: Write general description for this method

Returns:



15
16
17
# File 'lib/the_plaid_api/models/earnings.rb', line 15

def subtotals
  @subtotals
end

#totalEarningsTotal

An object representing both the current pay period and year to date amount for an earning category.

Returns:



28
29
30
# File 'lib/the_plaid_api/models/earnings.rb', line 28

def total
  @total
end

#totalsArray[EarningsTotal]

TODO: Write general description for this method

Returns:



19
20
21
# File 'lib/the_plaid_api/models/earnings.rb', line 19

def totals
  @totals
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/the_plaid_api/models/earnings.rb', line 68

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  subtotals = nil
  unless hash['subtotals'].nil?
    subtotals = []
    hash['subtotals'].each do |structure|
      subtotals << (EarningsTotal.from_hash(structure) if structure)
    end
  end

  subtotals = SKIP unless hash.key?('subtotals')
  # Parameter is an array, so we need to iterate through it
  totals = nil
  unless hash['totals'].nil?
    totals = []
    hash['totals'].each do |structure|
      totals << (EarningsTotal.from_hash(structure) if structure)
    end
  end

  totals = SKIP unless hash.key?('totals')
  # Parameter is an array, so we need to iterate through it
  breakdown = nil
  unless hash['breakdown'].nil?
    breakdown = []
    hash['breakdown'].each do |structure|
      breakdown << (EarningsBreakdown.from_hash(structure) if structure)
    end
  end

  breakdown = SKIP unless hash.key?('breakdown')
  total = EarningsTotal.from_hash(hash['total']) if hash['total']

  # 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.
  Earnings.new(subtotals: subtotals,
               totals: totals,
               breakdown: breakdown,
               total: total,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



31
32
33
34
35
36
37
38
# File 'lib/the_plaid_api/models/earnings.rb', line 31

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['subtotals'] = 'subtotals'
  @_hash['totals'] = 'totals'
  @_hash['breakdown'] = 'breakdown'
  @_hash['total'] = 'total'
  @_hash
end

.nullablesObject

An array for nullable fields



51
52
53
# File 'lib/the_plaid_api/models/earnings.rb', line 51

def self.nullables
  []
end

.optionalsObject

An array for optional fields



41
42
43
44
45
46
47
48
# File 'lib/the_plaid_api/models/earnings.rb', line 41

def self.optionals
  %w[
    subtotals
    totals
    breakdown
    total
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



127
128
129
130
131
132
# File 'lib/the_plaid_api/models/earnings.rb', line 127

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} subtotals: #{@subtotals.inspect}, totals: #{@totals.inspect}, breakdown:"\
  " #{@breakdown.inspect}, total: #{@total.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



120
121
122
123
124
# File 'lib/the_plaid_api/models/earnings.rb', line 120

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} subtotals: #{@subtotals}, totals: #{@totals}, breakdown: #{@breakdown},"\
  " total: #{@total}, additional_properties: #{@additional_properties}>"
end