Last active
June 27, 2019 04:33
-
-
Save Hamada92/f8fd7166e40ca21e1366cb4c483f4dc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#csv is the wave 1-5 files for centers. | |
childcare = Childcare.first | |
CSV.parse(csv, headers: true).each_with_index do |row, index| | |
center_kindercare_id = row['Location ID'] | |
region_id = row['Location Region'].to_i | |
district_id = row['Location District'].to_i | |
label = construct_region_label(region_id: region_id, district_id: district_id) | |
region = Region.where(label: label).first_or_create! do |r| | |
r.childcare_id = childcare.id | |
r.kindercare_id = region_id | |
end | |
center = Center.where(kindercare_id: center_kindercare_id).first | |
center.update_attributes!(region_id: region.id) | |
end | |
def construct_region_label(region_id:, district_id:) | |
label = "R#{0 if region_id < 10}#{region_id} D#{0 if district_id < 10}#{district_id}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def construct_region_label(region_id:, district_id:)
--> Should probably be in in Region model