module NameAbbr

Constants

VERSION

Public Class Methods

abbr_full_name(fullname) click to toggle source
# File lib/name_abbr.rb, line 13
def self.abbr_full_name(fullname)
  fullname = normalize(fullname)

  unless fullname.match(/ /).nil?
    parts = fullname.split(' ')
    [parts[0], parts[parts.length-1][0]].join(' ') + "."
  else
    fullname
  end
end
abbr_name(first_name, last_name) click to toggle source
# File lib/name_abbr.rb, line 2
def self.abbr_name(first_name, last_name)
  first_name = normalize(first_name)
  last_name = normalize(last_name)

  unless last_name.nil?
    [first_name, last_name[0]].join(' ') + "."
  else
    first_name
  end
end

Private Class Methods

normalize(input) click to toggle source
# File lib/name_abbr.rb, line 25
def self.normalize(input)
  return nil if input.nil?

  ret = input.to_s.strip.split(" ").map(&:capitalize).join(" ")

  ret.gsub!(/\-(.)/) do |match|
    "-#{ match[-1].upcase }"
  end

  ret
end