From 89a695388a138c618f5798bf260d96fbc07a631f Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Fri, 19 Feb 2021 17:09:47 +0000 Subject: [PATCH] Change school abbreviation if school has 3 names --- app/models/school.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index c72ddfb..964bd78 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -14,10 +14,15 @@ class School < ActiveRecord::Base def abbreviation name_array = self.name.split(' ') - if name_array.size > 1 - return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a[0..1].join('').upcase}" + if name_array.size > 2 + # If three words, use first letter of first word, first letter of second, and first two of third + return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a.first}#{name_array[2].chars.to_a[0..1].join('').upcase}" + elsif name_array.size > 1 + # If two words use first letter of first word and first three of the second + return "#{name_array[0].chars.to_a.first}#{name_array[1].chars.to_a[0..2].join('').upcase}" else - return "#{name_array[0].chars.to_a[0..2].join('').upcase}" + # If one word use first four letters + return "#{name_array[0].chars.to_a[0..3].join('').upcase}" end end