Module: Pupa::Concerns::Nameable

Extended by:
ActiveSupport::Concern
Included in:
Organization, Person
Defined in:
lib/pupa/models/concerns/nameable.rb

Overview

Adds the Popolo other_names property to a model.

Instance Method Summary collapse

Instance Method Details

#add_name(name, start_date: nil, end_date: nil, note: nil, family_name: nil, given_name: nil, additional_name: nil, honorific_prefix: nil, honorific_suffix: nil, patronymic_name: nil) ⇒ Object

Adds an alternate or former name.

Parameters:

  • name (String)

    an alternate or former name

  • start_date (String, Date, Time) (defaults to: nil)

    the date on which the name was adopted

  • end_date (String, Date, Time) (defaults to: nil)

    the date on which the name was abandoned

  • note (String) (defaults to: nil)

    a note, e.g. "Birth name"

  • family_name (String) (defaults to: nil)

    one or more family names

  • given_name (String) (defaults to: nil)

    one or more primary given names

  • additional_name (String) (defaults to: nil)

    one or more secondary given names

  • honorific_prefix (String) (defaults to: nil)

    one or more honorifics preceding a person's name

  • honorific_suffix (String) (defaults to: nil)

    one or more honorifics following a person's name

  • patronymic_name (String) (defaults to: nil)

    one or more patronymic names



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pupa/models/concerns/nameable.rb', line 36

def add_name(name, start_date: nil, end_date: nil, note: nil, family_name: nil, given_name: nil, additional_name: nil, honorific_prefix: nil, honorific_suffix: nil, patronymic_name: nil)
  data = {name: name}
  if start_date
    data[:start_date] = start_date
  end
  if end_date
    data[:end_date] = end_date
  end
  if note
    data[:note] = note
  end
  if family_name
    data[:family_name] = family_name
  end
  if given_name
    data[:given_name] = given_name
  end
  if additional_name
    data[:additional_name] = additional_name
  end
  if honorific_prefix
    data[:honorific_prefix] = honorific_prefix
  end
  if honorific_suffix
    data[:honorific_suffix] = honorific_suffix
  end
  if patronymic_name
    data[:patronymic_name] = patronymic_name
  end
  if name.present?
    @other_names << data
  end
end

#initialize(*args) ⇒ Object



12
13
14
15
# File 'lib/pupa/models/concerns/nameable.rb', line 12

def initialize(*args)
  @other_names = []
  super
end

#other_names=(other_names) ⇒ Object

Sets the other names.

Parameters:

  • other_names (Array)

    a list of other names



20
21
22
# File 'lib/pupa/models/concerns/nameable.rb', line 20

def other_names=(other_names)
  @other_names = symbolize_keys(other_names)
end