Sha256: f41552576e595f458bb55a37e1b8b71f4f55a5a1b0ea63a7badbeabe9f1c0abd

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 Bytes

Contents

module Pupa
  module Concerns
    # Adds the Popolo `other_names` property to a model.
    module Nameable
      extend ActiveSupport::Concern

      included do
        attr_accessor :other_names
        dump :other_names
      end

      # Adds an alternate or former name.
      #
      # @param [String] name an alternate or former name
      # @param [Date,Time] start_date the date on which the name was adopted
      # @param [Date,Time] end_date the date on which the name was abandoned
      # @param [String] note a note, e.g. "Birth name"
      def add_name(name, start_date: nil, end_date: nil, note: 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 name
          (@other_names ||= []) << data
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupa-0.0.9 lib/pupa/models/concerns/nameable.rb