Skip to content

Commit

Permalink
advice from JB
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sussman committed Jun 25, 2024
1 parent db416fc commit 6f7bfdd
Show file tree
Hide file tree
Showing 3 changed files with 3,293 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/models/applicant_tracking_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def convert_from_milliseconds(millisecond_string)
end

private_class_method def self.fetch_name(string)
return if string.empty?
return unless string&.present?

ATS_SYSTEM_PARSER.find { |regex, ats_name| break ats_name if string.match?(regex) }
end
Expand Down
40 changes: 17 additions & 23 deletions app/tasks/company_creator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class CompanyCreator
# frozen_string_literal: true

class CompanyCreator < ApplicationTask
def initialize(params)
@ats = params[:ats]
@ats_identifier = params[:ats_identifier]
@data = params[:data]
@ats_identifier = params[:ats_identifier] || @ats.fetch_company_id(@data)
@apply_with_cheddar = params[:apply_with_cheddar]
end

Expand All @@ -12,52 +14,44 @@ def call
process
end

def processable
@ats && (@ats_identifier || @data)
end

def process
fetch_ats_identifier unless @ats_identifier
find_or_create_company
end

private

def fetch_ats_identifier
@ats_identifier = @ats.fetch_company_id(@data)
def processable
@ats && @ats_identifier
end

def find_or_create_company
p "Finding or creating company with ATS identifier #{@ats_identifier}"
return unless @ats_identifier.present?

def process
create_company
assign_attributes_from_supplementary_data if @data
assign_attributes_from_supplementary_data
log_and_save_new_company
update_apply_with_cheddar
return @company
end

def assign_attributes_from_supplementary_data
return unless @data

p "Supplementary data found"
supplementary_data = @ats.company_details_from_data(@data)
@company.assign_attributes(supplementary_data)
end

def create_company
@company = Company.find_or_initialize_by(ats_identifier: @ats_identifier) do |new_company|
company_data = @ats.company_details(@ats_identifier)

new_company.applicant_tracking_system = @ats
new_company.assign_attributes(company_data)
new_company.assign_attributes(company_params)
end
end

def company_params
params = @ats.company_details(@ats_identifier)
params.merge(applicant_tracking_system: @ats)
end

def log_and_save_new_company
Rails.logger.info "Company created - #{@company.name}" if @company.new_record? && @company.save
end

def update_apply_with_cheddar
@company.update(apply_with_cheddar: @apply_with_cheddar) if @apply_with_cheddar
@company
end
end
Loading

0 comments on commit 6f7bfdd

Please sign in to comment.