Class: StackOneMigration::EmployeesMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/stackone_migration/mappers/employees_mapper.rb

Class Method Summary collapse

Class Method Details

.build_merge_enum(enum_class, enum_hash, stackone_enum) ⇒ Object



199
200
201
202
203
204
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 199

def self.build_merge_enum(enum_class, enum_hash, stackone_enum)
  merge_enum = enum_class.build_from_hash(map_enum(enum_hash, stackone_enum))
  merge_enum.raw_value = stackone_enum.source_value unless stackone_enum.nil?

  merge_enum
end

.employment_status_enum_hashObject



39
40
41
42
43
44
45
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 39

def self.employment_status_enum_hash
  {
    :active => 'ACTIVE',
    :pending => 'PENDING',
    :terminated => 'INACTIVE',
  }
end

.employment_type_enum_hashObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 47

def self.employment_type_enum_hash
  {
    :full_time => 'FULL_TIME',
    :part_time => 'PART_TIME',
    :contractor => 'CONTRACTOR',
    :intern => 'INTERN',
    :freelance => 'FREELANCE',
    :terminated => 'MERGE_NONSTANDARD_VALUE',
  }
end

.ethnicity_enum_hashObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 26

def self.ethnicity_enum_hash
  {
    :white => 'WHITE',
    :black_or_african_american => 'BLACK_OR_AFRICAN_AMERICAN',
    :asian => 'ASIAN_OR_INDIAN_SUBCONTINENT',
    :hispanic_or_latino => 'HISPANIC_OR_LATINO',
    :american_indian_or_alaska_native => 'AMERICAN_INDIAN_OR_ALASKA_NATIVE',
    :native_hawaiian_or_pacific_islander => 'NATIVE_HAWAIIAN_OR_OTHER_PACIFIC_ISLANDER',
    :two_or_more_races => 'TWO_OR_MORE_RACES',
    :not_disclosed => 'PREFER_NOT_TO_DISCLOSE',
  }
end

.gender_enum_hashObject



5
6
7
8
9
10
11
12
13
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 5

def self.gender_enum_hash
  {
    :male => 'MALE',
    :female => 'FEMALE',
    :non_binary => 'NON-BINARY',
    :other => 'OTHER',
    :not_disclosed => 'PREFER_NOT_TO_DISCLOSE',
  }
end

.location_type_enum_hashObject



84
85
86
87
88
89
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 84

def self.location_type_enum_hash
  {
    :home => 'HOME',
    :work => 'WORK',
  }
end

.map_country_enum(enum) ⇒ Object



215
216
217
218
219
220
221
222
223
224
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 215

def self.map_country_enum(enum)
  return nil if enum.nil? || enum.value.nil?

  enum_value = enum.value != 'unmapped_value' ? enum.value : enum.source_value

  country_enum = MergeHRISClient::CountryEnum.build_from_hash(enum_value)
  country_enum.raw_value = enum.source_value unless enum.nil?

  country_enum
end

.map_employments(employments) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 159

def self.map_employments(employments)
  if employments.nil?
    mapped_results = []
  else
    mapped_results = employments.map do |employment|
      map_to_employment_model(employment)
    end
  end
end

.map_enum(enum_hash, enum) ⇒ Object



206
207
208
209
210
211
212
213
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 206

def self.map_enum(enum_hash, enum)
  return nil if enum.nil? || enum.value.nil?

  mapped_enum = enum_hash[enum&.value&.to_sym]
  return mapped_enum unless mapped_enum.nil? || mapped_enum == 'MERGE_NONSTANDARD_VALUE'

  enum.source_value
end

.map_single_employee_to_list_model(employee) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 169

def self.map_single_employee_to_list_model(employee)
  mapped_employee = map_to_employee_model(employee)

  mapped_results = mapped_employee.nil? ? [] : [mapped_employee]

  MergeHRISClient::PaginatedEmployeeList.new(
    :_next => nil,
    :results => mapped_results,
    :previous => nil
  )
end

.map_to_employee_model(employee) ⇒ Object



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
118
119
120
121
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 91

