app/models/concerns/common_utils.rb
# Simply grab the first 3 letters if the region name is one word
# grab the first two letters of the first word and the first word of the last word if ...
# region name is more than one
# this should be OK for Ghana a country with then regions only.
# We should have something like the examples below
# UPW (Upper West)
# UPE (Upper East)
# ASH (Ashanti)
# GRA (Greater Accra)
# WES (Western)
# EAS (Eastern)
# CEN (Central)
# BRA (Brong Ahafo)
# VOL (Volta) Ny3 bro :)
# NOR (Northern)
Simply grab the first 3 letters if the region name is one word
grab the first two letters of the first word and the first word of the last word if
region name is more than one
this should be OK for Ghana a country with then regions only.
Simply grab the first 3 letters if the region name is one word grab the first two letters of the first word and the first word of the last word if region name is more than one this should be OK for Ghana a country with then regions only .
def region_code(name)
    return nil unless name
    name_array = name.downcase.gsub(/region/,"").strip.split
    if name_array.size > 1
      first_name = name_array[0]
      last_name = name_array[-1]
      "#{convert_name(first_name, 2)}#{convert_name(last_name, 1)}"
    else
      name = name_array[0]
      "#{name[0..2]}".upcase
    end
  end
def region_code ( name ) return nil unless name name_array = name . downcase . gsub ( / region / , "" ) . strip . split if name_array . size > 1 first_name = name_array [ 0 ] last_name = name_array [ - 1 ] "#{convert_name(first_name, 2)}#{convert_name(last_name, 1)}" else name = name_array [ 0 ] "#{name[0..2]}" . upcase end end
Simply grab the first 3 letters if the region name is one word
grab the first two letters of the first word and the first word of the last word if ...
region name is more than one
this should be OK for Ghana a country with then regions only.
Simply grab the first 3 letters if the region name is one word grab the first two letters of the first word and the first word of the last word if ... region name is more than one this should be OK for Ghana a country with then regions only .
name
<not_specific>