Skip to content

Commit

Permalink
rails 8 upgrade: fix SLC importer data casting
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Dec 2, 2024
1 parent c8c097a commit 010e494
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/models/student_loans_data_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@ def row_to_hash(row)
full_name: row.fetch("Full name"),
date_of_birth: cast_as_date(row.fetch("Date of birth")),
policy_name: row.fetch("Policy name"),
no_of_plans_currently_repaying: row.fetch("No of Plans Currently Repaying"),
plan_type_of_deduction: row.fetch("Plan Type of Deduction"),
no_of_plans_currently_repaying: calculate_no_of_plans_currently_repaying(row.fetch("No of Plans Currently Repaying")),
plan_type_of_deduction: calculate_plan_type_of_deduction(row.fetch("Plan Type of Deduction")),
amount: row.fetch("Amount")
}
end

def calculate_plan_type_of_deduction(value)
if value == "No data"
nil
else
value
end
end

def calculate_no_of_plans_currently_repaying(value)
if value == "No data"
nil
else
value
end
end

def cast_as_date(string)
Date.strptime(string, I18n.t("date.formats.day_month_year"))
rescue TypeError, Date::Error
Expand Down

0 comments on commit 010e494

Please sign in to comment.