def self.map_to_employee_model(employee)
  return nil if employee.nil?

  new_employee = MergeHRISClient::Employee.new(
    :id => employee.id,
    :remote_id => employee.id,
    :first_name => employee.first_name,
    :last_name => employee.last_name,
    :display_full_name => employee.display_name,
    :avatar => employee.avatar_url,
    :personal_email => employee.personal_email,
    :work_email => employee.work_email,
    :mobile_phone_number => employee.personal_phone_number || employee.work_phone_number,
    :gender => build_merge_enum(MergeHRISClient::GenderEnum, gender_enum_hash, employee.gender),
    :date_of_birth => employee.date_of_birth,
    :start_date => employee.start_date,
    :manager => employee.manager_id,
    :ethnicity => build_merge_enum(MergeHRISClient::EthnicityEnum, ethnicity_enum_hash, employee.ethnicity),
    :marital_status => build_merge_enum(MergeHRISClient::MaritalStatusEnum, marital_status_enum_hash, employee.marital_status),
    :hire_date => employee.hire_date,
    :employment_status => build_merge_enum(MergeHRISClient::EmploymentStatusEnum, employment_status_enum_hash, employee.employment_status),
    :termination_date => employee.termination_date,
    :home_location => map_to_location_model(employee.home_location),
    :work_location => map_to_location_model(employee.work_location),
    :employments => map_employments(employee.employments),
  )

  new_employee.employment_contract_type = employee.employment_contract_type unless employee.employment_contract_type.nil?

  new_employee
end

.map_to_employment_model(employment) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 141

def self.map_to_employment_model(employment)
  return nil if employment.nil?

  new_employment = MergeHRISClient::Employment.new(
    :job_title => employment.job_title,
    :pay_rate => employment.pay_rate,
    :pay_period => build_merge_enum(MergeHRISClient::PayPeriodEnum, pay_period_enum_hash, employment.pay_period),
    :pay_frequency => build_merge_enum(MergeHRISClient::PayFrequencyEnum, pay_frequency_enum_hash, employment.pay_frequency),
    :pay_currency => MergeHRISClient::PayCurrencyEnum.build_from_hash(employment.pay_currency&.to_s&.upcase),
    :effective_date => employment.effective_date,
    :employment_type => build_merge_enum(MergeHRISClient::EmploymentTypeEnum, employment_type_enum_hash, employment.employment_type),
  )

  new_employment.employment_contract_type = employment.employment_contract_type unless employment.employment_contract_type.nil?

  new_employment
end

.map_to_location_model(location) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 123

def self.map_to_location_model(location)
  return nil if location.nil?

  MergeHRISClient::Location.new(
    :id => location.id,
    :remote_id => location.id,
    :name => location.name,
    :phone_number => location.phone_number,
    :street_1 => location.street_1,
    :street_2 => location.street_2,
    :city => location.city || location.name,
    :state => location.state,
    :zip_code => location.zip_code,
    :country => map_country_enum(location.country),
    :location_type => build_merge_enum(MergeHRISClient::LocationTypeEnum, location_type_enum_hash, location.location_type),
  )
end

.map_to_paginated_employee_list_model(paginated_employees) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 181

def self.map_to_paginated_employee_list_model(paginated_employees)
  if paginated_employees&.data.nil?
    mapped_results = []
  else
    mapped_results = paginated_employees.data.map do |employee|
      map_to_employee_model(employee)
    end
  end

  next_page = paginated_employees.next_page unless paginated_employees.nil?

  MergeHRISClient::PaginatedEmployeeList.new(
    :_next => next_page,
    :results => mapped_results,
    :previous => nil
  )
end

.marital_status_enum_hashObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 15

def self.marital_status_enum_hash
  {
    :single => 'SINGLE',
    :married => 'MARRIED_FILING_JOINTLY',
    :divorced => 'MERGE_NONSTANDARD_VALUE',
    :widowed => 'QUALIFYING_WIDOW_OR_WIDOWER_WITH_DEPENDENT_CHILD',
    :domestic_partnership => 'MERGE_NONSTANDARD_VALUE',
    :other => 'MERGE_NONSTANDARD_VALUE',
  }
end

.pay_frequency_enum_hashObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 71

def self.pay_frequency_enum_hash
  {
    :weekly => 'WEEKLY',
    :bi_weekly => 'BIWEEKLY',
    :monthly => 'MONTHLY',
    :quarterly => 'QUARTERLY',
    :semi_annually => 'SEMIANNUALLY',
    :yearly => 'ANNUALLY',
    :thirteen_monthly => 'THIRTEEN-MONTHLY',
    :pro_rata => 'PRO_RATA',
  }
end

.pay_period_enum_hashObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/stackone_migration/mappers/employees_mapper.rb', line 58

def self.pay_period_enum_hash
  {
    :hour => 'HOUR',
    :day => 'DAY',
    :week => 'WEEK',
    :every_two_weeks => 'EVERY_TWO_WEEKS',
    :month => 'MONTH',
    :quarter => 'QUARTER',
    :every_six_months => 'EVERY_SIX_MONTHS',
    :year => 'YEAR',
  }
end