Module: Namae::NameFormatting

Included in:
Name
Defined in:
lib/namae/name.rb

Overview

NameFormatting can be mixed in by an object providing individual name parts (family, given, suffix, particle, etc.) to add support for name formatting.

Instance Method Summary collapse

Instance Method Details

#display_orderString

Returns the name in display order.

Returns:

  • (String)

    the name in display order



14
15
16
# File 'lib/namae/name.rb', line 14

def display_order
  [given_part, family_part, suffix].compact.reject(&:empty?).join(' ')
end

#initials(options = {}) ⇒ String

Returns the name’s initials.

Parameters:

  • options (Hash) (defaults to: {})

    the options to create the initials

Options Hash (options):

  • :expand (true, false) — default: false

    whether or not to expand the family name

  • :dots (true, false) — default: true

    whether or not to print dots between the initials

  • :spaces (true, false) — default: false

    whether or not to print spaces between the initals

Returns:

  • (String)

    the name’s initials.



25
26
27
28
29
30
31
32
33
# File 'lib/namae/name.rb', line 25

def initials(options = {})
  options = Name.defaults[:initials].merge(options)

  if options[:expand]
    [initials_of(given_part, options), family].compact.join(' ')
  else
    initials_of([given_part, family_part].join(' '), options)
  end
end

#sort_order(delimiter = ', ') ⇒ String

Returns the name in sort order.

Returns:

  • (String)

    the name in sort order



9
10
11
# File 'lib/namae/name.rb', line 9

def sort_order(delimiter = ', ')
  [family_part, suffix, given_part].compact.reject(&:empty?).join(delimiter)
end