Sha256: 4a361294e2d10fd7926d15d51f983a0f31b0b73c34432cdec1f89b0768e792ac

Contents?: true

Size: 720 Bytes

Versions: 1

Compression:

Stored size: 720 Bytes

Contents

module NameAbbr
  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

  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

  private
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
name_abbr-1.3.0 lib/name_abbr.rb