From 39acdd74c9ec0a6a5af28da7ace51aaf189ba720 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 1 Oct 2019 04:12:04 +0500 Subject: [PATCH] Improve code --- db/seeds.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index e63676f..1363b87 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -45,8 +45,9 @@ CSV.foreach( org_unit_kinds_filename, col_sep: '|', ) do |(codename, parent, short_name, name)| + parent = parent.blank? ? nil : OrgUnitKind.find_by!(codename: parent.strip) + codename.strip! - parent = parent.strip.presence short_name.strip! name.strip! @@ -56,7 +57,7 @@ CSV.foreach( codename: codename, short_name: short_name, name: name, - parent_kind: parent.nil? ? nil : OrgUnitKind.find_by!(codename: parent), + parent_kind: parent, ) end @@ -64,7 +65,13 @@ CSV.foreach( relation_statuses_filename, col_sep: '|', ) do |(org_unit_kind, codename, name)| - org_unit_kind = OrgUnitKind.find_by! codename: org_unit_kind.strip + org_unit_kind = + if org_unit_kind.blank? + nil + else + OrgUnitKind.find_by!(codename: org_unit_kind.strip) + end + codename.strip! name.strip!