module FullName

Constants

LOCALES

Public Instance Methods

full_name(locale = :en) click to toggle source
# File lib/full_name.rb, line 4
def full_name locale = :en
  return full_name unless LOCALES.include? locale

  unless first_name.nil? or first_name.empty?
    unless last_name.nil? or last_name.empty?
      build_with_both locale     
    else
      build_with_firstname      
    end
  else
    unless last_name.nil? or last_name.empty?
      build_with_lastname locale       
    else
      ''     
    end        
  end
end

Private Instance Methods

build_with_both(locale) click to toggle source
# File lib/full_name.rb, line 23
def build_with_both locale
  case locale  
    when :en then
      [first_name.capitalize, last_name.capitalize].join(' ')
    when :fr then
      "#{last_name.upcase}, #{first_name.capitalize}"
  end
end
build_with_firstname() click to toggle source
# File lib/full_name.rb, line 32
def build_with_firstname 
  first_name.capitalize
end
build_with_lastname(locale) click to toggle source
# File lib/full_name.rb, line 36
def build_with_lastname locale
  case locale  
    when :en then
      last_name.capitalize
    when :fr then
      last_name.upcase           
  end
end