Class: PeopleGroup::Connectors::Hris
- Inherits:
-
Object
- Object
- PeopleGroup::Connectors::Hris
- Defined in:
- lib/peoplegroup/connectors/hris.rb
Constant Summary collapse
- EmployeeNotFoundError =
Class.new(StandardError)
Instance Method Summary collapse
-
#active_and_current_employees ⇒ Array<Hash>
(also: #active_and_current_team_members)
List team members with the satus of ‘Active’ and a hireDate that is less than or equal to today.
-
#active_employees ⇒ Array<Hash] team members with a status of 'Active'.
(also: #active_team_members)
List team members with the satus of ‘Active’.
- #add_bonus(employee_number, comment) ⇒ Object
-
#departments ⇒ Array<Hash>
List active departments from Workday.
-
#eligibility_status(eid, salary_min, salary_max) ⇒ Hash
Check team member eligibility status based on salary ranges.
-
#employees ⇒ Array<Hash>
(also: #team_members)
List all team members from the WORKDAY_WORKERS_REPORT.
- #employment_statuses(employee_number) ⇒ Object
-
#fetch_manager(team_member) ⇒ Hash|nil
Find the manager of a team member.
-
#fetch_manager!(team_member) ⇒ Object
Find the manager of a team member and raise error if not found.
-
#fetch_second_level_manager(team_member) ⇒ Hash|nil
Find the second level manager of a team member.
-
#fetch_second_level_manager!(team_member) ⇒ Hash|nil
Find the second level manager of a team member, raise error if not found.
-
#get_employee_details(employee_number) ⇒ Hash
(also: #get_team_member_details)
Get the details of a team member from the WORKDAY_WORKERS_REPORT.
-
#get_employee_details!(employee_number) ⇒ Object
(also: #get_team_member_details!)
Get the details of a team member from the WORKDAY_WORKERS_REPORT.
-
#initialize ⇒ Hris
constructor
A new instance of Hris.
- #job_details(employee_number) ⇒ Object
-
#locations ⇒ Array<Hash>
List entities from Workday.
-
#search_employee(name) ⇒ Hash|nil
(also: #search_team_member)
Search a team member by name.
-
#search_employee!(name) ⇒ Object
(also: #search_team_member!)
Search team member by name.
-
#search_employee_by_field(field:, value:) ⇒ Hash|nil
(also: #search_team_member_by_field)
Search a team meber by field.
-
#search_employee_by_field!(field:, value:) ⇒ Object
(also: #search_team_member_by_field!)
Search a team member by field, and raise error if not found.
-
#search_team_member_by_email(email) ⇒ Hash|nil
(also: #slack_email_lookup_with_fallback)
Find the associated team member without checking case on their e-mail fields.
-
#search_team_member_by_email!(email) ⇒ Object
(also: #slack_email_lookup_with_fallback!)
Find the team member by email and raise error if not found.
-
#team_members_by_department(department) ⇒ Array<Hash>
Team members filtered by department.
-
#team_members_by_division(division) ⇒ Array<Hash>
Team members filtered by division.
Constructor Details
Instance Method Details
#active_and_current_employees ⇒ Array<Hash> Also known as: active_and_current_team_members
List team members with the satus of ‘Active’ and a hireDate that is less than or equal to today.
35 36 37 38 39 40 |
# File 'lib/peoplegroup/connectors/hris.rb', line 35 def active_and_current_employees today = Date.current employees.select do |employee| employee['status'] == 'Active' && Date.parse(employee['hireDate']) <= today end end |
#active_employees ⇒ Array<Hash] team members with a status of 'Active'. Also known as: active_team_members
List team members with the satus of ‘Active’.
28 29 30 |
# File 'lib/peoplegroup/connectors/hris.rb', line 28 def active_employees employees.select { |employee| employee['status'] == 'Active' } end |
#add_bonus(employee_number, comment) ⇒ Object
243 244 245 |
# File 'lib/peoplegroup/connectors/hris.rb', line 243 def add_bonus(employee_number, comment) @workday.add_bonus(employee_number, comment) end |
#departments ⇒ Array<Hash>
List active departments from Workday.
249 250 251 |
# File 'lib/peoplegroup/connectors/hris.rb', line 249 def departments @workday.departments end |
#eligibility_status(eid, salary_min, salary_max) ⇒ Hash
Check team member eligibility status based on salary ranges.
258 259 260 |
# File 'lib/peoplegroup/connectors/hris.rb', line 258 def eligibility_status(eid, salary_min, salary_max) @workday.eligibility_status(eid, salary_min, salary_max) end |
#employees ⇒ Array<Hash> Also known as: team_members
List all team members from the WORKDAY_WORKERS_REPORT.
18 19 20 21 22 23 |
# File 'lib/peoplegroup/connectors/hris.rb', line 18 def employees @employees ||= Workday::Report.call( url: ENV.fetch('WORKDAY_WORKERS_REPORT', nil), password: ENV.fetch('WORKDAY_ISU_PASSWORD', nil) ) end |
#employment_statuses(employee_number) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/peoplegroup/connectors/hris.rb', line 221 def employment_statuses(employee_number) # Terminated/Active in one field already. Those are the statuses we need to care about # Look for a hire date that is after the start date (not original hire date) to account for rehires # Affected: joining.rb # Probation period, CXC contract ending, temporary contract ending won't be needed # We can ignore garden leave (terminate access to systems without pausing benefits/stock vesting) # Affected: # - anniversary.rb # - cxc_contract_renewal_email.rb # - extension_netherlands_contract_email.rb # - probation_email.rb # - probation_status.rb raise NotImplementedError end |
#fetch_manager(team_member) ⇒ Hash|nil
Find the manager of a team member.
179 180 181 |
# File 'lib/peoplegroup/connectors/hris.rb', line 179 def fetch_manager(team_member) active_team_members.find { |tm| tm['employeeNumber'] == team_member['supervisorId'] } end |
#fetch_manager!(team_member) ⇒ Object
Find the manager of a team member and raise error if not found.
187 188 189 190 191 192 |
# File 'lib/peoplegroup/connectors/hris.rb', line 187 def fetch_manager!(team_member) manager = fetch_manager(team_member) raise EmployeeNotFoundError, "Manager not found for employee #{team_member['employeeNumber']}" if manager.nil? manager end |
#fetch_second_level_manager(team_member) ⇒ Hash|nil
Find the second level manager of a team member.
-
Find the team member’s manager.
-
Find the manager’s manager.
199 200 201 |
# File 'lib/peoplegroup/connectors/hris.rb', line 199 def fetch_second_level_manager(team_member) fetch_manager(fetch_manager(team_member)) end |
#fetch_second_level_manager!(team_member) ⇒ Hash|nil
Find the second level manager of a team member, raise error if not found.
208 209 210 211 212 213 |
# File 'lib/peoplegroup/connectors/hris.rb', line 208 def fetch_second_level_manager!(team_member) manager = fetch_second_level_manager(team_member) raise EmployeeNotFoundError, "No second level manager found for employee #{team_member['employeeNumber']}" if manager.nil? manager end |
#get_employee_details(employee_number) ⇒ Hash Also known as: get_team_member_details
Get the details of a team member from the WORKDAY_WORKERS_REPORT.
50 51 52 |
# File 'lib/peoplegroup/connectors/hris.rb', line 50 def get_employee_details(employee_number) employees.find { |emp| emp['employeeNumber'] == employee_number.to_s } end |
#get_employee_details!(employee_number) ⇒ Object Also known as: get_team_member_details!
Get the details of a team member from the WORKDAY_WORKERS_REPORT.
59 60 61 62 63 64 |
# File 'lib/peoplegroup/connectors/hris.rb', line 59 def get_employee_details!(employee_number) employee_details = get_employee_details(employee_number) raise EmployeeNotFoundError, "No team member found with employee number #{employee_number}" if employee_details.nil? employee_details end |
#job_details(employee_number) ⇒ Object
238 239 240 241 |
# File 'lib/peoplegroup/connectors/hris.rb', line 238 def job_details(employee_number) warn '[DEPRECATED] PeopleGroup::Connectors::Hris#job_details, use a custom workday report instead.' Workday::Report.call(url: ENV.fetch('WORKDAY_MANAGER_REPORT', nil)) end |
#locations ⇒ Array<Hash>
List entities from Workday.
217 218 219 |
# File 'lib/peoplegroup/connectors/hris.rb', line 217 def locations @workday.locations end |
#search_employee(name) ⇒ Hash|nil Also known as: search_team_member
Search a team member by name.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/peoplegroup/connectors/hris.rb', line 73 def search_employee(name) return if name.empty? employees.find do |emp| [ emp['displayName']&.downcase, "#{emp['firstName']&.downcase} #{emp['lastName']&.downcase}", "#{emp['preferredName']&.downcase} #{emp['lastName']&.downcase}", "#{emp['firstName']&.downcase} #{emp['customPreferredLastName']&.downcase}", "#{emp['preferredName']&.downcase} #{emp['customPreferredLastName']&.downcase}", emp['fullName5']&.downcase # this is firstName middleName lastName ].include?(name.downcase) end end |
#search_employee!(name) ⇒ Object Also known as: search_team_member!
Search team member by name.
93 94 95 96 97 98 |
# File 'lib/peoplegroup/connectors/hris.rb', line 93 def search_employee!(name) employee = search_employee(name) raise EmployeeNotFoundError, "No employee found with name #{name}" if employee.nil? employee end |
#search_employee_by_field(field:, value:) ⇒ Hash|nil Also known as: search_team_member_by_field
Search a team meber by field.
109 110 111 |
# File 'lib/peoplegroup/connectors/hris.rb', line 109 def search_employee_by_field(field:, value:) employees.find { |employee| employee[field] == value.to_s } end |
#search_employee_by_field!(field:, value:) ⇒ Object Also known as: search_team_member_by_field!
Search a team member by field, and raise error if not found.
119 120 121 122 123 124 |
# File 'lib/peoplegroup/connectors/hris.rb', line 119 def search_employee_by_field!(field:, value:) employee = search_employee_by_field(field: field, value: value) raise EmployeeNotFoundError, "No employee found with #{field}: #{value}" if employee.nil? employee end |
#search_team_member_by_email(email) ⇒ Hash|nil Also known as: slack_email_lookup_with_fallback
Find the associated team member without checking case on their e-mail fields.
-
Look for a match on their workEmail field.
-
Look for a match on their bestEmail field.
-
Look for a match on their homeEmail field.
133 134 135 136 137 138 139 140 |
# File 'lib/peoplegroup/connectors/hris.rb', line 133 def search_team_member_by_email(email) return nil unless email team_members.find do |team_member| emails = [team_member['workEmail'], team_member['bestEmail'], team_member['homeEmail']] emails.compact.any? { |match| email.casecmp(match).zero? } end end |
#search_team_member_by_email!(email) ⇒ Object Also known as: slack_email_lookup_with_fallback!
Find the team member by email and raise error if not found.
146 147 148 149 150 151 152 |
# File 'lib/peoplegroup/connectors/hris.rb', line 146 def search_team_member_by_email!(email) team_member = search_team_member_by_email(email) return team_member if team_member raise EmployeeNotFoundError, "Could not find team member with the e-mail: #{email}" end |
#team_members_by_department(department) ⇒ Array<Hash>
Team members filtered by department
162 163 164 |
# File 'lib/peoplegroup/connectors/hris.rb', line 162 def team_members_by_department(department) active_and_current_team_members.select { |team_member| team_member['department'] == department } end |
#team_members_by_division(division) ⇒ Array<Hash>
Team members filtered by division
172 173 174 |
# File 'lib/peoplegroup/connectors/hris.rb', line 172 def team_members_by_division(division) active_and_current_team_members.select { |team_member| team_member['division'] == division } end |